kwalify_to_json_schema 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/kwalify_to_json_schema.rb +2 -0
- data/lib/kwalify_to_json_schema/cli.rb +6 -5
- data/lib/kwalify_to_json_schema/converter.rb +24 -14
- data/lib/kwalify_to_json_schema/issue.rb +16 -0
- data/lib/kwalify_to_json_schema/issues.rb +10 -0
- data/lib/kwalify_to_json_schema/kwalify_to_json_schema.rb +8 -0
- data/lib/kwalify_to_json_schema/limitations.rb +1 -0
- data/lib/kwalify_to_json_schema/options.rb +10 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e93f6522625fde6b85d8f46a719a0a4ed2cec61ca281511094e32f1f8b8b8941
|
4
|
+
data.tar.gz: 47e10842e281ac6fb393e7c97dfa17ef574cfcc262507cc6e649eeec1d5e39a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46e85a186ef82f070f7d370f7ac33cc3c8ab68a866cb3fd342650b4d3d42c7dcce3d42072cfd9597e8accddbd979fa50421066842693fff6e735cb325773f0cd
|
7
|
+
data.tar.gz: '0799db65393f0084351df69fd34ceef0c3382d8a82ec3ef710c8b1ef041187bf9dd44201ac4ca25abace773ee07a0610048971d4f8b23b190db5fea8002ed87d'
|
@@ -6,6 +6,8 @@ require_relative "kwalify_to_json_schema/kwalify_to_json_schema"
|
|
6
6
|
require_relative "kwalify_to_json_schema/serialization"
|
7
7
|
require_relative "kwalify_to_json_schema/options"
|
8
8
|
require_relative "kwalify_to_json_schema/limitations"
|
9
|
+
require_relative "kwalify_to_json_schema/issue"
|
10
|
+
require_relative "kwalify_to_json_schema/issues"
|
9
11
|
require_relative "kwalify_to_json_schema/converter"
|
10
12
|
require_relative "kwalify_to_json_schema/custom_processing"
|
11
13
|
require_relative "kwalify_to_json_schema/cli"
|
@@ -29,7 +29,9 @@ module KwalifyToJsonSchema
|
|
29
29
|
option(*Options.cli_option(Options::TITLE))
|
30
30
|
option(*Options.cli_option(Options::DESCRIPTION))
|
31
31
|
option(*Options.cli_option(Options::ISSUES_TO_DESCRIPTION))
|
32
|
+
option(*Options.cli_option(Options::ISSUES_TO_STDERR))
|
32
33
|
option(*Options.cli_option(Options::SCHEMA_VERSION))
|
34
|
+
option(*Options.cli_option(Options::VERBOSE))
|
33
35
|
option Options::CUSTOM_PROCESSING,
|
34
36
|
:type => :string,
|
35
37
|
:desc => <<~DESC
|
@@ -60,6 +62,7 @@ module KwalifyToJsonSchema
|
|
60
62
|
:desc => "Process files recursively",
|
61
63
|
:long_desc => ""
|
62
64
|
option(*Options.cli_option(Options::SCHEMA_VERSION))
|
65
|
+
option(*Options.cli_option(Options::VERBOSE))
|
63
66
|
option Options::CUSTOM_PROCESSING,
|
64
67
|
:type => :string,
|
65
68
|
:desc => <<~DESC
|
@@ -69,11 +72,9 @@ module KwalifyToJsonSchema
|
|
69
72
|
DESC
|
70
73
|
|
71
74
|
def convert_dir(kwalify_schema_dir, result_dir)
|
72
|
-
opts =
|
73
|
-
|
74
|
-
|
75
|
-
}
|
76
|
-
|
75
|
+
opts = options.dup
|
76
|
+
opts[Options::CUSTOM_PROCESSING] = custom_processing(options)
|
77
|
+
|
77
78
|
path = [kwalify_schema_dir, options["recursive"] ? "**" : nil, "*.yaml"].compact
|
78
79
|
Dir.glob(File.join(*path)).each { |kwalify_schema_file|
|
79
80
|
result_file = File.join(result_dir, File.basename(kwalify_schema_file, File.extname(kwalify_schema_file))) + ".#{options["format"]}"
|
@@ -25,12 +25,15 @@ module KwalifyToJsonSchema
|
|
25
25
|
# | :title | string | nil | The JSON schema title |
|
26
26
|
# | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present|
|
27
27
|
# | :issues_to_description| boolean| false | To append the issuses to the JSON schema description |
|
28
|
+
# | :issues_to_stderr | boolean| false | To write the issuses standard error output |
|
28
29
|
# | :custom_processing | object | nil | To customize the conversion |
|
29
30
|
# | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
|
31
|
+
# | :verbose | boolean| false | To be verbose when converting |
|
30
32
|
# --
|
31
|
-
|
32
|
-
|
33
|
-
@
|
33
|
+
# @param options {Options} or {Hash}
|
34
|
+
def initialize(options = {})
|
35
|
+
@options = Options.new(options)
|
36
|
+
@issues = Issues.new
|
34
37
|
end
|
35
38
|
|
36
39
|
# Execute the conversion process
|
@@ -44,11 +47,12 @@ module KwalifyToJsonSchema
|
|
44
47
|
if issues.any? && options.issues_to_description?
|
45
48
|
description = json_schema["description"] ||= ""
|
46
49
|
description << "Issues when converting from Kwalify:\n"
|
47
|
-
description << issues.map { |
|
50
|
+
description << issues.descriptions_uniq.map { |description| "* #{description}" }.join("\n")
|
48
51
|
end
|
49
52
|
|
50
53
|
# Override description if given in option
|
51
54
|
json_schema["description"] = options.description if options.description
|
55
|
+
STDERR.puts issues if options.issues_to_stderr?
|
52
56
|
|
53
57
|
postprocess(json_schema)
|
54
58
|
end
|
@@ -65,12 +69,14 @@ module KwalifyToJsonSchema
|
|
65
69
|
|
66
70
|
# @param target Json schema target
|
67
71
|
# @param kelem Kwalify element
|
68
|
-
def process(target, kelem)
|
72
|
+
def process(target, kelem, path = [])
|
69
73
|
|
70
74
|
# Add description if available
|
71
75
|
target["description"] = kelem["desc"] if kelem["desc"]
|
76
|
+
ktype = kelem["type"]
|
77
|
+
path += [ktype] if ktype
|
72
78
|
|
73
|
-
case ktype
|
79
|
+
case ktype
|
74
80
|
when "map"
|
75
81
|
target["type"] = "object"
|
76
82
|
target["additionalProperties"] = false
|
@@ -79,8 +85,12 @@ module KwalifyToJsonSchema
|
|
79
85
|
if mapping.is_a? Hash
|
80
86
|
properties = target["properties"] = {}
|
81
87
|
mapping.each_pair { |name, e|
|
82
|
-
|
83
|
-
|
88
|
+
# Ignore mapping default value
|
89
|
+
if name == "="
|
90
|
+
new_issue path, Limitations::MAPPING_DEFAULT_VALUE_NOT_SUPPORTED
|
91
|
+
next
|
92
|
+
end
|
93
|
+
process(properties[name] = {}, e, path + [name])
|
84
94
|
required << name if e["required"] == true
|
85
95
|
}
|
86
96
|
target["required"] = required unless required.empty?
|
@@ -107,13 +117,13 @@ module KwalifyToJsonSchema
|
|
107
117
|
target["type"] = "boolean"
|
108
118
|
when "date"
|
109
119
|
# TODO
|
110
|
-
new_issue Limitations::DATE_TYPE_NOT_IMPLEMENTED
|
120
|
+
new_issue path, Limitations::DATE_TYPE_NOT_IMPLEMENTED
|
111
121
|
when "time"
|
112
122
|
# TODO
|
113
|
-
new_issue Limitations::TIME_TYPE_NOT_IMPLEMENTED
|
123
|
+
new_issue path, Limitations::TIME_TYPE_NOT_IMPLEMENTED
|
114
124
|
when "timestamp"
|
115
125
|
# TODO
|
116
|
-
new_issue Limitations::TIMESTAMP_TYPE_NOT_IMPLEMENTED
|
126
|
+
new_issue path, Limitations::TIMESTAMP_TYPE_NOT_IMPLEMENTED
|
117
127
|
when "scalar"
|
118
128
|
# Use one of
|
119
129
|
target["oneOf"] = [
|
@@ -156,7 +166,7 @@ module KwalifyToJsonSchema
|
|
156
166
|
end
|
157
167
|
end
|
158
168
|
|
159
|
-
new_issue Limitations::UNIQUE_NOT_SUPPORTED if kelem["unique"]
|
169
|
+
new_issue path, Limitations::UNIQUE_NOT_SUPPORTED if kelem["unique"]
|
160
170
|
|
161
171
|
target
|
162
172
|
end
|
@@ -173,8 +183,8 @@ module KwalifyToJsonSchema
|
|
173
183
|
ep.postprocess(json_schema)
|
174
184
|
end
|
175
185
|
|
176
|
-
def new_issue(description)
|
177
|
-
@issues << description
|
186
|
+
def new_issue(path, description)
|
187
|
+
@issues << Issue.new(path, description)
|
178
188
|
end
|
179
189
|
end
|
180
190
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module KwalifyToJsonSchema
|
2
|
+
# Used to represent issues encoutered while converting
|
3
|
+
class Issue
|
4
|
+
attr_reader :path
|
5
|
+
attr_reader :description
|
6
|
+
|
7
|
+
def initialize(path, description)
|
8
|
+
@path = path
|
9
|
+
@description = description
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"Issue #{path.join "/"}: #{description}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -11,12 +11,17 @@ module KwalifyToJsonSchema
|
|
11
11
|
# | :title | string | nil | The JSON schema title |
|
12
12
|
# | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present|
|
13
13
|
# | :issues_to_description| boolean| false | To append the issuses to the JSON schema description |
|
14
|
+
# | :issues_to_stderr | boolean| false | To write the issuses standard error output |
|
14
15
|
# | :custom_processing | object | nil | To customize the conversion |
|
15
16
|
# | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
|
17
|
+
# | :verbose | boolean| false | To be verbose when converting |
|
16
18
|
# --
|
17
19
|
# @param source Path to Kwalify YAML schema
|
18
20
|
# @param dest Path to resulting JSON schema
|
19
21
|
def self.convert_file(source, dest, options = {})
|
22
|
+
options = Options.new(options)
|
23
|
+
puts "Converting file://#{File.expand_path source } to file://#{File.expand_path dest}" if options.verbose?
|
24
|
+
|
20
25
|
# Get a converter
|
21
26
|
converter = Converter.new(options)
|
22
27
|
# Convert
|
@@ -35,14 +40,17 @@ module KwalifyToJsonSchema
|
|
35
40
|
# | :title | string | nil | The JSON schema title |
|
36
41
|
# | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present|
|
37
42
|
# | :issues_to_description| boolean| false | To append the issuses to the JSON schema description |
|
43
|
+
# | :issues_to_stderr | boolean| false | To write the issuses standard error output |
|
38
44
|
# | :custom_processing | object | nil | To customize the conversion |
|
39
45
|
# | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
|
46
|
+
# | :verbose | boolean| false | To be verbose when converting |
|
40
47
|
# --
|
41
48
|
# @param kwalify_schema Kwalify schema as YAML or JSON
|
42
49
|
# @param source_format format of the source schema
|
43
50
|
# @param dest_format format of the destination schema
|
44
51
|
# @param options
|
45
52
|
def self.convert_string(kwalify_schema, source_format = "yaml", dest_format = "json", options = {})
|
53
|
+
options = Options.new(options)
|
46
54
|
# Get a converter
|
47
55
|
converter = Converter.new(options)
|
48
56
|
# Convert
|
@@ -5,5 +5,6 @@ module KwalifyToJsonSchema
|
|
5
5
|
TIME_TYPE_NOT_IMPLEMENTED = "Kwalify 'time' type is not supported and is ignored"
|
6
6
|
TIMESTAMP_TYPE_NOT_IMPLEMENTED = "Kwalify 'timestamp' type is not supported and is ignored"
|
7
7
|
UNIQUE_NOT_SUPPORTED = "Kwalify 'unique' is not supported by JSON Schema and is ignored"
|
8
|
+
MAPPING_DEFAULT_VALUE_NOT_SUPPORTED = "Kwalify mapping default value is not supported by JSON Schema and is ignored"
|
8
9
|
end
|
9
10
|
end
|
@@ -8,23 +8,31 @@ module KwalifyToJsonSchema
|
|
8
8
|
# | :title | string | nil | The JSON schema title |
|
9
9
|
# | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present|
|
10
10
|
# | :issues_to_description| boolean| false | To append the issuses to the JSON schema description |
|
11
|
+
# | :issues_to_stderr | boolean| false | To write the issuses standard error output |
|
11
12
|
# | :custom_processing | object | nil | To customize the conversion |
|
12
13
|
# | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
|
14
|
+
# | :verbose | boolean| false | To be verbose when converting |
|
13
15
|
# --
|
14
16
|
DECLARATION = %q(
|
15
17
|
ID # The JSON schema identifier [string] (nil)
|
16
18
|
TITLE # The JSON schema title [string] (nil)
|
17
19
|
DESCRIPTION # The JSON schema description. If not given the Kwalify description will be used if present [string] (nil)
|
18
20
|
ISSUES_TO_DESCRIPTION # To append the issuses to the JSON schema description [boolean] (false)
|
21
|
+
ISSUES_TO_STDERR # To write the issuses standard error output [boolean] (false)
|
19
22
|
CUSTOM_PROCESSING # To customize the conversion [object] (nil)
|
20
23
|
SCHEMA_VERSION # JSON schema version. Changing this value only change the value of $schema field[string] ("draft-04")
|
24
|
+
VERBOSE # To be verbose when converting [boolean] (false)
|
21
25
|
)
|
22
26
|
|
23
27
|
# The options as Hash
|
24
28
|
attr_reader :options_hash
|
25
29
|
|
26
|
-
def initialize(
|
27
|
-
@options_hash = options_hash
|
30
|
+
def initialize(options)
|
31
|
+
@options_hash = options.is_a?(Options) ? options.options_hash : options
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_s
|
35
|
+
YAML.dump("Options" => options_hash)
|
28
36
|
end
|
29
37
|
|
30
38
|
# Parse options declaration text and give an array of Hash
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kwalify_to_json_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sylvain Gamot
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-06-
|
11
|
+
date: 2020-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- lib/kwalify_to_json_schema/cli.rb
|
93
93
|
- lib/kwalify_to_json_schema/converter.rb
|
94
94
|
- lib/kwalify_to_json_schema/custom_processing.rb
|
95
|
+
- lib/kwalify_to_json_schema/issue.rb
|
96
|
+
- lib/kwalify_to_json_schema/issues.rb
|
95
97
|
- lib/kwalify_to_json_schema/kwalify_to_json_schema.rb
|
96
98
|
- lib/kwalify_to_json_schema/limitations.rb
|
97
99
|
- lib/kwalify_to_json_schema/options.rb
|