Class: OpenAPIParser::Schemas::OpenAPI

Inherits:
Base
  • Object
show all
Defined in:
lib/openapi_parser/schemas/classes.rb,
lib/openapi_parser/schemas/openapi.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#object_reference, #parent, #raw_schema, #root

Instance Method Summary collapse

Methods inherited from Base

#after_init, #inspect

Methods included from Expandable

#expand_reference

Methods included from Findable

#find_object, #purge_object_cache

Methods included from Parser

#_openapi_all_child_objects, #_update_child_object, included, #load_data

Constructor Details

#initialize(raw_schema, config, uri: nil, schema_registry: {}) ⇒ OpenAPI

Returns a new instance of OpenAPI.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/openapi_parser/schemas/openapi.rb', line 8

def initialize(raw_schema, config, uri: nil, schema_registry: {})
  super('#', nil, self, raw_schema)
  @find_object_cache = {}
  @path_item_finder = OpenAPIParser::PathItemFinder.new(paths) if paths # invalid definition
  @config = config
  @uri = uri
  @schema_registry = schema_registry

  # schema_registery is shared among schemas, and prevents a schema from being loaded multiple times
  schema_registry[uri] = self if uri
end

Instance Attribute Details

#componentsComponents? (readonly)

Returns:



30
# File 'lib/openapi_parser/schemas/openapi.rb', line 30

openapi_attr_object :components, Components, reference: false

#openapiString? (readonly)

Returns:

  • (String, nil)


22
# File 'lib/openapi_parser/schemas/openapi.rb', line 22

openapi_attr_values :openapi

#pathsPaths? (readonly)

Returns:



26
# File 'lib/openapi_parser/schemas/openapi.rb', line 26

openapi_attr_object :paths, Paths, reference: false

Instance Method Details

#load_another_schema(uri) ⇒ OpenAPIParser::Schemas::OpenAPI

load another schema with shared config and schema_registry



39
40
41
42
43
44
45
46
47
# File 'lib/openapi_parser/schemas/openapi.rb', line 39

def load_another_schema(uri)
  resolved_uri = resolve_uri(uri)
  return if resolved_uri.nil?

  loaded = @schema_registry[resolved_uri]
  return loaded if loaded

  OpenAPIParser.load_uri(resolved_uri, config: @config, schema_registry: @schema_registry)
end

#request_operation(http_method, request_path) ⇒ OpenAPIParser::RequestOperation?



33
34
35
# File 'lib/openapi_parser/schemas/openapi.rb', line 33

def request_operation(http_method, request_path)
  OpenAPIParser::RequestOperation.create(http_method, request_path, @path_item_finder, @config)
end