Skip to content

Multi-query parameter validation not working #366

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

Closed
stojan-jovic opened this issue Jun 27, 2021 · 9 comments · Fixed by #830
Closed

Multi-query parameter validation not working #366

stojan-jovic opened this issue Jun 27, 2021 · 9 comments · Fixed by #830
Labels
area/contrib Indicates an issue on contrib area. kind/bug Indicates an issue

Comments

@stojan-jovic
Copy link

stojan-jovic commented Jun 27, 2021

Validation for query parameter with multiple values (i.e. array values in form-style query expansion) not working, at least from version 0.13.3 of openapi-core.

Example request:

http://localhost:8000/v1/test?a=1&a=2

Appropriate OpenAPI spec to validate above parameters as a = ['1', '2']:

parameters:
  - in: query
    name: a
    description: Test query parameter.
    schema:
      type: array
      items:
        type: string
    required: true

Validation error:

openapi_core.unmarshalling.schemas.exceptions.InvalidSchemaValue: Value [['1', '2']] not valid for schema of type array: (<ValidationError: "['1', '2'] is not of type string">,)

Till version 0.13.8 it was possible to "cheat" validation by describing schema as:

parameters:
  - in: query
    name: a
    description: Test query parameter.
    schema: {}
    required: true

Unfortunately, above workaround not working anymore (from version 0.14.0), but strangely, schema can be described as follows:

parameters:
  - in: query
    name: a
    description: Test query parameter.
    schema:
      type: array
      items:
        type: array
        items:
          type: string
    required: true

However, this is not proper way to describe query parameter with multiple values and should be fixed!

@p1c2u
Copy link
Collaborator

p1c2u commented Jun 30, 2021

It must be something with the integration. I assume you use Falcon one?

@stojan-jovic
Copy link
Author

Yes, it's Falcon, little older version, 1.4.1. Could not remember did I test the latest Falcon version, but I will check and report here.

@stojan-jovic
Copy link
Author

In meantime, I migrated to the latest openapi-core version, i.e. 0.19.0, with latest Falcon integration (3.1.1).

Following still working partially:

parameters:
  - in: query
    name: a
    description: Test query parameter.
    schema:
      type: array
      items:
        type: array
        items:
          type: string
    required: true

"Partially" because it failing if I pass only one parameter (in all other combinations it working fine).

However, my question again is - why valid OpenAPI 3 description is not supported:

parameters:
  - in: query
    name: a
    description: Test query parameter.
    schema:
      type: array
      items:
        type: string
    required: true

Falcon properly decodes such request, for example request /v1/test?a=1&a=2 will be unpacked as {'a': ['1', '2']} (Falcon request params), but openapi-core reports validation error:

openapi_core.validation.schemas.exceptions.InvalidSchemaValue: Value [['1', '2']] not valid for schema of type array: (<ValidationError: "['1', '2'] is not of type 'string'">,)

Am I missing something here?

@stojan-jovic
Copy link
Author

@p1c2u I apologize for making noise, but how can I properly describe multi-value query parameters in OpenAPI 3 spec so that it working fine with openapi-core validation with Falcon integration (all the most recent versions)?

It must be that I'm doing something wrong, but not sure what!?

@p1c2u p1c2u added area/contrib Indicates an issue on contrib area. kind/bug Indicates an issue labels Apr 11, 2024
@p1c2u
Copy link
Collaborator

p1c2u commented Apr 11, 2024

I think I found the reason of this issue. I will prepare fix for that.

@stojan-jovic
Copy link
Author

stojan-jovic commented Apr 11, 2024

Thanks a lot, Arthur, but it still doesn't work for me... I may be missing something, but is this OpenAPI spec snippet proper description for multi-value query parameters:

parameters:
  - in: query
    name: a
    description: Test query parameter.
    schema:
      type: array
      items:
        type: string
    required: true

@p1c2u
Copy link
Collaborator

p1c2u commented Apr 11, 2024

yes this looks correct. you can have a look at my test for the issue and compare.

did you check master version? can you prepare minimal example?

@stojan-jovic
Copy link
Author

Oh man, I was looking at version 0.19.1 all the time, spent few hours in debugging, because I was almost sure that I'm doing something wrong. :(
I thought that it contains fix because it has been released at similar time when you announced news here on the ticket.

Latest code from the master working perfectly fine!!! Thanks a lot, one more time.

Can you please tell me when we can expect official release with this fix?

@stojan-jovic
Copy link
Author

@p1c2u I apologize for disturbing one more time, can you please just let me know are there plans to release this fix in coming days or it may need some more time?

Thanks in advance, appreciate your hard work as always.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/contrib Indicates an issue on contrib area. kind/bug Indicates an issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants