Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If assert_request_schema_confirm and Committee::Middleware::RequestValidation are used at the same time, date-time validation fails. #283

Open
tsukaby opened this issue Sep 12, 2020 · 2 comments

Comments

@tsukaby
Copy link

tsukaby commented Sep 12, 2020

Description

If I use Committee::Middleware::RequestValidation, the date-time conversion is done at the same time as the request is processed.
Then, if I run assert_request_schema_confirm, the conversion is already completed and the validation will fail in the following part
https://github.com/ota42y/openapi_parser/blob/v0.12.1/lib/openapi_parser/schema_validators/string_validator.rb#L11
At this time, the value is already converted to DateTime.

Is this a bug?
If you have any solutions, please let me know.

Environment

ruby 2.7.1
rails 6.0.3.2
committee 4.2.0
rspec 3.9.0

application.rb

config.middleware.use Committee::Middleware::RequestValidation, schema_path: schema_path, parse_response_by_content_type: false

OpenAPI 3.0 yaml

/contents:
  get:
    summary: example
    description: example
    parameters:
      - in: query
        name: q
        description: filtering
        required: false
        style: deepObject
        schema:
          type: object
          description: filtering
          properties:
            start_at_gteq:
              type: string
              description: start_at greater than or equal
              format: date-time
              example: "2019-10-01T00:00:00+9:00"
              nullable: true
            end_at_lteq:
              type: string
              description: end_at less than or equal
              format: date-time
              example: "2019-10-31T23:59:59+9:00"
              nullable: true
    responses:
      "200":
        description: contents list
...

spec

it "foo" do
  get contents_url(q: { start_at_gteq: "2020-01-01", end_at_lteq: "2020-01-31" })
  assert_request_schema_confirm
  assert_response_schema_confirm
  expect(response).to have_http_status(:success)
end

spec result

Committee::InvalidRequest: #/.../schema/properties/end_at_lteq expected string, but received DateTime: 2020-01-31T00:00:00+00:00

  0) ContentsController request spec GET #index ...
     Failure/Error: assert_request_schema_confirm

     Committee::InvalidRequest:
       #/.../schema/properties/end_at_lteq expected string, but received DateTime: 2020-01-31T00:00:00+00:00
     # ./spec/spec.rb:98:in `block (6 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # OpenAPIParser::ValidateError:
     #   #/.../schema/properties/end_at_lteq expected string, but received DateTime: 2020-01-31T00:00:00+00:00
     #   ./spec/spec.rb:98:in `block (6 levels) in <top (required)>'

screenshot

@ota42y
Copy link
Member

ota42y commented Oct 11, 2020

Well, there seems to be a problem because I wasn't thinking about using this function at the same time.

It seems that we need to add warning or put in some workaround.

@tsukaby
Copy link
Author

tsukaby commented Oct 12, 2020

Thank you.
I'll let you know if I come up with any workarounds as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants