swagger-api / swagger-api/swagger-ui
Optional fields without example and default value should not appear in the example
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
... or at least this should be an option.
Content & configuration
The PetStore has dozens of examples, e.g.:
Category:
type: "object"
properties:
id:
type: "integer"
format: "int64"
name:
type: "string"
From this the example in the UI is the following:
"category": {
"id": 0,
"name": "string"
}
Describe the solution you'd like
I would like to have an option not to display an optional field in the example, if it doesn't have an example and/or a default value, so the above example (since both the "id" and the "name" fields are not required and have no default/example value) should become an empty object:
"category": {
}
Describe alternatives you've considered
As a workaround we can use example='', default='' for a string, even though a missing parameter is not the same as a parameter with an empty string, and check for empty string on the server side.
Additional context
Context: we have an integration test that tests that the schema committed can be "tried out" without any modification. Having "string" values for optional fields that have no default values on purpose makes this impossible.
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
Start by reproducing the PetStore schema example in Swagger UI, focusing on optional properties without example or default values. Done means an option can omit those properties from generated examples, while preserving the documented behavior for required properties and explicitly provided examples or defaults.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100