Class: OpenapiFirst::RuntimeRequest
- Inherits:
-
Object
- Object
- OpenapiFirst::RuntimeRequest
- Extended by:
- Forwardable
- Defined in:
- lib/openapi_first/runtime_request.rb
Overview
RuntimeRequest represents how an incoming request (Rack::Request) matches a request definition.
Instance Method Summary collapse
- #body ⇒ Object (also: #parsed_body)
- #cookies ⇒ Object
- #headers ⇒ Object
-
#initialize(request:, path_item:, operation:, path_params:) ⇒ RuntimeRequest
constructor
A new instance of RuntimeRequest.
- #known? ⇒ Boolean
- #known_path? ⇒ Boolean
- #known_request_method? ⇒ Boolean
-
#params ⇒ Object
Merged path and query parameters.
- #path_parameters ⇒ Object
- #query ⇒ Object (also: #query_parameters)
- #response(rack_response) ⇒ Object
- #validate ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(request:, path_item:, operation:, path_params:) ⇒ RuntimeRequest
Returns a new instance of RuntimeRequest.
13 14 15 16 17 18 |
# File 'lib/openapi_first/runtime_request.rb', line 13 def initialize(request:, path_item:, operation:, path_params:) @request = request @path_item = path_item @operation = operation @original_path_params = path_params end |
Instance Method Details
#body ⇒ Object Also known as: parsed_body
62 63 64 |
# File 'lib/openapi_first/runtime_request.rb', line 62 def body @body ||= BodyParser.new.parse(request, request.media_type) end |
#cookies ⇒ Object
57 58 59 60 |
# File 'lib/openapi_first/runtime_request.rb', line 57 def @cookies ||= operation.&.unpack(request.env) || {} end |
#headers ⇒ Object
52 53 54 55 |
# File 'lib/openapi_first/runtime_request.rb', line 52 def headers @headers ||= operation.header_parameters&.unpack(request.env) || {} end |
#known? ⇒ Boolean
23 24 25 |
# File 'lib/openapi_first/runtime_request.rb', line 23 def known? known_path? && known_request_method? end |
#known_path? ⇒ Boolean
27 28 29 |
# File 'lib/openapi_first/runtime_request.rb', line 27 def known_path? !!path_item end |
#known_request_method? ⇒ Boolean
31 32 33 |
# File 'lib/openapi_first/runtime_request.rb', line 31 def known_request_method? !!operation end |
#params ⇒ Object
Merged path and query parameters
36 37 38 |
# File 'lib/openapi_first/runtime_request.rb', line 36 def params @params ||= query.merge(path_parameters) end |
#path_parameters ⇒ Object
40 41 42 43 |
# File 'lib/openapi_first/runtime_request.rb', line 40 def path_parameters @path_parameters ||= operation.path_parameters&.unpack(@original_path_params) || {} end |
#query ⇒ Object Also known as: query_parameters
45 46 47 48 |
# File 'lib/openapi_first/runtime_request.rb', line 45 def query @query ||= operation.query_parameters&.unpack(request.env) || {} end |
#response(rack_response) ⇒ Object
76 77 78 |
# File 'lib/openapi_first/runtime_request.rb', line 76 def response(rack_response) RuntimeResponse.new(operation, rack_response) end |
#validate ⇒ Object
67 68 69 |
# File 'lib/openapi_first/runtime_request.rb', line 67 def validate RequestValidation::Validator.new(operation).validate(self) end |
#validate! ⇒ Object
71 72 73 74 |
# File 'lib/openapi_first/runtime_request.rb', line 71 def validate! error = validate error&.raise! end |