Class: Cocina::Generator::SchemaArray

Inherits:
SchemaBase
  • Object
show all
Defined in:
lib/cocina/generator/schema_array.rb

Overview

Class for generating from an openapi array

Constant Summary collapse

GENERIC_ITEMS_NAME =
'items'

Instance Attribute Summary

Attributes inherited from SchemaBase

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

Instance Method Summary collapse

Methods inherited from SchemaBase

#any_datatype?, #custom_type?, #datatype_from_doc_names, #datatype_from_doc_type, #defined_datatypes?, #deprecation, #description, #dry_datatype, #example, #filename, #initialize, #name, #optional, #preamble, #quote, #relaxed_comment, #string_dry_datatype

Constructor Details

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

Instance Method Details

#array_of_typeObject



13
14
15
16
17
18
# File 'lib/cocina/generator/schema_array.rb', line 13

def array_of_type
  items_name = schema_doc.items.name
  return items_name unless items_name == GENERIC_ITEMS_NAME

  dry_datatype(schema_doc.items)
end

#generateObject



9
10
11
# File 'lib/cocina/generator/schema_array.rb', line 9

def generate
  "attribute :#{name.camelize(:lower)}, Types::Strict::Array.of(#{array_of_type}).default([].freeze)"
end