Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-135847

[OAS] Update multi-value query parameter logic to use style/explode (OpenAPI 3.0) instead of collectionFormat (OpenAPI 2.0)

    XMLWordPrintable

Details

    • Task
    • Resolution: Unresolved
    • P2: Important
    • None
    • None
    • Network
    • None

    Description

      In OpenAPI 2.0, multi-value query parameters were supported using the type: array and the collectionFormat property. For example:

      parameters:
        - name: param
          in: query
          type: array
          collectionFormat: pipes
          items:
            type: string 

      However, collectionFormat was deprecated in OpenAPI 3.0 and and the newer logic revolves around style and explode properties.

       See  https://swagger.io/specification/#style-values for reference.

      For example:

      • collectionFormat: csvstyle: form, explode: false
      • collectionFormat: multistyle: form, explode: true
      • collectionFormat: pipesstyle: pipeDelimited 
      • collectionFormat: ssvstyle: spaceDelimited
      • collectionFormat: tsv ** does not have an alternative anymore.

      Note: OAPI 2.0  collectionFormat value is still set in DefaultCodegen.java in openapi-generator-cli-7.12.0 based on  isExplode ans style values.

      Support for style and explode was added by the openapi team https://github.com/OpenAPITools/openapi-generator/commit/578420cfa93c98c8f590f1154a620c8f4a1b5b45 

      But the current implementation still relies on the OpenAPI 2.0 collectionFormat value, which is not applicable to OpenAPI 3.0 specifications. This leads to incorrect generated code when using newer serialization styles.

      For example, the following OpenAPI 3.1 parameter:

      parameters: 
              - in: query
                name: my_param
                required: false
                style: deepObject
                explode: true # default value is false
                schema:
                  type: array
                  items:
                    type: string  

       The default value of collectionFormat is "csv" when not explicitly set in OpenAPI 3.1. As a result the following condition evaluates to true:

      } else if (QString("{{collectionFormat}}").indexOf("csv") == 0) {

      and this one to false

      } else if (QString("{{collectionFormat}}").indexOf("deepObject") == 0) {
      

      This causes the csv block to be executed instead of deepObject block, which leads to incorrect query parameter formatting.

      To do: Adjust query parameter generation in api-body.mustache file based on the style and explode values instead of collectionFormat.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            rybouabi Rym Bouabid
            rybouabi Rym Bouabid
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes