Class: KwalifyToJsonSchema::Converter
- Inherits:
-
Object
- Object
- KwalifyToJsonSchema::Converter
- Defined in:
- lib/kwalify_to_json_schema/converter.rb
Overview
Heart of conversion implementation
Example of use:
kwalify_schema = YAML.load(File.read(“kwalify_schema.yaml”))
converter = KwalifyToJsonSchema::Converter.new(options) json_schema = converter.exec(kwalify_schema)
File.write(“json_schema.json”, JSON.pretty_generate(json_schema))
Constant Summary collapse
- SCHEMA =
"http://json-schema.org/%s/schema#"
Instance Attribute Summary collapse
-
#issues ⇒ Object
readonly
Give the list of issues encontered while converting as array of strings.
-
#options ⇒ Object
readonly
The options given used to initialized the converter.
Instance Method Summary collapse
-
#exec(kwalify_schema) ⇒ Object
Execute the conversion process.
-
#initialize(options = {}) ⇒ Converter
constructor
Converter options: | Name | Type | Default value| Description | |———————–|——–|————–|——————————————————————————————| | :id | string | nil | The JSON schema identifier | | :title | string | nil | The JSON schema title | | :description | string | nil | The JSON schema description.
Constructor Details
#initialize(options = {}) ⇒ Converter
Converter options: | Name | Type | Default value| Description | |———————–|——–|————–|——————————————————————————————| | :id | string | nil | The JSON schema identifier | | :title | string | nil | The JSON schema title | | :description | string | nil | The JSON schema description. If not given the Kwalify description will be used if present| | :issues_to_description| boolean| false | To append the issues to the JSON schema description | | :issues_to_stderr | boolean| false | To write the issues to standard error output | | :custom_processing | object | nil | To customize the conversion | | :schema_version | string | “draft-04” | JSON schema version. Changing this value only change the value of $schema field | | :verbose | boolean| false | To be verbose when converting | –
34 35 36 37 |
# File 'lib/kwalify_to_json_schema/converter.rb', line 34 def initialize( = {}) @options = Options.new() @issues = Issues.new end |
Instance Attribute Details
#issues ⇒ Object (readonly)
Give the list of issues encontered while converting as array of strings.
19 20 21 |
# File 'lib/kwalify_to_json_schema/converter.rb', line 19 def issues @issues end |
#options ⇒ Object (readonly)
The options given used to initialized the converter
17 18 19 |
# File 'lib/kwalify_to_json_schema/converter.rb', line 17 def @options end |
Instance Method Details
#exec(kwalify_schema) ⇒ Object
Execute the conversion process
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/kwalify_to_json_schema/converter.rb', line 42 def exec(kwalify_schema) kwalify_schema = YAML.load(kwalify_schema) if kwalify_schema.is_a? String kwalify_schema = preprocess(kwalify_schema.dup) json_schema = process(root, kwalify_schema) if issues.any? && .issues_to_description? description = json_schema["description"] ||= "" description << "Issues when converting from Kwalify:\n" description << issues.descriptions_uniq.map { |description| "* #{description}" }.join("\n") end # Override description if given in option json_schema["description"] = .description if .description STDERR.puts issues if .issues_to_stderr? postprocess(json_schema) end |