Class: Openapi3Parser::Document
- Inherits:
-
Object
- Object
- Openapi3Parser::Document
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/openapi3_parser/document.rb,
lib/openapi3_parser/document/reference_registry.rb
Overview
Document is the root construct of a created OpenAPI Document and can be used to navigate the contents of a document or to check it’s validity.
Defined Under Namespace
Classes: ReferenceRegistry
Constant Summary collapse
- SUPPORTED_OPENAPI_VERSIONS =
A collection of the openapi versions that are supported
%w[3.0].freeze
- DEFAULT_OPENAPI_VERSION =
The version of OpenAPI that will be used by default for validation/construction
"3.0"
Instance Attribute Summary collapse
-
#openapi_version ⇒ String
readonly
The current value of openapi_version.
-
#root_source ⇒ Source
readonly
The current value of root_source.
-
#warnings ⇒ Array<String>
readonly
The current value of warnings.
Instance Method Summary collapse
-
#[] ⇒ Object
Look up an attribute on the root of the OpenAPI document by String or Symbol.
-
#components ⇒ Node::Components
The value of the components field on the OpenAPI document.
-
#each ⇒ Object
Iterate through the attributes of the root object.
-
#errors ⇒ Validation::ErrorCollection
Any validation errors that are present on the OpenAPI document.
-
#extension ⇒ Hash, ...
Look up an extension field provided for the root object of the document.
-
#external_docs ⇒ Node::ExternalDocumentation?
The value of the external_docs field on the OpenAPI document.
-
#info ⇒ Node::Info
The value of the info field on the OpenAPI document.
-
#initialize(source_input) ⇒ Document
constructor
A new instance of Document.
- #inspect ⇒ String
-
#keys ⇒ Object
Access keys of the root object.
-
#node_at(pointer, relative_to = nil) ⇒ Object
Look up a node at a particular location in the OpenAPI document.
-
#openapi ⇒ String
The value of the openapi version field for this document.
-
#paths ⇒ Node::Paths
The value of the paths field on the OpenAPI document.
-
#reference_sources ⇒ Array<Source>
All the additional sources that have been referenced as part of loading the OpenAPI document.
-
#resolved_input_at(pointer, relative_to = nil) ⇒ Object
Look up the resolved input for an address in the OpenAPI document, resolved_input refers to the input with references resolevd and all optional fields existing.
- #root ⇒ Node::Openapi
-
#security ⇒ Node::Array<Node::SecurityRequirement>
The value of the security field on the OpenAPI document.
-
#servers ⇒ Node::Array<Node::Server>
The value of the servers field on the OpenAPI document.
-
#source_for_source_input(source_input) ⇒ Source?
Look up whether an instance of SourceInput is already a known source for this document.
-
#sources ⇒ Array<Source>
All of the sources involved in this OpenAPI document.
-
#tags ⇒ Node::Array<Node::Tag>
The value of the tags field on the OpenAPI document.
-
#valid? ⇒ Boolean
Whether this OpenAPI document has any validation issues or not.
Constructor Details
#initialize(source_input) ⇒ Document
Returns a new instance of Document.
82 83 84 85 86 87 88 89 |
# File 'lib/openapi3_parser/document.rb', line 82 def initialize(source_input) @reference_registry = ReferenceRegistry.new @root_source = Source.new(source_input, self, reference_registry) @warnings = [] @openapi_version = determine_openapi_version(root_source.data["openapi"]) @build_in_progress = false @built = false end |
Instance Attribute Details
#openapi_version ⇒ String (readonly)
Returns the current value of openapi_version.
12 13 14 |
# File 'lib/openapi3_parser/document.rb', line 12 def openapi_version @openapi_version end |
#root_source ⇒ Source (readonly)
Returns the current value of root_source.
12 13 14 |
# File 'lib/openapi3_parser/document.rb', line 12 def root_source @root_source end |
#warnings ⇒ Array<String> (readonly)
Returns the current value of warnings.
12 13 14 |
# File 'lib/openapi3_parser/document.rb', line 12 def warnings @warnings end |
Instance Method Details
#[] ⇒ Object
Look up an attribute on the root of the OpenAPI document by String or Symbol
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#components ⇒ Node::Components
The value of the components field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#each ⇒ Object
Iterate through the attributes of the root object
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#errors ⇒ Validation::ErrorCollection
Any validation errors that are present on the OpenAPI document
115 116 117 118 119 |
# File 'lib/openapi3_parser/document.rb', line 115 def errors reference_factories.inject(factory.errors) do |memo, f| Validation::ErrorCollection.combine(memo, f.errors) end end |
#extension ⇒ Hash, ...
Look up an extension field provided for the root object of the document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#external_docs ⇒ Node::ExternalDocumentation?
The value of the external_docs field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#info ⇒ Node::Info
The value of the info field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#inspect ⇒ String
156 157 158 159 |
# File 'lib/openapi3_parser/document.rb', line 156 def inspect %{#{self.class.name}(openapi_version: #{openapi_version}, } + %{root_source: #{root_source.inspect})} end |
#keys ⇒ Object
Access keys of the root object
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#node_at(pointer, relative_to = nil) ⇒ Object
Look up a node at a particular location in the OpenAPI document
Examples:
document.node_at(“#/components/schemas”) document.node_at(%w[components schemas])
151 152 153 |
# File 'lib/openapi3_parser/document.rb', line 151 def node_at(pointer, relative_to = nil) look_up_pointer(pointer, relative_to, root) end |
#openapi ⇒ String
The value of the openapi version field for this document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#paths ⇒ Node::Paths
The value of the paths field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#reference_sources ⇒ Array<Source>
All the additional sources that have been referenced as part of loading the OpenAPI document
100 101 102 103 |
# File 'lib/openapi3_parser/document.rb', line 100 def reference_sources build unless built reference_registry.sources.reject(&:root?) end |
#resolved_input_at(pointer, relative_to = nil) ⇒ Object
Look up the resolved input for an address in the OpenAPI document, resolved_input refers to the input with references resolevd and all optional fields existing
137 138 139 |
# File 'lib/openapi3_parser/document.rb', line 137 def resolved_input_at(pointer, relative_to = nil) look_up_pointer(pointer, relative_to, factory.resolved_input) end |
#root ⇒ Node::Openapi
92 93 94 |
# File 'lib/openapi3_parser/document.rb', line 92 def root @root ||= factory.node(Node::Context.root(factory.context)) end |
#security ⇒ Node::Array<Node::SecurityRequirement>
The value of the security field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#servers ⇒ Node::Array<Node::Server>
The value of the servers field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#source_for_source_input(source_input) ⇒ Source?
Look up whether an instance of SourceInput is already a known source for this document.
126 127 128 |
# File 'lib/openapi3_parser/document.rb', line 126 def source_for_source_input(source_input) sources.find { |source| source.source_input == source_input } end |
#sources ⇒ Array<Source>
All of the sources involved in this OpenAPI document
108 109 110 |
# File 'lib/openapi3_parser/document.rb', line 108 def sources [root_source] + reference_sources end |
#tags ⇒ Node::Array<Node::Tag>
The value of the tags field on the OpenAPI document
77 78 79 |
# File 'lib/openapi3_parser/document.rb', line 77 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#valid? ⇒ Boolean
Whether this OpenAPI document has any validation issues or not. See #errors to access the errors
30 |
# File 'lib/openapi3_parser/document.rb', line 30 def_delegator :factory, :valid? |