kwalify_to_json_schema 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/kwalify_to_json_schema/cli.rb +10 -15
- data/lib/kwalify_to_json_schema/converter.rb +10 -8
- data/lib/kwalify_to_json_schema/kwalify_to_json_schema.rb +14 -14
- data/lib/kwalify_to_json_schema/options.rb +25 -14
- data/lib/kwalify_to_json_schema/serialization.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0655ac6570cc133063989b7781e8057fe9054ad609a7306411de16d7f3318e20
|
4
|
+
data.tar.gz: 49e0cb1f1473f3688b4c3a993c0c0c49057581d640d5f0ec0f131152c76e74df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 535ae226d987f26c1d4d8d1348486bfaefe6d37e927a80a4b0db3265018758aea2cc3953010706398c9802fc6c55f8cc083216b1bb3d4a325179aa12ef1baefa
|
7
|
+
data.tar.gz: fd6257842bc6ec9327152d67f6ae879fc8d5aad8cfc1897d5247b93d6152711a705f53bd244546c8f704f2bcbcf1ce2ccda6455ca3a6ab5c90a8a7710f4d2730
|
@@ -25,11 +25,11 @@ module KwalifyToJsonSchema
|
|
25
25
|
|
26
26
|
desc "convert KWALIFY_SCHEMA_FILE, RESULT_FILE",
|
27
27
|
"Convert a Kwalify schema file to a JSON schema file. The result file extension will decide the format: .json or .yaml"
|
28
|
-
option
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
option
|
28
|
+
option(*Options.cli_option(Options::ID))
|
29
|
+
option(*Options.cli_option(Options::TITLE))
|
30
|
+
option(*Options.cli_option(Options::DESCRIPTION))
|
31
|
+
option(*Options.cli_option(Options::ISSUES_TO_DESCRIPTION))
|
32
|
+
option Options::CUSTOM_PROCESSING,
|
33
33
|
:type => :string,
|
34
34
|
:desc => <<~DESC
|
35
35
|
Allows to provide a pre/post processing file on handled schemas.
|
@@ -38,10 +38,8 @@ module KwalifyToJsonSchema
|
|
38
38
|
DESC
|
39
39
|
|
40
40
|
def convert(kwalify_schema_file, result_file)
|
41
|
-
opts =
|
42
|
-
|
43
|
-
Options::CUSTOM_PROCESSING => custom_processing(options),
|
44
|
-
}
|
41
|
+
opts = options.dup
|
42
|
+
opts[Options::CUSTOM_PROCESSING] = custom_processing(options)
|
45
43
|
KwalifyToJsonSchema.convert_file(kwalify_schema_file, result_file, opts)
|
46
44
|
end
|
47
45
|
|
@@ -49,10 +47,7 @@ module KwalifyToJsonSchema
|
|
49
47
|
|
50
48
|
desc "convert_dir KWALIFY_SCHEMA_DIR, RESULT_DIR",
|
51
49
|
"Convert all the Kwalify schema from a directory to a JSON schema"
|
52
|
-
option
|
53
|
-
:type => :boolean,
|
54
|
-
:default => false,
|
55
|
-
:desc => "Will append any conversion issue to the schema description"
|
50
|
+
option(*Options.cli_option(:issues_to_description))
|
56
51
|
option :format,
|
57
52
|
:type => :string,
|
58
53
|
:enum => ["json", "yaml"],
|
@@ -63,7 +58,7 @@ module KwalifyToJsonSchema
|
|
63
58
|
:default => false,
|
64
59
|
:desc => "Process files recursively",
|
65
60
|
:long_desc => ""
|
66
|
-
option
|
61
|
+
option Options::CUSTOM_PROCESSING,
|
67
62
|
:type => :string,
|
68
63
|
:desc => <<~DESC
|
69
64
|
Allows to provide a pre/post processing file on handled schemas.
|
@@ -98,7 +93,7 @@ module KwalifyToJsonSchema
|
|
98
93
|
begin
|
99
94
|
processing_class = Object.const_get :CustomProcessing
|
100
95
|
custom_processing = processing_class.new
|
101
|
-
rescue NameError
|
96
|
+
rescue NameError
|
102
97
|
raise "The 'CustomProcessing' module must be defined in #{pf}"
|
103
98
|
end
|
104
99
|
end
|
@@ -19,13 +19,13 @@ module KwalifyToJsonSchema
|
|
19
19
|
attr_reader :issues
|
20
20
|
|
21
21
|
# Converter options:
|
22
|
-
# | Name | Type | Default value| Description
|
23
|
-
#
|
24
|
-
# | :id |
|
25
|
-
# | :title |
|
26
|
-
# | :description |
|
27
|
-
# | :issues_to_description|
|
28
|
-
# | :custom_processing |
|
22
|
+
# | Name | Type | Default value| Description |
|
23
|
+
# |-----------------------|--------|--------------|------------------------------------------------------------------------------------------|
|
24
|
+
# | :id | string | nil | The JSON schema identifier |
|
25
|
+
# | :title | string | nil | The JSON schema title |
|
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
|
+
# | :custom_processing | object | nil | To customize the conversion |
|
29
29
|
# --
|
30
30
|
def initialize(options_hash = {})
|
31
31
|
@options = Options.new(options_hash)
|
@@ -46,6 +46,9 @@ module KwalifyToJsonSchema
|
|
46
46
|
description << issues.map { |issue| "* #{issue}" }.join("\n")
|
47
47
|
end
|
48
48
|
|
49
|
+
# Override description if given in option
|
50
|
+
json_schema["description"] = options.description if options.description
|
51
|
+
|
49
52
|
postprocess(json_schema)
|
50
53
|
end
|
51
54
|
|
@@ -56,7 +59,6 @@ module KwalifyToJsonSchema
|
|
56
59
|
"$schema" => SCHEMA,
|
57
60
|
"$id" => options.id,
|
58
61
|
"title" => options.title,
|
59
|
-
"description" => options.description,
|
60
62
|
}.reject { |k, v| v.nil? }
|
61
63
|
end
|
62
64
|
|
@@ -5,13 +5,13 @@ module KwalifyToJsonSchema
|
|
5
5
|
# The file extension is used to select the format: .json or .yaml.
|
6
6
|
# Other extension will fallback to JSON.
|
7
7
|
# Converter options:
|
8
|
-
# | Name | Type | Default value| Description
|
9
|
-
#
|
10
|
-
# | :id |
|
11
|
-
# | :title |
|
12
|
-
# | :description |
|
13
|
-
# | :issues_to_description|
|
14
|
-
# | :custom_processing |
|
8
|
+
# | Name | Type | Default value| Description |
|
9
|
+
# |-----------------------|--------|--------------|------------------------------------------------------------------------------------------|
|
10
|
+
# | :id | string | nil | The JSON schema identifier |
|
11
|
+
# | :title | string | nil | The JSON schema title |
|
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
|
+
# | :custom_processing | object | nil | To customize the conversion |
|
15
15
|
# --
|
16
16
|
# @param source Path to Kwalify YAML schema
|
17
17
|
# @param dest Path to resulting JSON schema
|
@@ -28,13 +28,13 @@ module KwalifyToJsonSchema
|
|
28
28
|
# The source and destination strings can be JSON or YAML.
|
29
29
|
# Other extension will fallback to JSON.
|
30
30
|
# Converter options:
|
31
|
-
# | Name | Type | Default value| Description
|
32
|
-
#
|
33
|
-
# | :id |
|
34
|
-
# | :title |
|
35
|
-
# | :description |
|
36
|
-
# | :issues_to_description|
|
37
|
-
# | :custom_processing |
|
31
|
+
# | Name | Type | Default value| Description |
|
32
|
+
# |-----------------------|--------|--------------|------------------------------------------------------------------------------------------|
|
33
|
+
# | :id | string | nil | The JSON schema identifier |
|
34
|
+
# | :title | string | nil | The JSON schema title |
|
35
|
+
# | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present|
|
36
|
+
# | :issues_to_description| boolean| false | To append the issuses to the JSON schema description |
|
37
|
+
# | :custom_processing | object | nil | To customize the conversion |
|
38
38
|
# --
|
39
39
|
# @param kwalify_schema Kwalify schema as YAML or JSON
|
40
40
|
# @param source_format format of the source schema
|
@@ -2,20 +2,20 @@ module KwalifyToJsonSchema
|
|
2
2
|
# The possible options for the conversion and the associated accessors
|
3
3
|
class Options
|
4
4
|
# Converter options:
|
5
|
-
# | Name | Type | Default value| Description
|
6
|
-
#
|
7
|
-
# | :id |
|
8
|
-
# | :title |
|
9
|
-
# | :description |
|
10
|
-
# | :issues_to_description|
|
11
|
-
# | :custom_processing |
|
5
|
+
# | Name | Type | Default value| Description |
|
6
|
+
# |-----------------------|--------|--------------|------------------------------------------------------------------------------------------|
|
7
|
+
# | :id | string | nil | The JSON schema identifier |
|
8
|
+
# | :title | string | nil | The JSON schema title |
|
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
|
+
# | :custom_processing | object | nil | To customize the conversion |
|
12
12
|
# --
|
13
13
|
DECLARATION = %q(
|
14
|
-
ID # The JSON schema identifier [
|
15
|
-
TITLE # The JSON schema title [
|
16
|
-
DESCRIPTION # The JSON schema description [
|
17
|
-
ISSUES_TO_DESCRIPTION # To append the issuses to the JSON schema description [
|
18
|
-
CUSTOM_PROCESSING # To customize the conversion [
|
14
|
+
ID # The JSON schema identifier [string] (nil)
|
15
|
+
TITLE # The JSON schema title [string] (nil)
|
16
|
+
DESCRIPTION # The JSON schema description. If not given the Kwalify description will be used if present [string] (nil)
|
17
|
+
ISSUES_TO_DESCRIPTION # To append the issuses to the JSON schema description [boolean] (false)
|
18
|
+
CUSTOM_PROCESSING # To customize the conversion [object] (nil)
|
19
19
|
)
|
20
20
|
|
21
21
|
# The options as Hash
|
@@ -40,13 +40,13 @@ module KwalifyToJsonSchema
|
|
40
40
|
default_value = eval(default_value)
|
41
41
|
|
42
42
|
# Create read accessor
|
43
|
-
attr_reader_name = "#{name}#{type == "
|
43
|
+
attr_reader_name = "#{name}#{type == "boolean" ? "?" : ""}"
|
44
44
|
|
45
45
|
# Array entry as Hash for the option
|
46
46
|
{
|
47
47
|
const_name: const_name,
|
48
48
|
const_name_full: "#{Options.name}::#{const_name}",
|
49
|
-
name: name,
|
49
|
+
name: name.to_sym,
|
50
50
|
description: description,
|
51
51
|
type: type,
|
52
52
|
default_value: default_value,
|
@@ -55,6 +55,11 @@ module KwalifyToJsonSchema
|
|
55
55
|
}.compact
|
56
56
|
end
|
57
57
|
|
58
|
+
# Same as :parse but give a Hash with the name as key
|
59
|
+
def self.parse_hash
|
60
|
+
parse.map { |e| [e[:name], e] }.to_h
|
61
|
+
end
|
62
|
+
|
58
63
|
# Setup the constants and methods for the options
|
59
64
|
# Example: ID will lead to get ID constant and :id method
|
60
65
|
def self.setup
|
@@ -69,6 +74,12 @@ module KwalifyToJsonSchema
|
|
69
74
|
}
|
70
75
|
end
|
71
76
|
|
77
|
+
# Get description for option name
|
78
|
+
def self.cli_option(name)
|
79
|
+
o = parse_hash[name]
|
80
|
+
[o[:name], :type => o[:type].to_sym, :default => o[:default_value], :desc => o[:description]]
|
81
|
+
end
|
82
|
+
|
72
83
|
setup
|
73
84
|
end
|
74
85
|
end
|
@@ -25,7 +25,7 @@ module KwalifyToJsonSchema
|
|
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
|
-
|
28
|
+
{ "json" => Json, "yaml" => Yaml }[format] || Json
|
29
29
|
end
|
30
30
|
|
31
31
|
class Language
|