swagger-api / swagger-api/swagger-ui
Swagger UI: “Send empty value” Checkbox Not Selected by Default for null Default Values in Request Body
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
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:
- Go to 'https://editor-next.swagger.io'
- Copy Example OpenAPI definition above
- click "Try out"
- 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:
expected behavior in the UI after click on try out:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in https://editor-next.swagger.io using the OpenAPI definition in the report, then follow the Try it out request-body controls for nullable defaults. Verify that a null default leaves the input empty, selects “Send empty value,” and produces empty form values on Execute.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100