Class: Cocina::JsonSchemaWrapper::SchemaWrapper
- Inherits:
-
Object
- Object
- Cocina::JsonSchemaWrapper::SchemaWrapper
- Defined in:
- lib/cocina/json_schema_wrapper.rb
Overview
Wrapper for individual schemas
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #all_of ⇒ Object
- #default ⇒ Object
- #deprecated ⇒ Object
- #description ⇒ Object
- #enum ⇒ Object
- #example ⇒ Object
- #format ⇒ Object
-
#initialize(schema_def, name, parent) ⇒ SchemaWrapper
constructor
A new instance of SchemaWrapper.
- #items ⇒ Object
- #nullable ⇒ Object
- #one_of ⇒ Object
- #pattern ⇒ Object
- #properties ⇒ Object
- #required ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(schema_def, name, parent) ⇒ SchemaWrapper
Returns a new instance of SchemaWrapper.
37 38 39 40 41 |
# File 'lib/cocina/json_schema_wrapper.rb', line 37 def initialize(schema_def, name, parent) @schema_def = schema_def @name = name @parent = parent end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
35 36 37 |
# File 'lib/cocina/json_schema_wrapper.rb', line 35 def name @name end |
Instance Method Details
#all_of ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cocina/json_schema_wrapper.rb', line 60 def all_of return [] unless @schema_def['allOf'] @schema_def['allOf'].map do |schema| if schema['$ref'] ref_name = schema['$ref'].split('/').last SchemaWrapper.new(@parent.spec.dig('$defs', ref_name), ref_name, @parent) else SchemaWrapper.new(schema, nil, @parent) end end end |
#default ⇒ Object
112 113 114 |
# File 'lib/cocina/json_schema_wrapper.rb', line 112 def default @schema_def['default'] end |
#deprecated ⇒ Object
96 97 98 |
# File 'lib/cocina/json_schema_wrapper.rb', line 96 def deprecated @schema_def['deprecated'] end |
#description ⇒ Object
100 101 102 |
# File 'lib/cocina/json_schema_wrapper.rb', line 100 def description @schema_def['description'] end |
#enum ⇒ Object
108 109 110 |
# File 'lib/cocina/json_schema_wrapper.rb', line 108 def enum @schema_def['enum'] end |
#example ⇒ Object
104 105 106 |
# File 'lib/cocina/json_schema_wrapper.rb', line 104 def example @schema_def['example'] end |
#format ⇒ Object
116 117 118 |
# File 'lib/cocina/json_schema_wrapper.rb', line 116 def format @schema_def['format'] end |
#items ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/cocina/json_schema_wrapper.rb', line 120 def items return nil unless @schema_def['items'] if @schema_def['items']['$ref'] ref_name = @schema_def['items']['$ref'].split('/').last SchemaWrapper.new(@parent.spec.dig('$defs', ref_name), ref_name, @parent) else SchemaWrapper.new(@schema_def['items'], Generator::SchemaArray::GENERIC_ITEMS_NAME, @parent) end end |
#nullable ⇒ Object
88 89 90 |
# File 'lib/cocina/json_schema_wrapper.rb', line 88 def nullable @schema_def['nullable'] end |
#one_of ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/cocina/json_schema_wrapper.rb', line 47 def one_of return [] unless @schema_def['oneOf'] @schema_def['oneOf'].map do |schema| if schema['$ref'] ref_name = schema['$ref'].split('/').last SchemaWrapper.new(@parent.spec.dig('$defs', ref_name), ref_name, @parent) else SchemaWrapper.new(schema, nil, @parent) end end end |
#pattern ⇒ Object
92 93 94 |
# File 'lib/cocina/json_schema_wrapper.rb', line 92 def pattern @schema_def['pattern'] end |
#properties ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cocina/json_schema_wrapper.rb', line 73 def properties @schema_def['properties']&.transform_values do |schema| if schema['$ref'] ref_name = schema['$ref'].split('/').last SchemaWrapper.new(@parent.spec.dig('$defs', ref_name), ref_name, @parent) else SchemaWrapper.new(schema, nil, @parent) end end end |
#required ⇒ Object
84 85 86 |
# File 'lib/cocina/json_schema_wrapper.rb', line 84 def required @schema_def['required'] end |
#type ⇒ Object
43 44 45 |
# File 'lib/cocina/json_schema_wrapper.rb', line 43 def type @schema_def['type'] end |