Skip to content
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

JSON query parameter accepting array of objects is stringified twice #9521

Closed
timdream opened this issue Jan 26, 2024 · 2 comments
Closed

JSON query parameter accepting array of objects is stringified twice #9521

timdream opened this issue Jan 26, 2024 · 2 comments

Comments

@timdream
Copy link

timdream commented Jan 26, 2024

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

{
    "openapi": "3.1.0",
    "info": {
        "title": "Server",
        "version": "0.0.1"
    },
    "paths": {
        "/endpoint": {
            "get": {
                "responses": {
                },
                "parameters": [
                    {
                        "name": "param",
                        "in": "query",
                        "description": "a param that accepts an array of objects",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "array",
                                    "maxItems": 10,
                                    "items": {
                                        "type": "object",
                                        "properties": {
                                            "a": {
                                                "type": "string"
                                            },
                                            "b": {
                                                "type": "number"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                ]
            }
        }
    }
}

Describe the bug you're encountering

The above query parameter produces an encoded URI string that was JSON-stringified twice.

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor-next.swagger.io
  2. Copy and paste the OpenAPI spec
  3. Expand the endpoint definition on the UI and click [Try it out]
  4. Click [Add object item]
  5. Click [Execute]
  6. Inspect the generated URL

Expected behavior

Expected the following URL, encodes [{\n "a": "string",\n "b": 0\n}]

https://raw.githubusercontent.com/endpoint?param=
%5B%7B%0A%20%20%22a%22%3A%20%22string%22%2C%0A%20%20%22b%22%3A%200%0A%7D%5D

Actual behavior

Object is JSON-stringified twice. The generated URL encodes ["{\\n \\"a\\": \\"string\\",\\n \\"b\\": 0\\n}"], i.e., a JSON string in a JSON array.

https://raw.githubusercontent.com/endpoint?param=
%5B%22%7B%5Cn%20%20%5C%22a%5C%22%3A%20%5C%22string%5C%22%2C%5Cn%20%20%5C%22b%5C%22%3A%200%5Cn%7D%22%5D

Screenshots

image image
@char0n
Copy link
Member

char0n commented Apr 11, 2024

Addressed in #9805, with a swagger-client upstream change swagger-api/swagger-js#3466

@glowcloud
Copy link
Contributor

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

No branches or pull requests

3 participants