jhthorsen / mojolicious-plugin-openapi

OpenAPI / Swagger plugin for Mojolicious
54 stars 44 forks source link

OpenAPI3 array parameters #149

Closed augensalat closed 4 years ago

augensalat commented 4 years ago

I want to define a query parameter with OpenAPI3 that can be specified multiple times:

GET /list?order=name&order=age

The spec is basically

components:
  parameters:
    orderParam:
      in: query
      name: order
      style: form
      explode: true
      schema:
        type: array
        items:
          type: string
        minItems: 1
      required: false

This works for the above example, but fails when only one order is specified:

GET /list?order=name

Response:

{
    "errors": [
        {
            "message": "Expected array - got string.",
            "path": "/order"
        }
    ],
    "status": 400
}

If I understand https://swagger.io/docs/specification/serialization/ correctly, the following tests should pass.

https://gist.github.com/augensalat/316b3af7cb53978a61e1ed3075d995d5

I found that code which seems to do the right thing for Swagger2. https://github.com/jhthorsen/mojolicious-plugin-openapi/blob/7537ffccc7934fde85bc44e2978c7d4449c025d8/lib/JSON/Validator/OpenAPI/Mojolicious.pm#L166-L185 Probably this still has to be adapted to v3?

jhthorsen commented 4 years ago

This isn't supported at all:

And there seems to be a bug when there's only one item.

I welcome a PR!

augensalat commented 4 years ago

I would love to, but I still wait until #150 is really settled.

jhthorsen commented 4 years ago

I think this is fixed in #154 now.