Redocly / Redocly/redoc

Suggestion: "Optional" instead of "Required" on output.

Open
#230 5 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Enhancement
Dominant language
TypeScript
Stars
25.9k
Forks
2.4k
Avg merge
13h 10m
Merged PRs (30d)
4

Description

OpenAPI has a list of "required" fields for each object and it makes sense to mark them as "Required" when describing input. However on output most fields are usually "Required". Perhaps it's wiser to mark those that aren't as "Optional" instead? In a way it would make it similar to "Nullable" tags. And once again, I'm talking about descriptions of output of APIs, inputs are fine with "Requried".

Let me give you an example. Let's say I have some API which returns an address, for that I would describe it as:

address1 (required)
address2
city (required)
company
first_name (required)
last_name (required)
phone (required)
country (required)
province (required)
zip (required)

And for the sake of example let's not discuss whether it's wise to omit fields on output or return empty strings instead. Let's say I decided to omit some of the fields in my API. Wouldn't it be nicer to display the same structure as:

address1
address2 (optional)
city
company (optional)
first_name
last_name
phone
country
province
zip

Maybe even make it smart and if most fields are "required", use "Optional" tag for those which aren't. If most fields are not "required", then use "Required" tag as usual. That simple logic will reduce visual clutter and lower cognitive load when reading docs. Or maybe add it as an option?

That's a feature request.

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

Start by tracing how OpenAPI output schemas are rendered and where Required and Nullable labels are selected. Compare the proposed Optional heuristic with the current input and output documentation behavior, then define tests for both majority-required and majority-optional schemas before implementing or documenting the option.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
Domain
api, documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.