swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.93k stars 2.25k forks source link

Swagger Editor Incorrectly Renders Examples for `deepObject` `explode:true` Parameters #4781

Open ckoegel opened 9 months ago

ckoegel commented 9 months ago

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Customers API
  version: 1.0.0
servers:
  - url: 'https://api.customers.com/'
    description: Production
paths:
  /customers:
    get:
      summary: List All Customers
      operationId: listCustomers
      description: This operation returns a list of all customers.
      tags:
        - Customers
      parameters:
        - $ref: '#/components/parameters/firstName'
      responses:
        '200':
           description: OK
components:
  schemas:
    nameQueryParameter:
      title: Name Query Parameter
      description: Base model for a name query parameter.
      properties:
        eq:
          type: string
        ne:
          type: string
        regex:
          type: string
        contains:
          type: string
        sort:
          $ref: '#/components/schemas/sort'
      example:
        ne: 'David'
        contains: 'Da'
        sort: ASC
    sort:
      type: string
      enum:
        - ASC
        - DESC
  parameters:
    firstName:
      name: firstName
      in: query
      description: Sorting and filtering parameters for `firstName`.
      style: deepObject
      explode: true
      schema:
        $ref: '#/components/schemas/nameQueryParameter'
  securitySchemes:
    Token:
      type: http
      scheme: bearer
      bearerFormat: JWT
security:
  - Token: []
tags:
  - name: Customers

Describe the bug you're encountering

According to the Official Swagger Docs, when a query parameter is defined with the style deepObject and has the explode field set to true, each property of the object is expanded into its own query parameter as such: paramName[property]=value. When using the combination of deepObject and explode: true for a parameter and viewing it in the Swagger Editor, the example for the parameter shows as an object in the form paramName={property: value} instead of the exploded form. In the example spec provided above, the firstName parameter is defined as a deepObject with explode set to true. Instead of each property being their own parameter, the example shows one single firstName object as a query parameter, and using the Try it out function sends the request using the unexploded form. This happens for both v3.0.3 and v3.1.0 of OAS.

To reproduce...

Steps to reproduce the behavior:

  1. Open the Swagger Editor at https://editor-next.swagger.io/
  2. Paste the provided spec in the editor
  3. Refer to the example or Try it out feature in the right panel for the listCustomers endpoint

Expected behavior

The editor should render the provided example as a series of exploded query parameters and the Try it out request should use the exploded form instead of object form for the provided properties.

Additional context or thoughts

This is in the alpha version of the editor, so there may be plans to support this in the future I'm unaware of

Mazgis47 commented 2 months ago

Same here, but according to the https://swagger.io/docs/specification/serialization/ explode: true for the deepObject is n/a. However it seems that e.g. github.com/go-openapi/runtime/middleware explodes deepObject by default. So probably the best is to handle that in the web app.