Forum Discussion

mmateyak's avatar
mmateyak
New Contributor
5 years ago

Explode a query param's properties not working correctly

Swagger 2.1.2 embedded as part of springdoc 1.3.4

 

I'm attempting to explode a query param object meant to express a range of years (2019-2020 for example), defined as follows:

 

      parameters:
      - name: requestParameters
        in: query
        required: false
        style: form
        explode: true
        schema:
          type: object
          properties:
            year:
              maxItems: 2
              minItems: 2
              type: array
              items:
                type: integer
                format: int32

 

 

However there is an issue whereas Swagger UI displays the query param as a single object Parameter containing the properties under it still, which is incorrect.  With "form" and "explode" it should populate each request parameter as it's own query param.  However when importing into Postman 7.22.1, the Params are all listed separately, which is correct (although Postman is still encapsulating it as a single element object as &year=[<int>,<int>], not exploded &year=<int>&year=<int>

 

Swagger UI presentation:

requestParameters
object
(query)
=
{
"year": [
0
]

}

Should be:

year
array[integer]
(query)
=
{
 [
0,0
]

}

 

Similarly, other properties defined under the "requestParameters" Parameter in the spec are enums and their enum values/items are not fully exploded and elevated to Parameters.

2 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    Change your parameter definition to:

          parameters:
          - name: year
            in: query
            required: false
            style: form
            explode: true
            schema:
              type: array
              maxItems: 2
              minItems: 2
              items:
                type: integer
                format: int32

     

  • mmateyak's avatar
    mmateyak
    New Contributor

    HKosova 

    Unfortunately, I'm not explicitly defining the JSON/YAML spec, it is autogenerated between springdoc which is built on top of swagger.

     

    I am starting with @RequestParam MultiValueMap<String, String> requestParameter which I don't have the ability to change easily and the spec is built as noted in the original post.

     

    So I guess there are two follow up questions:

    1) Is the swagger UI parsing the generated structure as expected/desired?  If so, any idea why postman would parse the same spec (OAS 3) differently?  I would think both would parse it exactly the same, per the spec.

     

    2) Per your recommendation, how would an underlying property of a parameter's schema be elevated to it's own parameter with it's own schema programmatically?  I had thought the explode+form features would effectively do that per the documentation here:

     

    https://swagger.io/docs/specification/serialization/#query

     

    Object id = {"role": "admin", "firstName": "Alex"}

    form *true */users{?id*}/users?id=5/users?id=3&id=4&id=5/users?role=admin&firstName=Alex

     

    Does this not apply to a Map as a request parameter object with an underlying array property?

     

     

    Thanks,
    Matt