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.
36 37 38 39 40 |
# File 'lib/cocina/json_schema_wrapper.rb', line 36 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.
34 35 36 |
# File 'lib/cocina/json_schema_wrapper.rb', line 34 def name @name end |
Instance Method Details
#all_of ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/cocina/json_schema_wrapper.rb', line 59 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
111 112 113 |
# File 'lib/cocina/json_schema_wrapper.rb', line 111 def default @schema_def['default'] end |
#deprecated ⇒ Object
95 96 97 |
# File 'lib/cocina/json_schema_wrapper.rb', line 95 def deprecated @schema_def['deprecated'] end |
#description ⇒ Object
99 100 101 |
# File 'lib/cocina/json_schema_wrapper.rb', line 99 def description @schema_def['description'] end |
#enum ⇒ Object
107 108 109 |
# File 'lib/cocina/json_schema_wrapper.rb', line 107 def enum @schema_def['enum'] end |
#example ⇒ Object
103 104 105 |
# File 'lib/cocina/json_schema_wrapper.rb', line 103 def example @schema_def['example'] end |
#format ⇒ Object
115 116 117 |
# File 'lib/cocina/json_schema_wrapper.rb', line 115 def format @schema_def['format'] end |
#items ⇒ Object
119 120 121 122 123 124 125 126 127 128 |
# File 'lib/cocina/json_schema_wrapper.rb', line 119 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
87 88 89 |
# File 'lib/cocina/json_schema_wrapper.rb', line 87 def nullable @schema_def['nullable'] end |
#one_of ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cocina/json_schema_wrapper.rb', line 46 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
91 92 93 |
# File 'lib/cocina/json_schema_wrapper.rb', line 91 def pattern @schema_def['pattern'] end |
#properties ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cocina/json_schema_wrapper.rb', line 72 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
83 84 85 |
# File 'lib/cocina/json_schema_wrapper.rb', line 83 def required @schema_def['required'] end |
#type ⇒ Object
42 43 44 |
# File 'lib/cocina/json_schema_wrapper.rb', line 42 def type @schema_def['type'] end |