Skip to content

Swagger UI: “Send empty value” Checkbox Not Selected by Default for null Default Values in Request Body #10352

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

Open
ragaman555 opened this issue Mar 10, 2025 · 0 comments

Comments

@ragaman555
Copy link

Q&A

  • OS: macOS
  • Browser: chrome, safari
  • Swagger-UI version: v5.20.1

Example Swagger/OpenAPI definition:

openapi: 3.1.0
info:
  title: test
  version: 0.0.1
paths:
  /test:
    post:
      summary: Test
      operationId: test
      requestBody:
        content:
          application/x-www-form-urlencoded:
            schema:
              $ref: '#/components/schemas/Body_test'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
      
components:
  schemas:
    Body_test:
      properties:
        name:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Name
        digit:
          anyOf:
            - type: integer
            - type: 'null'
          default: null
          title: Name
      type: object
      title: Body_test

Swagger-UI configuration options:
noting, just use https://editor-next.swagger.io for reproduce.

Describe the bug you're encountering

In Swagger UI, when using AnyOf variables that can be null and have a default value of null, the input fields are incorrectly populated with the string "null" after clicking “Try it out.” Additionally, the “Send empty value” checkbox remains unchecked.

If the request is sent via “Execute” without modifying the fields, Swagger UI submits the string values "null", even though the schema defines them as Integer | null:

curl -X 'POST' \
  'https://editor-next.swagger.io/test' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'name=null&digit=null'

To reproduce...

Steps to reproduce the behavior:

  1. Go to 'https://editor-next.swagger.io'
  2. Copy Example OpenAPI definition above
  3. click "Try out"
  4. Scroll down to name, digit

Expected behavior

When the default value is explicitly set to null:
• The “Send empty value” checkbox should be checked by default.
• The input fields should be empty, displaying only the placeholder text.

Currently, Swagger UI misinterprets null as a literal string, leading to incorrect behavior. This should not be the intended default behavior and appears to be a bug.

Immediately click on Execute should perform:

curl -X 'POST' \
  'https://editor-next.swagger.io/test' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'name=&digit='

Screenshots

actual behavior in the UI after click on try out:

Image

expected behavior in the UI after click on try out:

Image

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

No branches or pull requests

1 participant