-
-
Notifications
You must be signed in to change notification settings - Fork 604
Closed
Labels
bugSomething isn't workingSomething isn't workingopenapi-tsRelevant to the openapi-typescript libraryRelevant to the openapi-typescript library
Description
Description
We have generated TS interfaces using our OpenAPI 3.1.0 specification. There are some parameters that have default values (so they are not required in request, and the body without them will be still valid):
However, these parameters are treated as required when generating paths:
| Name | Version |
|---|---|
openapi-typescript |
7.0.1 |
| Node.js | 20.13.1 |
| OS + version | macOS Sonoma 14.4 |
Reproduction
Try to use this openapi schema:
"src__schemas__social_profiles__Create": {
"properties": {
"card_title": {
"type": "string",
"maxLength": 64,
"minLength": 1,
"title": "Card Title",
"default": "Social Profile"
},
"template": {
"type": "string",
"maxLength": 64,
"minLength": 1,
"title": "Template"
},
"photo": {
"anyOf": [
{
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"const": ""
}
],
"title": "Photo",
"default": ""
},
"signature": {
"anyOf": [
{
"type": "string",
"maxLength": 2083,
"minLength": 1,
"format": "uri"
},
{
"const": ""
}
],
"title": "Signature",
"default": ""
},
"design": {
"type": "object",
"title": "Design",
"default": {
}
},
"details": {
"type": "object",
"title": "Details",
"default": {
}
},
"socials": {
"type": "object",
"title": "Socials",
"default": {
}
},
"meta": {
"type": "object",
"title": "Meta",
"default": {
}
}
},
"type": "object",
"required": [
"template"
],
"title": "Create",
"description": "Social Profile schema for create."
}You can see that default values are set, but the fields are not recognized as not required.
Expected result
Parameters that have default values have | undefined in type declaration, like
type SocialProfileCreate = {
card_title: string;
template: string;
photo?: string | "";
signature?: string | "";
design?: Record<string, never>;
details?: Record<string, never>;
socials?: Record<string, never>;
meta?: Record<string, never>;
}Checklist
- My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint) - 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