Class: Lutaml::Jsonschema::Schema

Inherits:
Base
  • Object
show all
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

Instance Method Details

#all_property_entriesObject



181
182
183
184
185
# File 'lib/lutaml/jsonschema/schema.rb', line 181

def all_property_entries
  result = property_entries.dup
  all_of.each { |s| result.concat(s.all_property_entries) }
  result
end

#array?Boolean

Returns:

  • (Boolean)


167
168
169
# File 'lib/lutaml/jsonschema/schema.rb', line 167

def array?
  types.include?("array")
end

#noop_serializer(_instance, _hash) ⇒ Object



187
# File 'lib/lutaml/jsonschema/schema.rb', line 187

def noop_serializer(_instance, _hash); end

#object?Boolean

Returns:

  • (Boolean)


163
164
165
# File 'lib/lutaml/jsonschema/schema.rb', line 163

def object?
  types.include?("object")
end

#parse_additional_properties(instance, value) ⇒ Object



146
147
148
149
150
151
152
153
# File 'lib/lutaml/jsonschema/schema.rb', line 146

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



189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'lib/lutaml/jsonschema/schema.rb', line 189

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



134
135
136
# File 'lib/lutaml/jsonschema/schema.rb', line 134

def parse_type(instance, value)
  instance.type = value.is_a?(Array) ? value.join(",") : value
end

#ref?Boolean

Returns:

  • (Boolean)


177
178
179
# File 'lib/lutaml/jsonschema/schema.rb', line 177

def ref?
  !!dollar_ref
end

#serialize_additional_properties(instance, hash) ⇒ Object



155
156
157
158
159
160
161
# File 'lib/lutaml/jsonschema/schema.rb', line 155

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



138
139
140
141
142
143
144
# File 'lib/lutaml/jsonschema/schema.rb', line 138

def serialize_type(instance, hash)
  t = instance.type
  return unless t

  parts = t.split(",")
  hash["type"] = parts.length == 1 ? parts.first : parts
end

#typesObject



171
172
173
174
175
# File 'lib/lutaml/jsonschema/schema.rb', line 171

def types
  return [] unless type

  type.split(",")
end