openapi-core icon indicating copy to clipboard operation
openapi-core copied to clipboard

Multi-query parameter validation not working

Open stojan-jovic opened this issue 4 years ago • 2 comments

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!

stojan-jovic avatar Jun 27 '21 01:06 stojan-jovic

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

p1c2u avatar Jun 30 '21 13:06 p1c2u

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 avatar Jun 30 '21 14:06 stojan-jovic

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 avatar Apr 09 '24 18:04 stojan-jovic

@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!?

stojan-jovic avatar Apr 09 '24 18:04 stojan-jovic

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

p1c2u avatar Apr 11 '24 08:04 p1c2u

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

stojan-jovic avatar Apr 11 '24 15:04 stojan-jovic

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?

p1c2u avatar Apr 11 '24 18:04 p1c2u

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 avatar Apr 12 '24 04:04 stojan-jovic

@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.

stojan-jovic avatar Apr 17 '24 01:04 stojan-jovic