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 Attribute Summary collapse
-
#path_item ⇒ Object
readonly
Returns the value of attribute path_item.
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.
14 15 16 17 18 19 |
# File 'lib/openapi_first/runtime_request.rb', line 14 def initialize(request:, path_item:, operation:, path_params:) @request = request @path_item = path_item @operation = operation @original_path_params = path_params end |
Instance Attribute Details
#path_item ⇒ Object (readonly)
Returns the value of attribute path_item.
25 26 27 |
# File 'lib/openapi_first/runtime_request.rb', line 25 def path_item @path_item end |
Instance Method Details
#body ⇒ Object Also known as: parsed_body
73 74 75 |
# File 'lib/openapi_first/runtime_request.rb', line 73 def body @body ||= BodyParser.new.parse(request, request.media_type) end |
#cookies ⇒ Object
66 67 68 69 70 71 |
# File 'lib/openapi_first/runtime_request.rb', line 66 def return {} unless operation. @cookies ||= OpenapiParameters::Cookie.new(operation.).unpack(request.env[Rack::HTTP_COOKIE]) || {} end |
#headers ⇒ Object
60 61 62 63 64 |
# File 'lib/openapi_first/runtime_request.rb', line 60 def headers return {} unless operation.header_parameters @headers ||= OpenapiParameters::Header.new(operation.header_parameters).unpack_env(request.env) || {} end |
#known? ⇒ Boolean
27 28 29 |
# File 'lib/openapi_first/runtime_request.rb', line 27 def known? known_path? && known_request_method? end |
#known_path? ⇒ Boolean
31 32 33 |
# File 'lib/openapi_first/runtime_request.rb', line 31 def known_path? !!path_item end |
#known_request_method? ⇒ Boolean
35 36 37 |
# File 'lib/openapi_first/runtime_request.rb', line 35 def known_request_method? !!operation end |
#params ⇒ Object
Merged path and query parameters
40 41 42 |
# File 'lib/openapi_first/runtime_request.rb', line 40 def params @params ||= query.merge(path_parameters) end |
#path_parameters ⇒ Object
44 45 46 47 48 49 |
# File 'lib/openapi_first/runtime_request.rb', line 44 def path_parameters return {} unless operation.path_parameters @path_parameters ||= OpenapiParameters::Path.new(operation.path_parameters).unpack(@original_path_params) || {} end |
#query ⇒ Object Also known as: query_parameters
51 52 53 54 55 56 |
# File 'lib/openapi_first/runtime_request.rb', line 51 def query return {} unless operation.query_parameters @query ||= OpenapiParameters::Query.new(operation.query_parameters).unpack(request.env[Rack::QUERY_STRING]) || {} end |
#response(rack_response) ⇒ Object
87 88 89 |
# File 'lib/openapi_first/runtime_request.rb', line 87 def response(rack_response) RuntimeResponse.new(operation, rack_response) end |
#validate ⇒ Object
78 79 80 |
# File 'lib/openapi_first/runtime_request.rb', line 78 def validate RequestValidation::Validator.new(operation).validate(self) end |
#validate! ⇒ Object
82 83 84 85 |
# File 'lib/openapi_first/runtime_request.rb', line 82 def validate! error = validate error&.raise! end |