Class: Cocina::Generator::Schema

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

Overview

Class for generating from an openapi schema

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

#generateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cocina/generator/schema.rb', line 11

def generate
  "    # frozen_string_literal: true\n\n    module Cocina\n      module Models\#{'              '}\n        \#{preamble}class \#{name} < Struct\n\n          \#{validate}\n          \#{types}\n\n          \#{model_attributes}\n        end\n      end\n    end\n  RUBY\nend\n"

#schema_propertiesObject



7
8
9
# File 'lib/cocina/generator/schema.rb', line 7

def schema_properties
  @schema_properties ||= (properties + all_of_properties + one_of_properties).uniq(&:key)
end