Class: Lacerda::Conversion::DataStructure::Member::Type
- Inherits:
-
Object
- Object
- Lacerda::Conversion::DataStructure::Member::Type
- Defined in:
- lib/lacerda/conversion/data_structure/member/type.rb
Instance Method Summary collapse
-
#array_type ⇒ Object
bui As there are specied types in the array, ‘nil` should not be a valid value and therefore required should be true.
-
#initialize(type_definition, is_required, scope) ⇒ Type
constructor
A new instance of Type.
- #object? ⇒ Boolean
-
#to_hash ⇒ Object
A type is transformed to json schema either as a primitive: { “type” => [“string”] } { “type” => [“string”, “null”] } Or as a oneOf.
Constructor Details
#initialize(type_definition, is_required, scope) ⇒ Type
Returns a new instance of Type.
6 7 8 9 10 11 |
# File 'lib/lacerda/conversion/data_structure/member/type.rb', line 6 def initialize(type_definition, is_required, scope) @type_definition = type_definition @scope = scope @type_name = type_definition['element'] @is_required = is_required end |
Instance Method Details
#array_type ⇒ Object
bui As there are specied types in the array, ‘nil` should not be a valid value and therefore required should be true.
33 34 35 36 37 38 39 40 |
# File 'lib/lacerda/conversion/data_structure/member/type.rb', line 33 def array_type return unless array? if nested_types.size == 1 && PRIMITIVES.include?(nested_types.first) primitive(nested_types.first, true) else oneOf(nested_types, true) end end |
#object? ⇒ Boolean
13 14 15 |
# File 'lib/lacerda/conversion/data_structure/member/type.rb', line 13 def object? @type_name == 'object' end |
#to_hash ⇒ Object
A type is transformed to json schema either as a primitive:
{ "type" => ["string"] }
{ "type" => ["string", "null"] }
Or as a oneOf. $ref are always within a oneOf
{"oneOf"=>[{"$ref"=>"#/definitions/tag"}, {"type"=>"null"}]}
22 23 24 25 26 27 28 |
# File 'lib/lacerda/conversion/data_structure/member/type.rb', line 22 def to_hash if PRIMITIVES.include?(@type_name) primitive(@type_name, required?) else oneOf([@type_name], required?) end end |