swagger-api / swagger-api/swagger-ui

Show "undefined" explicitly in addition to not showing a red asterisk

Open
#7,945 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Is your feature request related to a problem?

If you define a component where every field is optional, the UI shows all fields without a red asterisk. This is expected and fine. However, when sharing this schema with other teams who are unfamiliar with this specific format, they may interpret the lack of a red asterisk to mean all fields are required. For example, look at the two screenshots below:

Screen Shot 2022-03-25 at 11 53 48 AM Screen Shot 2022-03-25 at 11 53 52 AM

In the first, you would think every property is required since we see string for all of them.

In the second, you realize they are actually all optional except for id since it has a red asterisk.

Describe the solution you'd like

The solution is to show string | undefined for properties that are not required. This would clear up the issue and make it more clear that something is not required. We could also show a ? next to the field name instead of undefined.

Thanks so much!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files or tests, so first locate the Swagger UI component that renders schema properties and their required-field indicators. Verify how optional properties are displayed, then make the rendered type explicitly indicate undefined or use a question mark, and confirm the result in the schema view.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.