-
-
Notifications
You must be signed in to change notification settings - Fork 604
Open
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Description
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.
| Name | Version |
|---|---|
openapi-typescript |
7.4.0 |
| Node.js | 20.16.0 |
| OS + version | macOS 14.5 |
Reproduction
Gives the following typing on the /failing endpoint:
{
/** @default false */
bool_with_default: boolean;
bool_with_no_default?: boolean;
/** @default ok */
string_with_default: string;
string_with_no_default?: string;
};
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.
{
/** @default false */
bool_with_default?: boolean;
bool_with_no_default?: boolean;
/** @default ok */
string_with_default?: string;
string_with_no_default?: string;
}
Checklist
- My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint) - I’m willing to open a PR (see CONTRIBUTING.md)
Gero-B and MikaelSiidorow
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Type
Projects
Status
No status