swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
25.96k stars 8.85k forks source link

String example for RequestBody is wrongly reported with double quotes in the UI #10035

Open marco-brandizi opened 1 week ago

marco-brandizi commented 1 week ago

Q&A (please complete the following information)

Content & configuration

Example Swagger/OpenAPI definition:

...
    "/v1/search-stats": {
      "post": {
        "summary": "Various stats about keyword-search",
        "description": "\tEstimates how many items (matched documents, non matched docs) a search string\n\twould return from the /search API.\n",
        "operationId": "keywordSearchStats",
        "requestBody": {
          "description": "The same as keywords in /search",
          "content": {
            "application/json": {
              "schema": {
                "type": "string",
                "example": "'seed germination' OR flower*"
              }
            }
          }
        },
...        

Describe the bug you're encountering

When using the definitions above (coming from Swagger annotations), the Swagger UI includes double quotes in the displayed example, when you try the API with a literal value of: "'seed germination' OR flower*", the result is null, since the implementation expects to receive a string without double quotes: 'seed germination' OR flower*.

To reproduce...

Use @io.swagger.v3.oas.annotations.parameters.RequestBody in a Spring REST controller's method that accept a simple String as request body, then check the results in the Spring-generated Swagger UI.

Expected behavior

Double quotes should only be included when the example specify them, not automatically, as it seems to be the case.

Additional context or thoughts

Looks similar to #4643