Class: Meta::JsonSchema::DynamicSchema
- Inherits:
-
BaseSchema
- Object
- BaseSchema
- Meta::JsonSchema::DynamicSchema
- Defined in:
- lib/meta/json_schema/schemas/dynamic_schema.rb
Instance Attribute Summary
Attributes inherited from BaseSchema
Instance Method Summary collapse
- #filter(value, user_options = {}) ⇒ Object
-
#initialize(resolver, one_of: nil, **base_options) ⇒ DynamicSchema
constructor
A new instance of DynamicSchema.
- #to_schema_doc(user_options) ⇒ Object
Methods inherited from BaseSchema
#defined_scopes, #filter?, #find_schema, #if?, #scoped, #staged, #to_schema, #value?
Constructor Details
#initialize(resolver, one_of: nil, **base_options) ⇒ DynamicSchema
Returns a new instance of DynamicSchema.
6 7 8 9 10 11 |
# File 'lib/meta/json_schema/schemas/dynamic_schema.rb', line 6 def initialize(resolver, one_of: nil, **) super() @resolver = resolver @one_of = one_of end |
Instance Method Details
#filter(value, user_options = {}) ⇒ Object
13 14 15 16 17 |
# File 'lib/meta/json_schema/schemas/dynamic_schema.rb', line 13 def filter(value, = {}) value = super(value, ) schema = @resolver.call(value).to_schema schema.filter(value, ) end |
#to_schema_doc(user_options) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/meta/json_schema/schemas/dynamic_schema.rb', line 19 def to_schema_doc() schema = { type: 'object' } schema[:oneOf] = @one_of.map do |schema| schema.to_schema_doc() end if @one_of schema end |