Class: OpenapiFirst::ValidatedRequest
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- OpenapiFirst::ValidatedRequest
- Extended by:
- Forwardable
- Defined in:
- lib/openapi_first/validated_request.rb
Overview
A validated request. It can be valid or not.
Instance Attribute Summary collapse
-
#error ⇒ Failure?
readonly
A Failure object if the request is invalid.
-
#request_definition ⇒ Request?
readonly
The request definition if this request is defined in the API description.
Instance Method Summary collapse
-
#initialize(original_request, error:, parsed_values: {}, request_definition: nil) ⇒ ValidatedRequest
constructor
A new instance of ValidatedRequest.
-
#invalid? ⇒ Boolean
Checks if the request is invalid.
-
#known? ⇒ Boolean
Returns true if the request is defined.
-
#operation ⇒ Hash
The raw OpenAPI 3 operation object.
-
#operation_id ⇒ String?
The OpenAPI 3 operationId.
-
#parsed_body ⇒ Hash<String, anything>
Parsed body.
-
#parsed_cookies ⇒ Hash<String, anything>
Parsed cookies.
-
#parsed_headers ⇒ Hash<String, anything>
Parsed headers.
-
#parsed_params ⇒ Hash<String, anything>
Merged path, query, body parameters.
-
#parsed_path_parameters ⇒ Hash<String, anything>
Parsed path parameters.
-
#parsed_query ⇒ Hash<String, anything>
Parsed query parameters.
-
#valid? ⇒ Boolean
Checks if the request is valid.
Constructor Details
#initialize(original_request, error:, parsed_values: {}, request_definition: nil) ⇒ ValidatedRequest
Returns a new instance of ValidatedRequest.
11 12 13 14 15 16 |
# File 'lib/openapi_first/validated_request.rb', line 11 def initialize(original_request, error:, parsed_values: {}, request_definition: nil) super(original_request) @parsed_values = Hash.new({}).merge(parsed_values) @error = error @request_definition = request_definition end |
Instance Attribute Details
#error ⇒ Failure? (readonly)
A Failure object if the request is invalid
20 21 22 |
# File 'lib/openapi_first/validated_request.rb', line 20 def error @error end |
#request_definition ⇒ Request? (readonly)
The request definition if this request is defined in the API description
24 25 26 |
# File 'lib/openapi_first/validated_request.rb', line 24 def request_definition @request_definition end |
Instance Method Details
#invalid? ⇒ Boolean
Checks if the request is invalid.
73 74 75 |
# File 'lib/openapi_first/validated_request.rb', line 73 def invalid? !valid? end |
#known? ⇒ Boolean
Returns true if the request is defined.
78 79 80 |
# File 'lib/openapi_first/validated_request.rb', line 78 def known? request_definition != nil end |
#operation ⇒ Hash
Returns The raw OpenAPI 3 operation object.
32 |
# File 'lib/openapi_first/validated_request.rb', line 32 def_delegator :request_definition, :operation |
#operation_id ⇒ String?
Returns The OpenAPI 3 operationId.
28 |
# File 'lib/openapi_first/validated_request.rb', line 28 def_delegator :request_definition, :operation_id |
#parsed_body ⇒ Hash<String, anything>
Parsed body. This parses the body according to the content type. Note that this returns the hole body, not only the fields that are defined in the OpenAPI spec. You can use JSON Schemas ‘additionalProperties` or `unevaluatedProperties` to returns a validation error if the body contains unknown fields.
63 64 65 |
# File 'lib/openapi_first/validated_request.rb', line 63 def parsed_body @parsed_values[:body] end |
#parsed_cookies ⇒ Hash<String, anything>
Parsed cookies. This only returns the query parameters that are defined in the OpenAPI spec.
54 55 56 |
# File 'lib/openapi_first/validated_request.rb', line 54 def @parsed_values[:cookies] end |
#parsed_headers ⇒ Hash<String, anything>
Parsed headers. This only returns the query parameters that are defined in the OpenAPI spec.
48 49 50 |
# File 'lib/openapi_first/validated_request.rb', line 48 def parsed_headers @parsed_values[:headers] end |
#parsed_params ⇒ Hash<String, anything>
Merged path, query, body parameters. Here path has the highest precedence, then query, then body.
85 86 87 |
# File 'lib/openapi_first/validated_request.rb', line 85 def parsed_params @parsed_params ||= parsed_body.merge(parsed_query, parsed_path_parameters) end |
#parsed_path_parameters ⇒ Hash<String, anything>
Parsed path parameters
36 37 38 |
# File 'lib/openapi_first/validated_request.rb', line 36 def parsed_path_parameters @parsed_values[:path] end |
#parsed_query ⇒ Hash<String, anything>
Parsed query parameters. This only returns the query parameters that are defined in the OpenAPI spec.
42 43 44 |
# File 'lib/openapi_first/validated_request.rb', line 42 def parsed_query @parsed_values[:query] end |
#valid? ⇒ Boolean
Checks if the request is valid.
68 69 70 |
# File 'lib/openapi_first/validated_request.rb', line 68 def valid? error.nil? end |