Class: Jsapi::Meta::Schema::Discriminator
- Defined in:
- lib/jsapi/meta/schema/discriminator.rb
Instance Method Summary collapse
-
#mappings ⇒ Object
:attr: mappings.
-
#property_name ⇒ Object
:attr: property_name.
-
#resolve(value, definitions) ⇒ Object
Looks up the inherriting schema for
valueindefinitions. -
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI discriminator object.
Methods inherited from Base
#initialize, #inspect, #reference?
Methods included from Attributes::ClassMethods
Constructor Details
This class inherits a constructor from Jsapi::Meta::Base
Instance Method Details
#mappings ⇒ Object
:attr: mappings
9 |
# File 'lib/jsapi/meta/schema/discriminator.rb', line 9 attribute :mappings, { String => String } |
#property_name ⇒ Object
:attr: property_name
13 |
# File 'lib/jsapi/meta/schema/discriminator.rb', line 13 attribute :property_name, String |
#resolve(value, definitions) ⇒ Object
Looks up the inherriting schema for value in definitions.
16 17 18 19 20 21 |
# File 'lib/jsapi/meta/schema/discriminator.rb', line 16 def resolve(value, definitions) schema = definitions.schema(mapping(value) || value) raise "inherriting schema not found: #{value.inspect}" unless schema schema.resolve(definitions) end |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI discriminator object.
24 25 26 27 28 29 30 31 32 |
# File 'lib/jsapi/meta/schema/discriminator.rb', line 24 def to_openapi(version) version = OpenAPI::Version.from(version) return property_name if version.major == 2 { propertyName: property_name, mapping: mappings }.compact end |