kwalify_to_json_schema 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9e7de38a589bad1cb9d5850e28ed875a341e6024d9236f1633c212771814edc
4
- data.tar.gz: eff3ee76a633a828a43b584651754c7ac300b89cf4b90917c0625ea98cd11473
3
+ metadata.gz: 5cf3ece3c538c1574fff63993e51e8e6eb284c29761ab610cb3b0731853747c7
4
+ data.tar.gz: 33e5b9c4cbed92021fd1e5b9502a33f48b502ae7e56cb949ef20f878c459f64f
5
5
  SHA512:
6
- metadata.gz: c5c0d389205182ba2ac093f5cd120aaf6e3d202ab06da674f8d837d4641259d096597788dca2a5e19f29a65d921e1253f816b868056f419602a5b2acdb804eaf
7
- data.tar.gz: dd1ef9b5e4d27fd0e6d60eba4dd36b3adbb68517a9bac2ab1a28a1c40f9e419ce6fb56538713cd0279758fe7c91d12686c4ecfd858c90f32c6c239be922bd0dc
6
+ metadata.gz: 3be33ae75e36dabe85f77d8267ffe98c14def6d8c58243c210c3926e48c5c5257564b57f49d0792e9c5c33d4a2d20c268042305d32fee4bc957a0536a6e1aa75
7
+ data.tar.gz: 5d21d177961dedd730b4b2ae73d4225c15a508340440e3cd1f89cbbff24a7c4d56a5e0af524ca48cf690ac4e1042734ca2f00d34a5ba1c5e9513921e0d67a29e
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kwalify_to_json_schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Gamot
@@ -87,21 +87,15 @@ executables:
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema.rb"
91
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/cli.rb"
92
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/converter.rb"
93
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/custom_processing.rb"
94
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/kwalify_to_json_schema.rb"
95
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/limitations.rb"
96
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/options.rb"
97
- - "/home/sylvain/kwalify_to_json_schema/lib/kwalify_to_json_schema/serialization.rb"
98
- - "/home/sylvain/kwalify_to_json_schema/test/custom_processing.rb"
99
- - "/home/sylvain/kwalify_to_json_schema/test/test_kwalify_to_json_schema.rb"
100
- - "/home/sylvain/kwalify_to_json_schema/tools/all.rb"
101
- - "/home/sylvain/kwalify_to_json_schema/tools/doc_template.rb"
102
- - "/home/sylvain/kwalify_to_json_schema/tools/limitations.rb"
103
- - "/home/sylvain/kwalify_to_json_schema/tools/options.rb"
104
90
  - bin/kwalify_to_json_schema
91
+ - lib/kwalify_to_json_schema.rb
92
+ - lib/kwalify_to_json_schema/cli.rb
93
+ - lib/kwalify_to_json_schema/converter.rb
94
+ - lib/kwalify_to_json_schema/custom_processing.rb
95
+ - lib/kwalify_to_json_schema/kwalify_to_json_schema.rb
96
+ - lib/kwalify_to_json_schema/limitations.rb
97
+ - lib/kwalify_to_json_schema/options.rb
98
+ - lib/kwalify_to_json_schema/serialization.rb
105
99
  homepage: https://github.com/s-ga/kwalify_to_json_schema
106
100
  licenses:
107
101
  - MIT
