kwalify_to_json_schema 0.5.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e93f6522625fde6b85d8f46a719a0a4ed2cec61ca281511094e32f1f8b8b8941
4
- data.tar.gz: 47e10842e281ac6fb393e7c97dfa17ef574cfcc262507cc6e649eeec1d5e39a5
3
+ metadata.gz: 24ea47c83c28031d1630aa6460ab29125ee794b7b1ddfff220e4ec544a7b3c43
4
+ data.tar.gz: 3147694baf5304f1ed35298c8626584befbabfeca7313a5d100c275ce3882f48
5
5
  SHA512:
6
- metadata.gz: 46e85a186ef82f070f7d370f7ac33cc3c8ab68a866cb3fd342650b4d3d42c7dcce3d42072cfd9597e8accddbd979fa50421066842693fff6e735cb325773f0cd
7
- data.tar.gz: '0799db65393f0084351df69fd34ceef0c3382d8a82ec3ef710c8b1ef041187bf9dd44201ac4ca25abace773ee07a0610048971d4f8b23b190db5fea8002ed87d'
6
+ metadata.gz: 5606734e11c35ab09d8eb671d1839d66a72b09cc9620fca6c66bd5ae43d5e713dc0cbb9aeaf839bcea91635bb136656861c69dd2b9b9705d8b8de838bd4773b9
7
+ data.tar.gz: 1fe43731e2afac08c7a0bfe6813c57c33219c84583a4adee8c6cc4ee92f93183040aeb26c139abbe8e3fc1344c4d1ebd5c03a4e9afe9d848805816f88e60723e
@@ -24,7 +24,7 @@ module KwalifyToJsonSchema
24
24
  CODE
25
25
 
26
26
  desc "convert KWALIFY_SCHEMA_FILE, RESULT_FILE",
27
- "Convert a Kwalify schema file to a JSON schema file. The result file extension will decide the format: .json or .yaml"
27
+ "Convert a Kwalify schema file to a JSON schema file. The result file extension will decide the format: .json, .yaml or .yml"
28
28
  option(*Options.cli_option(Options::ID))
29
29
  option(*Options.cli_option(Options::TITLE))
30
30
  option(*Options.cli_option(Options::DESCRIPTION))
@@ -75,7 +75,7 @@ module KwalifyToJsonSchema
75
75
  opts = options.dup
76
76
  opts[Options::CUSTOM_PROCESSING] = custom_processing(options)
77
77
 
