Skip to content

Fix anyOf transformation #895

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
merged 1 commit into from
Jun 2, 2022
Merged

Fix anyOf transformation #895

merged 1 commit into from
Jun 2, 2022

Conversation

MunifTanjim
Copy link
Contributor

Fixes #894

@mull
Copy link

mull commented Apr 19, 2022

Anything I can do to help move this along?

@MunifTanjim
Copy link
Contributor Author

Anything I can do to help move this along?

Additional tests are added and previous tests were updated. So I guess we just need approval from one of the maintainers. 🤞🏼

@codecov
Copy link

codecov bot commented Apr 24, 2022

Codecov Report

Merging #895 (1405383) into main (c0eef5f) will not change coverage.
The diff coverage is n/a.

❗ Current head 1405383 differs from pull request most recent head f6baac8. Consider uploading reports for the commit f6baac8 to get more accurate results

@@            Coverage Diff            @@
##              main      #895   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines            1         1           
=========================================
  Hits             1         1           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 08d42a6...f6baac8. Read the comment docs.

@drwpow
Copy link
Contributor

drwpow commented Apr 24, 2022

Hm after revisiting the spec, I’m not so sure this is an improvement on the existing behavior. Copying a comment I made here:

Hm, from the OpenAPI specification:

OpenAPI 3.0 provides several keywords which you can use to combine schemas. You can use these keywords to create a complex schema, or validate a value against multiple criteria.

  • oneOf – validates the value against exactly one of the subschemas
  • allOf – validates the value against all the subschemas
  • anyOf – validates the value against any (one or more) of the subschemas

I don’t believe anyOf is OR, as it may be either one of the subschemas, or all of the subschemas. To get OR you would want oneOf, no?

I think the current behavior is correct (Partial<A> & Partial<B> & Partial<C>) unless I’m missing something.

@drwpow drwpow added the question Further information is requested label Apr 24, 2022
@MunifTanjim
Copy link
Contributor Author

Replied in #894 (comment) @drwpow

@drwpow
Copy link
Contributor

drwpow commented May 20, 2022

So as discussed in #894, I’m in favor of this change and I’ve been convinced this is proper behavior. Even though this is a fix, this may disrupt enough people I’m going to release this in a breaking change.

There are some other minor bugfixes I’ll merge first, then I’ll ship a prerelease candidate for the next major version with this for testing. If that looks good, we’ll cut a new major for this 😎

@MunifTanjim
Copy link
Contributor Author

Rebased on latest main.

@drwpow drwpow merged commit f9229a2 into openapi-ts:main Jun 2, 2022
@drwpow
Copy link
Contributor

drwpow commented Jun 2, 2022

Just released a new version at openapi-typescript@next that has this behavior. If anyone has time to test this out in their existing schemas and see if it works as intended it’d be much appreciated 🙏. I’ll do the same in mine.

If the behavior works as expected, I’ll cut a stable release of this.

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

Successfully merging this pull request may close these issues.

anyOf should not result in intersection type
3 participants