Skip to content

Conversation

@desjoerd
Copy link
Contributor

Add type: "null" downcasting when in oneOf and anyOf for OpenAPI v3

Description

This PR adds downcasting of oneOf and anyOf for openapi v3.

When writing OpenAPI v3 it will remove schemas from oneOf and anyOf with { "type": "null" } and apply it to the parent as nullable: true. It also tries to find a common overlapping type which will also be applied to the parent schema as nullable: true is only doing something when type is specified.

It's between a bug-fix and a feature as the current situation downcasts { "type": "null" } to { "nullable": true } which according to some clarifications of the spec doesn't do anything and tools expect the nullable: true on the parent schema.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Related Issue(s)

Changes Made

  • Add detection and processing of compositions where there could be a type: null for OpenAPI v3.
  • Apply either the type of the schema or the inferred type on the schema, a possible explicit type is not overwritten.
  • When multiple possible types are detected it will omit the inferred type.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 1.X of the library, if so PR link:
  • My change applies to the version 2.X of the library, if so PR link:
  • My change applies to the version 3.X of the library, if so PR link:
  • I have evaluated the applicability of my change against the other versions above.

@desjoerd desjoerd requested a review from a team as a code owner December 12, 2025 21:45
@desjoerd
Copy link
Contributor Author

@microsoft-github-policy-service agree

@desjoerd
Copy link
Contributor Author

desjoerd commented Dec 12, 2025

@baywet I've drafted this PR. Let me know what you think. Some parts are a little bit rough imho, for example the update to SerializeNullable, and SerializeTypeProperty.

Edit: I just went ahead and implemented it. I know that I take a risk that this won't be merged or requires significant changes, then I will just see it as an exercise 🙃

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

desjoerd and others added 3 commits December 15, 2025 20:40
Co-authored-by: Vincent Biret <vincentbiret@hotmail.com>
…and use JsonNode.DeepEquals in tests

Co-authored-by: desjoerd <2460430+desjoerd@users.noreply.github.com>
Copilot AI and others added 3 commits December 15, 2025 22:58
Co-authored-by: desjoerd <2460430+desjoerd@users.noreply.github.com>
Co-authored-by: desjoerd <2460430+desjoerd@users.noreply.github.com>
Address PR microsoft#2645 review comments: improve type checking logic and use JsonNode.DeepEquals
@desjoerd
Copy link
Contributor Author

@baywet I've addressed your comments (with copilot so I could go to the movie Zootopia 2 in the meantime 😎, AI let's programming really happen from your phone 😜).

Let me know if I need to change something.

@desjoerd
Copy link
Contributor Author

@baywet I've removed that whole code block around HasMultipleTypes, this part is already covered when writing the type property.

I noticed that when you gave me the link to the location where HasMultipleTypes is used.

Copy link
Member

@baywet baywet left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

@baywet baywet enabled auto-merge (squash) December 17, 2025 20:56
@baywet baywet merged commit 782cf8d into microsoft:support/v2 Dec 17, 2025
8 checks passed
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