78
- path = [kwalify_schema_dir, options["recursive"] ? "**" : nil, "*.yaml"].compact
78
+ path = [kwalify_schema_dir, options["recursive"] ? "**" : nil, "*.{yaml,yml}"].compact
79
79
  Dir.glob(File.join(*path)).each { |kwalify_schema_file|
80
80
  result_file = File.join(result_dir, File.basename(kwalify_schema_file, File.extname(kwalify_schema_file))) + ".#{options["format"]}"
81
81
  KwalifyToJsonSchema.convert_file(kwalify_schema_file, result_file, opts)
@@ -24,8 +24,8 @@ module KwalifyToJsonSchema
24
24
  # | :id | string | nil | The JSON schema identifier |
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
- # | :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 |
27
+ # | :issues_to_description| boolean| false | To append the issues to the JSON schema description |
28
+ # | :issues_to_stderr | boolean| false | To write the issues to standard error output |
29
29
  # | :custom_processing | object | nil | To customize the conversion |
30
30
  # | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
31
31
  # | :verbose | boolean| false | To be verbose when converting |
@@ -85,13 +85,18 @@ module KwalifyToJsonSchema
85
85
  if mapping.is_a? Hash
86
86
  properties = target["properties"] = {}
87
87
  mapping.each_pair { |name, e|
88
- # Ignore mapping default value
88
+ # Handle partial support of mapping default value
89
+ # Only default rule is supported (see http://www.kuwata-lab.com/kwalify/ruby/users-guide.02.html#tips-default)
89
90
  if name == "="
90
- new_issue path, Limitations::MAPPING_DEFAULT_VALUE_NOT_SUPPORTED
91
- next
91
+ if e.is_a?(Hash)
92
+ process(target["additionalProperties"] = {}, e, path)
93
+ else
94
+ new_issue path, Limitations::ONLY_DEFAULT_RULE_SUPPORTED_FOR_DEFAULT_MAPPING
95
+ end
96
+ else
97
+ process(properties[name] = {}, e, path + [name])
98
+ required << name if e["required"] == true
92
99
  end
93
- process(properties[name] = {}, e, path + [name])
94
- required << name if e["required"] == true
95
100
  }
96
101
  target["required"] = required unless required.empty?
97
102
  end
@@ -99,7 +104,13 @@ module KwalifyToJsonSchema
99
104
  target["type"] = "array"
100
105
  sequence = kelem["sequence"]
101
106
  if sequence.is_a? Array
102
- process(target["items"] = {}, sequence.first)
107
+ rule = sequence.first
108
+ if rule["unique"]
109
+ target["uniqueItems"] = true
110
+ rule = rule.dup
111
+ rule.delete("unique")
112
+ end
113
+ process(target["items"] = {}, rule)
103
114
  end
104
115
  when "str"
105
116
  target["type"] = "string"
@@ -135,7 +146,7 @@ module KwalifyToJsonSchema
135
146
  when "any"
136
147
  # Don't put type
137
148
  else
138
- new_issue("Unknown Kwalify type #{ktype}")
149
+ new_issue(path, "Unknown Kwalify type #{ktype}")
139
150
  end
140
151
 
141
152
  target["enum"] = kelem["enum"] if kelem["enum"]
@@ -166,7 +177,7 @@ module KwalifyToJsonSchema
166
177
  end
167
178
  end
168
179
 
169
- new_issue path, Limitations::UNIQUE_NOT_SUPPORTED if kelem["unique"]
180
+ new_issue path, Limitations::UNIQUE_NOT_SUPPORTED_WITHIN_MAPPING if kelem["unique"]
170
181
 
171
182
  target
172
183
  end
@@ -10,8 +10,8 @@ module KwalifyToJsonSchema
10
10
  # | :id | string | nil | The JSON schema identifier |
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
- # | :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 |
13
+ # | :issues_to_description| boolean| false | To append the issues to the JSON schema description |
14
+ # | :issues_to_stderr | boolean| false | To write the issues to standard error output |
15
15
  # | :custom_processing | object | nil | To customize the conversion |
16
16
  # | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
17
17
  # | :verbose | boolean| false | To be verbose when converting |
@@ -39,8 +39,8 @@ module KwalifyToJsonSchema
39
39
  # | :id | string | nil | The JSON schema identifier |
40
40
  # | :title | string | nil | The JSON schema title |
41
41
  # | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present|
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 |
42
+ # | :issues_to_description| boolean| false | To append the issues to the JSON schema description |
43
+ # | :issues_to_stderr | boolean| false | To write the issues to standard error output |
44
44
  # | :custom_processing | object | nil | To customize the conversion |
45
45
  # | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
46
46
  # | :verbose | boolean| false | To be verbose when converting |
@@ -4,7 +4,7 @@ module KwalifyToJsonSchema
4
4
  DATE_TYPE_NOT_IMPLEMENTED = "Kwalify 'date' type is not supported and is ignored"
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
- 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"
7
+ UNIQUE_NOT_SUPPORTED_WITHIN_MAPPING = "Kwalify 'unique' within a mapping is not supported by JSON Schema and is ignored"
8
+ ONLY_DEFAULT_RULE_SUPPORTED_FOR_DEFAULT_MAPPING = "Kwalify mapping default value is not supported by JSON Schema and is ignored. Only default rule is supported"
9
9
  end
10
10
  end
@@ -7,8 +7,8 @@ module KwalifyToJsonSchema
7
7
  # | :id | string | nil | The JSON schema identifier |
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
- # | :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 |
10
+ # | :issues_to_description| boolean| false | To append the issues to the JSON schema description |
11
+ # | :issues_to_stderr | boolean| false | To write the issues to standard error output |
12
12
  # | :custom_processing | object | nil | To customize the conversion |
13
13
  # | :schema_version | string | "draft-04" | JSON schema version. Changing this value only change the value of $schema field |
14
14
  # | :verbose | boolean| false | To be verbose when converting |
@@ -17,8 +17,8 @@ module KwalifyToJsonSchema
17
17
  ID # The JSON schema identifier [string] (nil)
18
18
  TITLE # The JSON schema title [string] (nil)
19
19
  DESCRIPTION # The JSON schema description. If not given the Kwalify description will be used if present [string] (nil)
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)
20
+ ISSUES_TO_DESCRIPTION # To append the issues to the JSON schema description [boolean] (false)
21
+ ISSUES_TO_STDERR # To write the issues to standard error output [boolean] (false)
22
22
  CUSTOM_PROCESSING # To customize the conversion [object] (nil)
23
23
  SCHEMA_VERSION # JSON schema version. Changing this value only change the value of $schema field[string] ("draft-04")
24
24
  VERBOSE # To be verbose when converting [boolean] (false)
@@ -18,14 +18,20 @@ module KwalifyToJsonSchema
18
18
  serialization_for_format(format).serialize(object)
19
19
  end
20
20
 
21
- # @return a Hash giving serialization/deserialization module and methods for a given file extension (.json/.yaml)
21
+ # @return a Hash giving serialization/deserialization module and methods for a given file extension (.json/.yaml/.yml)
22
22
  def self.serialization_for_file(file)
23
23
  serialization_for_format(File.extname(file)[1..-1])
24
24
  end
25
25
 
26
26
  # @return a Hash giving serialization/deserialization module and methods for a format (json/yaml)
27
27
  def self.serialization_for_format(format)
28
- { "json" => Json, "yaml" => Yaml }[format] || Json
28
+ mod = {
29
+ "json" => Json,
30
+ "yaml" => Yaml,
31
+ "yml" => Yaml,
32
+ }[format]
33
+ raise "Unsupported format '#{format}'" unless mod
34
+ mod
29
35
  end
30
36
 
31
37
  class Language
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.5.0
4
+ version: 0.6.1
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-16 00:00:00.000000000 Z
11
+ date: 2022-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor