Class: OpenapiRuby::Middleware::SchemaResolver
- Inherits:
-
Object
- Object
- OpenapiRuby::Middleware::SchemaResolver
- Defined in:
- lib/openapi_ruby/middleware/schema_resolver.rb
Instance Method Summary collapse
- #document ⇒ Object
- #find_operation(method, request_path) ⇒ Object
-
#initialize(spec_path: nil, document: nil) ⇒ SchemaResolver
constructor
A new instance of SchemaResolver.
- #path_matcher ⇒ Object
- #schemer ⇒ Object
Constructor Details
#initialize(spec_path: nil, document: nil) ⇒ SchemaResolver
Returns a new instance of SchemaResolver.
6 7 8 9 10 11 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 6 def initialize(spec_path: nil, document: nil) @spec_path = spec_path @document = document @path_matcher = nil @schemer = nil end |
Instance Method Details
#document ⇒ Object
13 14 15 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 13 def document @document ||= load_document end |
#find_operation(method, request_path) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 25 def find_operation(method, request_path) result = path_matcher.match(request_path) return nil unless result template, path_params = result operation = document.dig("paths", template, method.downcase) return nil unless operation { operation: operation, template: template, path_params: path_params } end |
#path_matcher ⇒ Object
21 22 23 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 21 def path_matcher @path_matcher ||= PathMatcher.new(document.fetch("paths", {}).keys) end |
#schemer ⇒ Object
17 18 19 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 17 def schemer @schemer ||= JSONSchemer.openapi(document) end |