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_register.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: ReferenceRegister
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 docuemnt.
-
#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.
91 92 93 94 95 96 97 98 |
# File 'lib/openapi3_parser/document.rb', line 91 def initialize(source_input) @reference_register = ReferenceRegister.new @root_source = Source.new(source_input, self, reference_register) @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.
21 22 23 |
# File 'lib/openapi3_parser/document.rb', line 21 def openapi_version @openapi_version end |
#root_source ⇒ Source (readonly)
Returns the current value of root_source.
21 22 23 |
# File 'lib/openapi3_parser/document.rb', line 21 def root_source @root_source end |
#warnings ⇒ Array<String> (readonly)
Returns the current value of warnings.
21 22 23 |
# File 'lib/openapi3_parser/document.rb', line 21 def warnings @warnings end |
Instance Method Details
#[] ⇒ Object
Look up an attribute on the root of the OpenAPI document by String or Symbol
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
124 125 126 127 128 |
# File 'lib/openapi3_parser/document.rb', line 124 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 def_delegators :root, :openapi, :info, :servers, :paths, :components, :security, :tags, :external_docs, :extension, :[], :each, :keys |
#inspect ⇒ String
165 166 167 168 |
# File 'lib/openapi3_parser/document.rb', line 165 def inspect %{#{self.class.name}(openapi_version: #{openapi_version}, } + %{root_source: #{root_source.inspect})} end |
#keys ⇒ Object
Access keys of the root object
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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 docuemnt
Examples:
document.node_at(“#/components/schemas”) document.node_at(%w[components schemas])
160 161 162 |
# File 'lib/openapi3_parser/document.rb', line 160 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
109 110 111 112 |
# File 'lib/openapi3_parser/document.rb', line 109 def reference_sources build unless built reference_register.sources 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
146 147 148 |
# File 'lib/openapi3_parser/document.rb', line 146 def resolved_input_at(pointer, relative_to = nil) look_up_pointer(pointer, relative_to, factory.resolved_input) end |
#root ⇒ Node::Openapi
101 102 103 |
# File 'lib/openapi3_parser/document.rb', line 101 def root factory.node end |
#security ⇒ Node::Array<Node::SecurityRequirement>
The value of the security field on the OpenAPI document
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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.
135 136 137 |
# File 'lib/openapi3_parser/document.rb', line 135 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
117 118 119 |
# File 'lib/openapi3_parser/document.rb', line 117 def sources [root_source] + reference_sources end |
#tags ⇒ Node::Array<Node::Tag>
The value of the tags field on the OpenAPI document
86 87 88 |
# File 'lib/openapi3_parser/document.rb', line 86 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
39 |
# File 'lib/openapi3_parser/document.rb', line 39 def_delegator :factory, :valid? |