Class: Lutaml::Model::Schema::Generator::Definition

Inherits:
Object
  • Object
show all
Includes:
SharedMethods
Defined in:
lib/lutaml/model/schema/generator/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SharedMethods

#extract_register_from

Constructor Details

#initialize(type) ⇒ Definition



13
14
15
16
# File 'lib/lutaml/model/schema/generator/definition.rb', line 13

def initialize(type)
  @type = type
  @name = type.name.gsub("::", "_")
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/lutaml/model/schema/generator/definition.rb', line 11

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



11
12
13
# File 'lib/lutaml/model/schema/generator/definition.rb', line 11

def type
  @type
end

Instance Method Details

#to_schemaObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/lutaml/model/schema/generator/definition.rb', line 18

def to_schema
  @schema = {
    name => {
      "type" => "object",
      "additionalProperties" => false,
      "properties" => properties_to_schema(type),
    },
  }

  # Add choice validation if present
  if type.choice_attributes.any?
    @schema[name]["oneOf"] = generate_choice_attributes(type)
  end

  @schema
end