Skip to content

Support v3.1 typed arrays #1167

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Thomasdezeeuw
Copy link

In OpenAPI v3.1 the nullable property was replaced with a "typed array", that is an array that can either be of type T or null.

To make the minimal amount of changes this commit converts a type array back into what a 3.0 parser would expect.

Closes #991

In OpenAPI v3.1 the nullable property was replaced with a "typed array",
that is an array that can either be of type T or null.

To make the minimal amount of changes this commit converts a type array
back into what a 3.0 parser would expect.

Closes acacode#991
Copy link

changeset-bot bot commented Apr 10, 2025

⚠️ No Changeset found

Latest commit: f1988f6

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@smorimoto smorimoto added the enhancement New feature or request label Apr 11, 2025
@Thomasdezeeuw
Copy link
Author

@smorimoto any chance you could review this? We could really use this change.

@smorimoto smorimoto requested a review from Copilot April 24, 2025 00:10
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces support for OpenAPI v3.1 typed arrays by converting them back to the v3.0 format to minimize changes.

  • Adjusts the schema parser to detect a two-element type array containing "null".
  • Sets the type and nullable properties accordingly.

Comment on lines +42 to +45
if (property.type[0] == "null") {
property.type = property.type[1];
property.nullable = true;
} else if (property.type[1] == "null") {
Copy link
Preview

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

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

Consider using strict equality (===) instead of loose equality (==) for comparing property.type elements to "null" to avoid potential type coercion issues.

Suggested change
if (property.type[0] == "null") {
property.type = property.type[1];
property.nullable = true;
} else if (property.type[1] == "null") {
if (property.type[0] === "null") {
property.type = property.type[1];
property.nullable = true;
} else if (property.type[1] === "null") {

Copilot uses AI. Check for mistakes.

property.type = property.type[0];
property.nullable = true;
}
}

Choose a reason for hiding this comment

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

I had to add also this after your condition, to type array with single type work.

if (Array.isArray(property.type) && property.type.length == 1) { property.type = property.type[0]; }

Example yaml:

SomeType:
type:
- string
enum:
- one
- two

OtherComponent:
type: object
properties:
type:
$ref: '#/components/schemas/SomeType'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nullable array with $ref is generated as any[] | null
3 participants