swagger-ui icon indicating copy to clipboard operation
swagger-ui copied to clipboard

SwaggerUI does not display array of 0 integer values example nor displays 0 when adding via "Add integer item"

Open bluelight773 opened this issue 2 years ago • 0 comments

Q&A (please complete the following information)

  • OS: Ubuntu 20.04 LTS
  • Browser: Chrome
  • Version: 102.0.5005.61 (Official Build) (64-bit)
  • Method of installation: Unsure, part of Python/Django/DRF/drf-spectacular?
  • Swagger-UI version: 4.12.0?
  • Swagger/OpenAPI version: OpenAPI 3.0.3

Content & configuration

You can simply use Swagger Editor (https://editor.swagger.io/), use the following YAML, and look at the result for the example values.

Example Swagger/OpenAPI definition:

openapi: 3.0.3
info:
  title: Test API
  version: 1.0.0
paths:
  /test_endpoint/:
    get:
      parameters:
      - in: query
        name: int_array_parameter
        schema:
          type: array
          items:
            type: integer
        examples:
          ThreeZerosExample:
            value:
              - 0
              - 0
              - 0
      responses:
        '200':
            description: Success response

Swagger-UI configuration options: Not sure, but you can simply use https://editor.swagger.io/ to reproduce the error.

Describe the bug you're encountering

The three text fields show as empty rather than containing 0. A workaround is to provide the values as "0" rather than 0.

However, there is a related issue for which I don't see a good workaround: If you use the UI to add elements by clicking on "Add integer item", all new items appear as blank text fields, but in reality, the value 0 is used for them.

To reproduce...

Steps to reproduce the behavior:

  1. Enter the provided YAML into https://editor.swagger.io/
  2. Click on /test_endpoint/ to expand it
  3. Notice that the three text fields are empty.
  4. You can go further and click on "Add integer item" and notice that the items appear as blank text fields. Click "Execute" to see what the blank field values are assumed to be (0).

Expected behavior

  1. The three text fields should contain the value 0. A workaround is to use "0" in the yaml rather than 0. Doing so ensures the text fields appear with the value 0 inside.
  2. The items added via "Add integer item" should appear as 0 just like they appear to be based on the executed query when you click "Execute".

bluelight773 avatar Jun 09 '22 12:06 bluelight773