Class: Literal::Openapi::Adapters::OpenAPI3_0

Inherits:
BaseAdapter
  • Object
show all
Defined in:
lib/literal/openapi/adapters/open_api_3_0.rb

Direct Known Subclasses

OpenAPI3_1

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



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/literal/openapi/adapters/open_api_3_0.rb', line 8

def convert_nilable(type)
  inner = convert_type(type.type)
  # A bare `$ref` with `nullable: true` is invalid OpenAPI 3.0 (the nullable
  # is ignored because siblings to $ref are disallowed). Easy_talk works
  # around this by emitting an `anyOf` with a null branch. Mirror that for
  # parity.
  if inner.is_a?(::Hash) && inner.keys == ["$ref"]
    { "anyOf" => [inner, { "type" => "null" }] }
  else
    inner.merge("nullable" => true)
  end
end

#convert_oneof(types, include_null:) ⇒ Object



21
22
23
24
25
# File 'lib/literal/openapi/adapters/open_api_3_0.rb', line 21

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