Module: KwalifyToJsonSchema
- Defined in:
- lib/kwalify_to_json_schema/cli.rb,
lib/kwalify_to_json_schema/issue.rb,
lib/kwalify_to_json_schema/issues.rb,
lib/kwalify_to_json_schema/options.rb,
lib/kwalify_to_json_schema/converter.rb,
lib/kwalify_to_json_schema/limitations.rb,
lib/kwalify_to_json_schema/serialization.rb,
lib/kwalify_to_json_schema/custom_processing.rb,
lib/kwalify_to_json_schema/kwalify_to_json_schema.rb
Defined Under Namespace
Modules: Limitations, Serialization Classes: Cli, Converter, CustomProcessing, Issue, Issues, Options
Class Method Summary collapse
-
.convert_file(source, dest, options = {}) ⇒ Object
Convert a Kwalify schema file to JSON .schema.
-
.convert_string(kwalify_schema, source_format = "yaml", dest_format = "json", options = {}) ⇒ Object
Convert a Kwalify schema string to JSON .schema.
Class Method Details
.convert_file(source, dest, options = {}) ⇒ Object
Convert a Kwalify schema file to JSON .schema. The destination file can be JSON or YAML. The file extension is used to select the format: .json or .yaml. Other extension will fallback to JSON. 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 | –
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kwalify_to_json_schema/kwalify_to_json_schema.rb', line 21 def self.convert_file(source, dest, = {}) = Options.new() puts "Converting file://#{File. source } to file://#{File. dest}" if .verbose? # Get a converter converter = Converter.new() # Convert converted = converter.exec(Serialization.deserialize_from_file(source)) # Serialize Serialization.serialize_to_file(dest, converted) end |
.convert_string(kwalify_schema, source_format = "yaml", dest_format = "json", options = {}) ⇒ Object
Convert a Kwalify schema string to JSON .schema. The source and destination strings can be JSON or YAML. Other extension will fallback to JSON. 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 | –
52 53 54 55 56 57 58 59 60 |
# File 'lib/kwalify_to_json_schema/kwalify_to_json_schema.rb', line 52 def self.convert_string(kwalify_schema, source_format = "yaml", dest_format = "json", = {}) = Options.new() # Get a converter converter = Converter.new() # Convert converted = converter.exec(Serialization.deserialize_from_string(kwalify_schema, source_format)) # Serialize Serialization.serialize_to_string(converted, dest_format) end |