@@ -1,14 +0,0 @@
1
- # Customization of Kwalify to JSON schema
2
- class CustomProcessing
3
- def preprocess(kwalify_schema)
4
- # Remove and keep the wrapping name
5
- head = kwalify_schema.first
6
- @name = head.first
7
- head.last
8
- end
9
-
10
- def postprocess(json_schema)
11
- # Restore the wrapping name
12
- { @name => json_schema }
13
- end
14
- end
@@ -1,75 +0,0 @@
1
- require "minitest/autorun"
2
- require "json-schema"
3
- require_relative "../lib/kwalify_to_json_schema"
4
-
5
- module KwalifyToJsonSchema
6
- class Test < Minitest::Test
7
- @@debug = false
8
- @@tmpdir = Dir.mktmpdir
9
-
10
- [
11
- { test_group: "conversion", cli_options: [] },
12
- { test_group: "custom_processing", cli_options: ["--custom-processing", File.join(__dir__, "custom_processing.rb")] },
13
- ].each { |entry|
14
- test_group = entry[:test_group]
15
- cli_options = entry[:cli_options]
16
-
17
- # Create a test method for every Kwalify schema
18
- Dir.glob(File.join(__dir__, test_group, "kwalify", "*.yaml")).each { |source|
19
- test_file_base = File.basename(source, File.extname(source))
20
- test_name_base = test_file_base.gsub("#", "_")
21
- expected_formats = %w(json yaml)
22
-
23
- # Define a method for the test JSON output
24
- define_method("test_#{test_group}_#{test_name_base}_output".to_sym) {
25
- formats_done = 0
26
- expected_formats.map { |expected_format|
27
- output_file = test_file_base + ".#{expected_format}"
28
- expected = File.join(File.join(__dir__, test_group, "json_schema", expected_format, output_file))
29
-
30
- next unless File.exist?(expected)
31
- formats_done += 1
32
-
33
- ser = KwalifyToJsonSchema::Serialization::serialization_for_format(expected_format)
34
- dest = File.join(@@tmpdir, output_file)
35
-
36
- args = ["convert", source, dest]
37
- # Add issues to description if filename include "#issues_to_description"
38
- args << "--issues_to_description" if output_file.include?("#issues_to_description")
39
- args.concat cli_options
40
-
41
- # Convert
42
- # KwalifyToJsonSchema.convert_file(source, dest, options)
43
- KwalifyToJsonSchema::Cli.start(args)
44
-
45
- # Validate schema
46
- validate_json_schema_file(dest)
47
-
48
- if @@debug
49
- puts test_name_base
50
- puts ser.normalize(File.read(dest))
51
- end
52
- # Compare to expected result
53
- assert_equal(
54
- ser.normalize(File.read(expected)),
55
- ser.normalize(File.read(dest))
56
- )
57
- }
58
-
59
- skip "None of the expected #{expected_formats.join(", ")} result for test #{test_name_base} was found" if formats_done == 0
60
- }
61
- }
62
- }
63
-
64
- def validate_json_schema_file(schema_file)
65
- schema = KwalifyToJsonSchema::Serialization::deserialize_from_file(schema_file)
66
- validate_json_schema(schema)
67
- end
68
-
69
- def validate_json_schema(schema)
70
- # FIXME draft7 is not available in current json-schema gem
71
- metaschema = JSON::Validator.validator_for_name("draft4").metaschema
72
- JSON::Validator.validate!(metaschema, schema)
73
- end
74
- end
75
- end
@@ -1,4 +0,0 @@
1
- require_relative "../lib/kwalify_to_json_schema"
2
- require_relative "doc_template"
3
- require_relative "limitations"
4
- require_relative "options"
@@ -1,13 +0,0 @@
1
- require "erb"
2
-
3
- module DocTemplate
4
- def self.render(template_file, dest_file)
5
- template = ERB.new(File.read(template_file), nil, "-")
6
- File.write(dest_file, template.result(get_binding(template_file)))
7
- end
8
-
9
- def self.get_binding(template_file)
10
- template_dir = File.dirname template_file
11
- binding
12
- end
13
- end
@@ -1,19 +0,0 @@
1
- require_relative "../lib/kwalify_to_json_schema/limitations"
2
-
3
- # Gives implementation limitations
4
- module Limitations
5
-
6
- # @return list of limitation as array of strings
7
- def self.list
8
- KwalifyToJsonSchema::Limitations.constants.map { |cst|
9
- KwalifyToJsonSchema::Limitations.const_get(cst)
10
- }
11
- end
12
-
13
- # @return limitation as markdown text
14
- def self.markdown
15
- list.map { |l|
16
- "* #{l}"
17
- }.join("\n")
18
- end
19
- end
@@ -1,96 +0,0 @@
1
- require "yaml"
2
- require_relative "../lib/kwalify_to_json_schema/options"
3
-
4
- # Gives implementation limitations
5
- module Options
6
-
7
- # @return list of limitation as array of strings
8
- def self.list
9
- KwalifyToJsonSchema::Options.parse
10
- end
11
-
12
- # @return limitation as markdown text
13
- def self.ascii_table(formatting = ["%s"] * 4)
14
- header = ["Name", "Type", "Default value", "Description"]
15
-
16
- nb_cols = header.length
17
-
18
- table = [header] +
19
- [[""] * nb_cols] +
20
- list.map { |o|
21
- [
22
- formatting[0] % o[:name].to_sym.inspect,
23
- formatting[1] % o[:type],
24
- formatting[2] % o[:default_value].inspect,
25
- formatting[3] % o[:description],
26
- ]
27
- }
28
- nb_rows = table.length
29
-
30
- cols_max_length = (0..nb_cols - 1).map { |c|
31
- (0..nb_rows - 1).map { |r|
32
- cell = table[r][c]
33
- cell.length
34
- }.max
35
- }
36
-
37
- table.map.each_with_index { |row, r|
38
- row.map.each_with_index { |cell, c|
39
- max_length = cols_max_length[c]
40
- if r == 1
41
- "|-" + cell + ("-" * (max_length - cell.length))
42
- else
43
- "| " + cell + (" " * (max_length - cell.length))
44
- end
45
- }.join + "|"
46
- }.join "\n"
47
- end
48
-
49
- def self.markdown
50
- ascii_table [
51
- "`%s`",
52
- "`%s`",
53
- "`%s`",
54
- "_%s_",
55
- ]
56
- end
57
-
58
- def self.inject_as_code_comment(file)
59
- new_lines = []
60
- state = :init
61
- count = 0
62
-
63
- options_start = "Converter options:"
64
- options_stop = "--"
65
-
66
- File.read(file).each_line { |line|
67
- if line.strip.start_with? "#"
68
- content = line.strip[1..-1].strip
69
- case state
70
- when :init
71
- new_lines << line
72
- if content == options_start
73
- count += 1
74
- state = :in_options
75
- padding = line.index("#")
76
- new_lines.concat(ascii_table.lines.map { |l| "#{" " * padding}# #{l.chomp}\n" })
77
- end
78
- when :in_options
79
- if content.start_with? options_stop
80
- new_lines << line
81
- state = :init
82
- end
83
- end
84
- else
85
- state = :error unless state == :init
86
- new_lines << line
87
- end
88
- }
89
-
90
- if state == :error
91
- puts "Missing '#{options_stop}' delimiter after '#{options_start}' in file://#{file}"
92
- else
93
- File.write(file, new_lines.join) if count > 0
94
- end
95
- end
96
- end