-
-
Notifications
You must be signed in to change notification settings - Fork 613
Closed
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Description
openapi-typescript version
7.10.1
Node.js version
22.20
OS + version
macOS
Description
I'm seeing an issue in the openapi-typescript library that I'm not sure how to get around. Previously this worked fine (without components) but after moving to components I'm seeing a lot of wrongly generated types.
Reproduction
Here's an example:
{
"components": {
"schemas": {
"PipesRequestConfig": {
"type": "object",
"properties": {
"environment": {
"type": "string",
"enum": [
"production",
"sandbox"
],
"default": "production"
},
"widgets": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean",
"default": false
}
},
"default": {
"enabled": false
}
},
"field_definitions": {
"type": "object",
"properties": {
"enabled": {
"type": "boolean"
}
},
"default": {
"enabled": false
},
"required": [
"enabled"
]
},
"transform": {
"type": "object",
"properties": {
"include_fields": {
"type": "string",
"enum": [
"input",
"annotated"
]
}
},
"default": {
"include_fields": "input"
},
"required": [
"include_fields"
]
}
},
"default": {
"environment": "production",
"transform": {
"include_fields": "input"
},
"widgets": {
"enabled": false
},
"field_definitions": {
"enabled": false
}
}
}
}
}
}But it is turned into the following type:
PipesRequestConfig: {
/**
* @default production
* @enum {string}
*/
environment: "production" | "sandbox";
/** @default {
* "enabled": false
* } */
widgets: {
/** @default false */
enabled: boolean;
};
/** @default {
* "enabled": false
* } */
field_definitions: {
enabled: boolean;
};
/** @default {
* "include_fields": "input"
* } */
transform: {
/** @enum {string} */
include_fields: "input" | "annotated";
};
};Example: The widgets key is not listed as a required property. But the resulting type has it as required.I've tried explicitly setting the --properties-required-by-default=false but it did not help.
Expected result
Fields like widgets are optional.
Required
- My OpenAPI schema is valid and passes the Redocly validator (
npx @redocly/cli@latest lint)
Extra
- I’m willing to open a PR (see CONTRIBUTING.md)
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library