Class: Lutaml::Model::Schema::BaseSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/model/schema/base_schema.rb

Direct Known Subclasses

JsonSchema, YamlSchema

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, schema:, id: nil, title: nil, description: nil) ⇒ BaseSchema

Returns a new instance of BaseSchema.



26
27
28
29
30
31
32
# File 'lib/lutaml/model/schema/base_schema.rb', line 26

def initialize(klass, schema:, id: nil, title: nil, description: nil)
  @schema = schema
  @klass = klass
  @id = id
  @title = title
  @description = description
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



24
25
26
# File 'lib/lutaml/model/schema/base_schema.rb', line 24

def description
  @description
end

#idObject

Returns the value of attribute id.



24
25
26
# File 'lib/lutaml/model/schema/base_schema.rb', line 24

def id
  @id
end

#klassObject (readonly)

Returns the value of attribute klass.



23
24
25
# File 'lib/lutaml/model/schema/base_schema.rb', line 23

def klass
  @klass
end

#schemaObject (readonly)

Returns the value of attribute schema.



23
24
25
# File 'lib/lutaml/model/schema/base_schema.rb', line 23

def schema
  @schema
end

#titleObject

Returns the value of attribute title.



24
25
26
# File 'lib/lutaml/model/schema/base_schema.rb', line 24

def title
  @title
end

Class Method Details

.generate(klass, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/lutaml/model/schema/base_schema.rb', line 10

def generate(klass, options = {})
  schema = new(
    klass,
    schema: options[:schema],
    id: options[:id],
    title: options[:title],
    description: options[:description],
  ).generate_schema_hash

  format_schema(schema, options)
end

Instance Method Details

#generate_schema_hashObject



34
35
36
37
38
39
40
41
42
# File 'lib/lutaml/model/schema/base_schema.rb', line 34

def generate_schema_hash
  {
    "$schema" => schema,
    "$id" => id,
    "description" => description,
    "$ref" => "#/$defs/#{klass.name.gsub('::', '_')}",
    "$defs" => generate_definitions(klass),
  }.compact
end