Module: Schematist::JsonOutput
- Included in:
- Schema
- Defined in:
- lib/schematist/json_output.rb
Constant Summary collapse
- DRAFT_2020_12 =
"https://json-schema.org/draft/2020-12/schema"
Instance Method Summary collapse
- #to_json(*_args) ⇒ Object
-
#to_json_schema ⇒ Object
A Draft 2020-12 JSON Schema document, string-keyed and ready for any JSON Schema validator.
Instance Method Details
#to_json(*_args) ⇒ Object
22 23 24 25 |
# File 'lib/schematist/json_output.rb', line 22 def to_json(*_args) validate! # Validate schema before generating JSON string JSON.pretty_generate(to_json_schema) end |
#to_json_schema ⇒ Object
A Draft 2020-12 JSON Schema document, string-keyed and ready for any JSON Schema validator
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/schematist/json_output.rb', line 8 def to_json_schema validate! # Validate schema before generating JSON document = schema_body class_description = document.delete(:description) header = { "$schema" => DRAFT_2020_12, title: document.delete(:title) || @name, description: @description || class_description }.compact json_compatible(resolve_runtime_values(header.merge(document))) end |