-
-
Notifications
You must be signed in to change notification settings - Fork 460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Schemas using $ref give different output to identical inlined spec when using defaults #1903
Comments
Gah, I just found a similar closed ticket that references this merged PR All problems go away when I use |
I've taken a look at the code, and basically the whole This feature seems to cater for people who are using defaults on their OUTPUT schemas to make fields mandatory in their output types. However, the default key is only ever used with api INPUTS to specify to the consumer what the value would be if you omit it. Please can somebody explain the point of this feature (now enabled by default)? |
Description
Defining an object using an external file $ref gives different typing outputs for schemas with keys that have defaults defined. Object keys are incorrectly marked as required/non optional if they contain a default and are defined within an externally $ref ed file. The same schema generates correctly without using a $ref.
openapi-typescript
7.4.0
20.16.0
macOS 14.5
Reproduction
spec.json
alpha.json
Gives the following typing on the /failing endpoint:
Note, the omission of the
?
optional identifier on keys that have defaults set.Expected result
All fields should be marked as optional in both of the endpoints. Giving a field a default should not make it mandatory. Using an external file with $ref should be logically identical to an inline spec.
Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: