Class: Lutaml::Jsonschema::Schema
- Defined in:
- lib/lutaml/jsonschema/base.rb,
lib/lutaml/jsonschema/schema.rb
Overview
Forward declaration for circular references (Schema ↔ PropertyEntry ↔ Link).
Instance Method Summary collapse
- #all_property_entries ⇒ Object
- #array? ⇒ Boolean
- #noop_serializer(_instance, _hash) ⇒ Object
- #object? ⇒ Boolean
- #parse_additional_properties(instance, value) ⇒ Object
- #parse_legacy_definitions(instance, value) ⇒ Object
- #parse_type(instance, value) ⇒ Object
- #ref? ⇒ Boolean
- #serialize_additional_properties(instance, hash) ⇒ Object
- #serialize_type(instance, hash) ⇒ Object
- #types ⇒ Object
Instance Method Details
#all_property_entries ⇒ Object
185 186 187 188 189 |
# File 'lib/lutaml/jsonschema/schema.rb', line 185 def all_property_entries result = property_entries.dup all_of.each { |s| result.concat(s.all_property_entries) } result end |
#array? ⇒ Boolean
171 172 173 |
# File 'lib/lutaml/jsonschema/schema.rb', line 171 def array? types.include?("array") end |
#noop_serializer(_instance, _hash) ⇒ Object
191 |
# File 'lib/lutaml/jsonschema/schema.rb', line 191 def noop_serializer(_instance, _hash); end |
#object? ⇒ Boolean
167 168 169 |
# File 'lib/lutaml/jsonschema/schema.rb', line 167 def object? types.include?("object") end |
#parse_additional_properties(instance, value) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/lutaml/jsonschema/schema.rb', line 149 def parse_additional_properties(instance, value) case value when true, false instance.additional_properties = value when Hash instance.additional_properties_schema = Schema.from_json(value.to_json) end end |
#parse_legacy_definitions(instance, value) ⇒ Object
193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/lutaml/jsonschema/schema.rb', line 193 def parse_legacy_definitions(instance, value) return unless value.is_a?(Hash) value.each do |name, schema_hash| next if instance.definition_entries.any? { |e| e.name == name } instance.definition_entries.push( PropertyEntry.new( name: name, schema: Schema.from_json(schema_hash.to_json), ), ) end end |
#parse_type(instance, value) ⇒ Object
137 138 139 |
# File 'lib/lutaml/jsonschema/schema.rb', line 137 def parse_type(instance, value) instance.type = value.is_a?(Array) ? value.join(",") : value end |
#ref? ⇒ Boolean
181 182 183 |
# File 'lib/lutaml/jsonschema/schema.rb', line 181 def ref? !!dollar_ref end |
#serialize_additional_properties(instance, hash) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'lib/lutaml/jsonschema/schema.rb', line 158 def serialize_additional_properties(instance, hash) if instance.additional_properties_schema hash["additionalProperties"] = JSON.parse(instance.additional_properties_schema.to_json) elsif !instance.additional_properties.nil? hash["additionalProperties"] = instance.additional_properties end end |
#serialize_type(instance, hash) ⇒ Object
141 142 143 144 145 146 147 |
# File 'lib/lutaml/jsonschema/schema.rb', line 141 def serialize_type(instance, hash) t = instance.type return unless t parts = t.split(",") hash["type"] = parts.length == 1 ? parts.first : parts end |
#types ⇒ Object
175 176 177 178 179 |
# File 'lib/lutaml/jsonschema/schema.rb', line 175 def types return [] unless type type.split(",") end |