postmanlabs / postman-app-support

Postman is an API platform for building and using APIs. Postman simplifies each step of the API lifecycle and streamlines collaboration so you can create better APIs—faster.
https://www.postman.com
5.85k stars 841 forks source link

Import collection from OAS: duplicated query parameter when type is array of string items #11948

Open maticardenas opened 1 year ago

maticardenas commented 1 year ago

Is there an existing issue for this?

Describe the Issue

We have the update of our public collections automated through the usage of Postman API's /import/openapi endpoint. We've noticed that one of our endpoints got a duplicated query parameter, and after doing some test we identified that this only happens when the parameter is defined as an array of string in its OAS definition:

      parameters:
        - schema:
            type: array
            items:
              type: string
              example: postnl
          in: query
          name: carrier_code
          description: selection of carriers
          required: true

In other paths and endpoints that we have in the same OAS where the parameter is defined as simple string, duplication at the collection doesn't happen.

Steps To Reproduce

  1. Grab an OpenAPI specification with an endpoint with a set of parameters where one is defined as type array with items of type string
  2. Import the OAS as collection through Postman API's /import/openapi
  3. When going to the collection's request corresponding to the OAS endpoint in question, the parameter appears duplicated, which is wrong and misleading for users.

Screenshots or Videos

image

Operating System

macOS

Postman Version

10.12.11

Postman Platform

Postman App

User Account Type

Signed In User

Additional Context?

No response

davidespihernandez commented 1 year ago

Hi, Matías! Thanks for your question! I'm not sure if this is an error. A correct way of passing an array of values using the query string is:

?array=value1&array=value2&array=value3

You can also pass a single string with comma-separated values, like:

?array=value1,value2

There's no standard way of passing arrays (it depends on the implementation/framework), but repeating the name of the variable in the query string is a commonly accepted one (the default way in several web frameworks, actually). I think this is what is reflected in the generated collection.

If you are using a single string with comma-separated values, perhaps you have to change the OpenAPI definition to reflect that. This article can give you more information about this: https://medium.com/raml-api/arrays-in-query-params-33189628fa68

Please let me know if you need more help.

petkostas commented 1 year ago

Hi @davidespihernandez the main problem here is that it is not very clear that this is a list/array. Maybe would be good to add a remark on the representation (e.g. an array of strings)

aman-v-singh commented 1 year ago

Hey @petkostas, Thanks for your question.

As @davidespihernandez has mentioned, there can be multiple ways of passing an array of values as a query string. The representation depends on the backend server's framework, hence the repetition of the variable name itself can be considered as a representation of an array of values. If you would like to pass the array of values as a single string with comma-separated values, you can make use of the style and explode attributes of the Parameter object.

For Example:-

    parameters:
      - schema:
          type: array
          items:
            type: string
            example: postnl
        in: query
        name: carrier_code
        description: selection of carriers
        required: true
        style: form
        explode: false

image

You can refer to the following link for further details and examples about style and explode attributes. https://spec.openapis.org/oas/v3.1.0#style-values

Please let us know if you need more help.

petkostas commented 1 year ago

@aman-v-singh I am not referring to the implementation. I am referring to how Postman displays them. It isn't very clear for the user (check the screenshot of @maticardenas ) when he sees the multiple keys in the Query params table of Postman.