Skip to content
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

“nullable” reference objects are not correctly generated. #186

Closed
mbsanchez opened this issue Nov 7, 2023 · 3 comments · Fixed by #187
Closed

“nullable” reference objects are not correctly generated. #186

mbsanchez opened this issue Nov 7, 2023 · 3 comments · Fixed by #187

Comments

@mbsanchez
Copy link

mbsanchez commented Nov 7, 2023

The issue is that when I have a type like this:

const personSchema = z.object({
   firstname: z.string(),
   lastname: z.string()
});

const houseSchema = object({
   address: z.string(),
   owner: personSchema.nullable().optional()
});

When the open API spec is generated the owner field is generated like:

"owner": {
  "oneOf": [
    {
      "$ref": "#/components/schemas/Person"
    },
    {
      "nullable": true
    }
  ]
},

But it is incorrect, as when the client uses the spect to generate the typescript code, the owner field is not well recognized. The correct output should be:

"owner": {
  "oneOf": [
    {
      "$ref": "#/components/schemas/Person"
    },
  ],
  "nullable": true
},
@samchungy
Copy link
Owner

Ah nice one.

TIL: OAI/OpenAPI-Specification#1368

I'll raise a PR sometime todayish

@mbsanchez
Copy link
Author

Great, thank you so much,

FYI: in my case, this format I've shown you works perfectly using "anyOf", "oneOf" and "allOf". Check this screenshot of the swagger editor using "anyOf":

image

@samchungy
Copy link
Owner

Just gonna sleep on this one, and if I don't have any bad thoughts I'll deploy tomorrow morning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants