Default required, explicit optional fields #5563
devinrhode2
started this conversation in
Enhancements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Been on a few teams using Java Spring Boot on the backend and TypeScript and KUBB on the frontend.
I feel that, on the UI side, default optional is bad because it encourages the UI to write code to handle fields being missing when that may not be the case. It may actually simply be that a developer forgot to mark a field as required, which means we're bloating the UI dev codebase for no reason because the API devs forgot to add a required annotation.
My suggestion is to support a top-level field which indicates that all properties in this document are required by default, and then we add support for an optional annotation. I'm sure this has been discussed many times before, but we're writing email up front. In that case, it's very hard to enforce that all the fields have
requiredon them unless maybe they have a special string in the description.Another idea here is to maybe keep the default as optional, but support a supported inline property to indicate if something is optional or required. It can be hard to just look at the source code: you have to look up and down from the
requiredto the properties to see if everything's in there or not. There could be a third top-level setting to say there is no default: optional, required. Everything must be explicitly marked.It could be required mode explicit versus required mode required, or required. You could say
default requiredis a top-level key in the Open API spec, and then there are, I don't know, three values:default required: truedefault required: falsedefault required: explicitnullorundefined, or something like thatAll reactions