Closed ysemennikov closed 5 days ago
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.js20.13.1
OS + versionmacOS Sonoma 14.4
ReproductionTry 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, liketype 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
- [x] My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint
)- [ ] I’m willing to open a PR (see CONTRIBUTING.md)
Hi, @ysemennikov ! The results I generated using your scheme test were correct.
@phk422 We're seeing this issue as well. Could the difference be that the requestBody is using a referenced component schema rather than an inline schema?
@phk422 We're seeing this issue as well. Could the difference be that the requestBody is using a referenced component schema rather than an inline schema?
Hi @phk422, the requestBody in our OpenAPI schema was also referenced, not inline. Maybe this really makes sense?
@phk422 We're seeing this issue as well. Could the difference be that the requestBody is using a referenced component schema rather than an inline schema?
Hi @phk422, the requestBody in our OpenAPI schema was also referenced, not inline. Maybe this really makes sense?
Ah, yes, I overlooked it. I already submitted a pr to fix it!
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:
openapi-typescript
7.0.1
20.13.1
macOS Sonoma 14.4
Reproduction
Try to use this openapi schema:
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, likeChecklist
npx @redocly/cli@latest lint
)