Class: OpenapiContracts::Doc
- Inherits:
-
Object
- Object
- OpenapiContracts::Doc
- Defined in:
- lib/openapi_contracts/doc.rb
Defined Under Namespace
Classes: FileParser, Header, Method, Parser, Path, Response, Schema
Instance Attribute Summary collapse
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(schema) ⇒ Doc
constructor
A new instance of Doc.
-
#paths ⇒ Object
Returns an Enumerator over all paths.
- #response_for(path, method, status) ⇒ Object
-
#responses(&block) ⇒ Object
Returns an Enumerator over all Responses.
- #with_path(path) ⇒ Object
Constructor Details
#initialize(schema) ⇒ Doc
17 18 19 20 21 22 |
# File 'lib/openapi_contracts/doc.rb', line 17 def initialize(schema) @schema = Schema.new(schema) @paths = @schema['paths'].to_h do |path, _| [path, Path.new(@schema.at_pointer(['paths', path]))] end end |
Instance Attribute Details
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
15 16 17 |
# File 'lib/openapi_contracts/doc.rb', line 15 def schema @schema end |
Class Method Details
.parse(dir, filename = 'openapi.yaml') ⇒ Object
11 12 13 |
# File 'lib/openapi_contracts/doc.rb', line 11 def self.parse(dir, filename = 'openapi.yaml') new Parser.call(dir, filename) end |
Instance Method Details
#paths ⇒ Object
Returns an Enumerator over all paths
25 26 27 |
# File 'lib/openapi_contracts/doc.rb', line 25 def paths @paths.each_value end |
#response_for(path, method, status) ⇒ Object
29 30 31 |
# File 'lib/openapi_contracts/doc.rb', line 29 def response_for(path, method, status) with_path(path)&.with_method(method)&.with_status(status) end |
#responses(&block) ⇒ Object
Returns an Enumerator over all Responses
34 35 36 37 38 39 40 41 42 |
# File 'lib/openapi_contracts/doc.rb', line 34 def responses(&block) return enum_for(:responses) unless block_given? paths.each do |path| path.methods.each do |method| method.responses.each(&block) end end end |
#with_path(path) ⇒ Object
44 45 46 |
# File 'lib/openapi_contracts/doc.rb', line 44 def with_path(path) @paths[path] end |