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, strict_reference_validation: true) ⇒ SchemaResolver
constructor
A new instance of SchemaResolver.
- #path_matcher ⇒ Object
- #schemer ⇒ Object
Constructor Details
#initialize(spec_path: nil, document: nil, strict_reference_validation: true) ⇒ SchemaResolver
Returns a new instance of SchemaResolver.
6 7 8 9 10 11 12 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 6 def initialize(spec_path: nil, document: nil, strict_reference_validation: true) @spec_path = spec_path @document = document @strict_reference_validation = strict_reference_validation @path_matcher = nil @schemer = nil end |
Instance Method Details
#document ⇒ Object
14 15 16 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 14 def document @document ||= load_document.tap { |doc| validate_document!(doc) } end |
#find_operation(method, request_path) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 26 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
22 23 24 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 22 def path_matcher @path_matcher ||= PathMatcher.new(document.fetch("paths", {}).keys) end |
#schemer ⇒ Object
18 19 20 |
# File 'lib/openapi_ruby/middleware/schema_resolver.rb', line 18 def schemer @schemer ||= JSONSchemer.openapi(document) end |