Skip to content

Conversation

@gduliscouet-ubitransport
Copy link
Contributor

@gduliscouet-ubitransport gduliscouet-ubitransport commented Dec 19, 2024

Changes

Allow all types except UNKNOWN to be nullable.
Fixes #1821 and #1940 .

How to Review

I re-applied #1959 (it didn't move for a while)

I added tests for the new syntax for OAS 3.1 (not the one with oneOf, but with a type array, as documented here).

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)
  • add a minor changeset patch

@changeset-bot
Copy link

changeset-bot bot commented Dec 19, 2024

🦋 Changeset detected

Latest commit: 234bceb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
openapi-typescript Minor
swr-openapi Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gduliscouet-ubitransport
Copy link
Contributor Author

Hello @drwpow ,
Could I get your input for this schema ?
I added it to the tests, but it doesn't pass yet.
From what I see in the code, it seems to me that if we have a $ref in an object schema, all other keys are ignored. Is it me that misunderstood how $ref work ? Or is it a bug we should fix ?

Once we resolve that I'll finalize the PR

@drwpow
Copy link
Contributor

drwpow commented Dec 19, 2024

it seems to me that if we have a $ref in an object schema, all other keys are ignored. Is it me that misunderstood how $ref work ? Or is it a bug we should fix ?

That’s my understanding. If you look at the OpenAPI 3.1 specification, you’ll often see typings like this: SchemaObject | ReferenceObject. The fact that a reference object IS NOT a SchemaObject, or any other type for that matter, means they aren’t to be mixed-and-matched. If you want to combine multiple objects, you MUST use allOf/oneOf/anyOf to compose an object (but within those arrays, you are allowed to have some object be ReferenceObject and some SchemaObjects, but there’s no such thing as combining the two together.

@netlify
Copy link

netlify bot commented Jan 3, 2025

Deploy Preview for openapi-ts ready!

Name Link
🔨 Latest commit 234bceb
🔍 Latest deploy log https://app.netlify.com/projects/openapi-ts/deploys/6777a14889bcbb0008661d01
😎 Deploy Preview https://deploy-preview-2059--openapi-ts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@gduliscouet-ubitransport gduliscouet-ubitransport marked this pull request as ready for review January 3, 2025 08:44
@gduliscouet-ubitransport gduliscouet-ubitransport requested a review from a team as a code owner January 3, 2025 08:44
Copy link
Contributor

@drwpow drwpow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great tests, and great fix! Replied to the comment about $ref handling, but let’s merge & release the rest of it as-is

@drwpow drwpow merged commit 9e4f61c into openapi-ts:main Jan 3, 2025
8 checks passed
@openapi-ts-bot openapi-ts-bot mentioned this pull request Jan 3, 2025
ut0xygen pushed a commit to ut0xygen/openapi-typescript that referenced this pull request Aug 5, 2025
* fix(openapi-typescript): handle nullable schemas

* chore(examples): regenerate after nullable handling fix
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 this pull request may close these issues.

[openapi-typescript] Incorrect type generated for nullable objects

2 participants