Skip to content

Conversation

@desjoerd
Copy link

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
Author

@microsoft-github-policy-service agree

@desjoerd
Copy link
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 🙃

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.

1 participant