Skip to content

Swagger-UI can't render content inside a parameter #4442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hazardfn opened this issue Apr 14, 2018 · 16 comments · Fixed by #5571
Closed

Swagger-UI can't render content inside a parameter #4442

hazardfn opened this issue Apr 14, 2018 · 16 comments · Fixed by #5571

Comments

@hazardfn
Copy link

hazardfn commented Apr 14, 2018

Q A
Bug or feature request? Bug
Which Swagger/OpenAPI version? 3.0.0
Which Swagger-UI version? v3.13.4
How did you install Swagger-UI? standalone-dist
Which browser & version? Firefox 61.0a1
Which operating system? Mac Sierra

Demonstration API definition

Try and add a query parameter referencing an object (which according to the spec is a valid thing to do)

        - name: users
          in: query
          description: List of users to query for
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserArray"

components:
  schemas:

    UserArray:
      type: array
      items:
        $ref: "#/components/schemas/User"

    User:
      required:
        - userId
        - currency
      properties:
        userId:
          type: integer
          format: int32
        currency:
          type: string

Configuration (browser query string, constructor, config.yaml)

I am using no additional config options, everything is vanilla.

Expected Behavior

The UI should offer me a nice way of typing in arrays of objects in a query param. According to the documentation this should be possible:

in: query
name: coordinates
content:
  application/json:
    schema:
      type: object
      required:
        - lat
        - long
      properties:
        lat:
          type: number
        long:
          type: number

Current Behavior

Screen_Shot_2018_04_14_at_19_25_39

Context

Just an honest labourer trying to document a horrendous API I didn't write 🤣

@hkosova
Copy link
Contributor

hkosova commented Apr 16, 2018

Possible duplicate of #3558.


By the way, you example defines the users parameter as a JSON string containing an array of objects, something like (before URL encoding):

/foo?users=[{"userId":0,"currency":"usd"},{"userId":1,"currency":"eur"}]

Is this actually the case?.. 🙀

Or are you trying to describe something like

/foo?users[0].userId=0&users[0].currency=usd&users[1].userId=1&users[1].currency=eur

?

@hazardfn
Copy link
Author

@hkosova That is the case unfortunately, horrific I know...

Perhaps this kind of thing should never be possible then it would encourage people to write nice API's ☮️

@webron
Copy link
Contributor

webron commented Apr 17, 2018

@hazardfn oh, trust me, we don't encourage it. the added support for it in the spec, was due to existing APIs rather than advocating it for new APIs.

@aleskovets
Copy link

@hkosova, is here a way to describe your example with openapi3? Looks like deepObject-way would not support indexes
/foo?users[0].userId=0&users[0].currency=usd&users[1].userId=1&users[1].currency=eur

@hkosova
Copy link
Contributor

hkosova commented Dec 3, 2018

@aleskovets deepObject behavior is not defined for arrays, so there's currently no way describe the query string you mentioned. This limitation is discussed in the OpenAPI Specification repository:

Are indexes in the query parameter array representable?
OAI/OpenAPI-Specification#1006 (comment)

@ksac1
Copy link

ksac1 commented Mar 25, 2019

The solution to the problem : "😱 Could not render this component, see the console." in Swagger Open API 3 can be resolved by following the link: https://swagger.io/docs/specification/describing-parameters/

@vinhlh
Copy link

vinhlh commented Mar 28, 2019

@ksac1 how? when swagger-ui doesn't support ?

@ksac1
Copy link

ksac1 commented Mar 28, 2019

@vinhlh : Yes, just follow the way of writing the path parameters and query parameters on the link: https://swagger.io/docs/specification/describing-parameters/

It really worked for me.

@hkosova
Copy link
Contributor

hkosova commented Mar 28, 2019

@ksac1 there are two ways to define the parameter data - using schema and using content. Parameters with schema are displayed properly in Swagger UI. This issue is specifically about parameters with content.

@ksac1
Copy link

ksac1 commented Mar 28, 2019

@hkosova :
Untitled

@shockey
Copy link
Contributor

shockey commented Apr 23, 2019

@ksac1, @hkosova probably wrote that documentation 😉


To clarify for those reading along: Swagger UI is indeed missing support for content data within parameters. We're tracking this as a feature request!

@shockey shockey changed the title Swagger-UI can't render content inside a query parameter Swagger-UI can't render content inside a parameter May 16, 2019
@vinhlh
Copy link

vinhlh commented May 21, 2019

@shockey do you guys have any plan to support this?
Or is there any chance that we can help/ contribute.

@jessebrennan
Copy link

Probably not the right place for this, but this issue is reference in the Swagger documentation and it seems like the documentation may no longer be accurate.

@hkosova
Copy link
Contributor

hkosova commented Nov 25, 2019

@jessebrennan Thanks, the documentation has been updated to reflect that parameters with content are supported in Swagger UI 3.23.7+ and Swagger Editor 3.6.34+.

@akrz
Copy link

akrz commented Mar 10, 2020

@hkosova This only supports simple json objects, right? Tried to use content with type array of objects but its not working.

Example case use: ?sort=[{"property":"date", "direction":"ASC"}]

Tried with:

"parameters": {
  "in": "query",
  "name": "sort",
  "content": {
    "application/json": {
      "schema": {
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "property": {
              "type": "string"
            },
            "direction": {
              "type": "string"
            }
          }
        }
      }
    }
  }
}

@hkosova
Copy link
Contributor

hkosova commented Mar 10, 2020

@akrz if something does not work please open a new issue and fill in the details in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants