Skip to content

fix incorrect types generated when refs reference types with discriminators #1289

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

Merged

Conversation

adamschoenemann
Copy link
Contributor

@adamschoenemann adamschoenemann commented Aug 9, 2023

Changes

This PR fixes the code, so that incorrect types are not generated when referencing a type (with a discriminator with an implicit mapping) inside a oneOf/anyOf

How to Review

I added tests to both index.test.ts and schema-object.test.ts, and I tried to fix the code, but I must admit it was kind of a shot in the dark, but it does seem to work :)

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript) (I ran this but nothing changed)

@changeset-bot
Copy link

changeset-bot bot commented Aug 9, 2023

🦋 Changeset detected

Latest commit: 76f092f

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

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

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

@adamschoenemann adamschoenemann force-pushed the fix-ref-types-with-discriminators branch from 90c98a4 to 2720165 Compare August 9, 2023 10:06
@adamschoenemann
Copy link
Contributor Author

It also looks related to #1116

@adamschoenemann
Copy link
Contributor Author

Test macos failed, because the digital ocean test timed out. I'm pretty sure it's got nothing to do with this change... I observed this test being quite slow locally as well, on the main branch

@drwpow
Copy link
Contributor

drwpow commented Aug 9, 2023

Looks great to me! But just replace that deleted test to ensure this is working correctly.

Also yeah I should probably just disable DigitalOcean in the macOS test. It’s gotten worse as DigitalOcean’s API has gotten even bigger from when the test was originally added. It’s not a macOS issue; it’s an issue with the limited resources on the slow macOS runner in GitHub Actions. I think it’d be safe to assume if other tests pass in macOS, it’s safe. Ignore in your PR though; I’ll merge it even if that macOS test times out.

@adamschoenemann adamschoenemann force-pushed the fix-ref-types-with-discriminators branch from 7b2caa4 to 76f092f Compare August 9, 2023 21:15
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.

Awesome work! 👏 Thank you

@drwpow drwpow merged commit 7f452fa into openapi-ts:main Aug 10, 2023
@github-actions github-actions bot mentioned this pull request Aug 10, 2023
@drwpow
Copy link
Contributor

drwpow commented Sep 13, 2023

Just a heads up: In reviewing issues I realized #1158 does outline a bug that results in slightly-altered typegen in one of the tests added:

- components["schemas"]["parent"] | null
+ {
+   operation: "schema-object";
+ } & (components["schemas"]["parent"] | null)

This seems weird, but I believe the discriminator spec does suggest that if propertyName is present, it should generate that property even with no mapping.

It’s weird, but seems to be how it’s outlined 🤷. Anyways that shouldn’t cause a regression in this fix at all; just wanted to flag an incoming change.

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.

2 participants