-
-
Notifications
You must be signed in to change notification settings - Fork 481
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
Inconsistent behavior for optional properties with defaults #1957
Comments
Jus found this - #1903 seems to be the same issue |
Not sure if my issue is identical to this one. I have a {
"paths": {
"/schools": {
"post": {
"responses": {
"200": {
"description": "List of school objects",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"school_id": {
"type": "string",
"format": "uuid",
"description": "The school identifier",
"example": "acb46979-1072-41fc-920c-5577816a88bc"
},
"school_name": {
"type": "string",
"description": "The school name",
"example": "Super School"
},
// closing braces But the generated export interface operations {
// upper content redacted
responses: {
/** @description List of school objects */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": {
data?: {
/**
* Format: uuid
* @description The school identifier
* @example acb46979-1072-41fc-920c-5577816a88bc
*/
school_id?: string;
/**
* @description The school name
* @example Super school
*/
school_name?: string;
// lower content redacted
} Though I'm not using |
I don't think it's related - I can't tell from your redacted openapi schema but it looks like the fields are not specified as required eg |
Thanks for your reply, and you're right I am missing |
I am seeing this as well still with version 7.4.3. Here is the spec im using (google admin API): https://pastebin.com/4d48Kyap Command which hangs:
Whereas this finishes basically instantly:
|
Description
I've discovered inconsistent behavior when generating types for optional fields which also provide a default value. See sandbox for more info
Given a simple
Item
schema:Depending on where it is defined in the openapi spec file we get different results:
If we define
Item
in the endpoint directly without using a ref we get:If we define
Item
incomponents
and use a ref in the endpoint spec the result becomes:The latter behavior is unexpected and incorrect as the field should not be required
openapi-typescript
7.4.1
20.12.1
Reproduction
https://codesandbox.io/p/devbox/openapi-typescript-optional-default-5zjvsz
see
spec.json
input file andoutput.d.ts
resultChecklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: