Class: Cocina::Generator::SchemaRef

Inherits:
SchemaBase show all
Defined in:
lib/cocina/generator/schema_ref.rb

Overview

Class for generating from an openapi reference

Instance Attribute Summary

Attributes inherited from SchemaBase

#key, #nullable, #parent, #relaxed, #required, #schema_doc

Instance Method Summary collapse

Methods inherited from SchemaBase

#any_datatype?, #description, #dry_datatype, #example, #filename, #initialize, #name, #omittable, #optional, #quote, #relaxed_comment, #string_dry_datatype

Constructor Details

This class inherits a constructor from Cocina::Generator::SchemaBase

Instance Method Details

#generateObject



7
8
9
10
11
12
13
# File 'lib/cocina/generator/schema_ref.rb', line 7

def generate
  if required && !relaxed
    "attribute(:#{name.camelize(:lower)}, #{schema_doc.name}.default { #{schema_doc.name}.new })"
  else
    "attribute :#{name.camelize(:lower)}, #{schema_doc.name}.optional.meta(omittable: true)"
  end
end