Class: Literal::Openapi::Adapters::OpenAPI3_1

Inherits:
OpenAPI3_0 show all
Defined in:
lib/literal/openapi/adapters/open_api_3_1.rb

Constant Summary

Constants inherited from BaseAdapter

BaseAdapter::PRIMITIVE_MAP, BaseAdapter::PROPERTY_KEY_ORDER

Instance Method Summary collapse

Methods inherited from BaseAdapter

#build_schema, #convert_class_type, #convert_primitive, #convert_ref, #convert_type, #convert_union, #inline_schema, #ref_schema?, #reorder_property_keys, #schema_name

Instance Method Details

#convert_nilable(type) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/literal/openapi/adapters/open_api_3_1.rb', line 12

def convert_nilable(type)
  base = convert_type(type.type)
  base_type = base["type"]

  if base_type.is_a?(::String)
    base.merge("type" => [base_type, "null"])
  else
    { "oneOf" => [base, { "type" => "null" }] }
  end
end

#convert_oneof(types, include_null:) ⇒ Object



23
24
25
26
27
# File 'lib/literal/openapi/adapters/open_api_3_1.rb', line 23

def convert_oneof(types, include_null:)
  result = { "oneOf" => types.map { |t| convert_type(t) } }
  result["oneOf"] << { "type" => "null" } if include_null
  result
end