Skip to content

Fix defaultNonNullable behavior #1445

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
Nov 19, 2023
Merged

Fix defaultNonNullable behavior #1445

merged 1 commit into from
Nov 19, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Nov 18, 2023

Changes

defaultNonNullable: true can’t make parameters required even if a default value is given (comment).

How to Review

  • Tests should pass.

Checklist

  • Unit tests updated
  • docs/ updated (if necessary)
  • pnpm run update:examples run (only applicable for openapi-typescript)

Copy link

changeset-bot bot commented Nov 18, 2023

⚠️ No Changeset found

Latest commit: 01eb231

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

Copy link

cloudflare-workers-and-pages bot commented Nov 18, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 01eb231
Status: ✅  Deploy successful!
Preview URL: https://5d4fc629.openapi-ts.pages.dev
Branch Preview URL: https://fix-default-non-nullable.openapi-ts.pages.dev

View logs

@drwpow drwpow force-pushed the fix/default-non-nullable branch from 7c4305c to 506eb49 Compare November 18, 2023 22:34
},
],
[
"defaultNonNullable > parameters aren’t required even with defaults",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This new test asserts that a parameter with a default is ignored, but a response object with a default is not

@drwpow drwpow force-pushed the fix/default-non-nullable branch from 506eb49 to 01eb231 Compare November 19, 2023 00:10
("default" in v && options.ctx.defaultNonNullable)
("default" in v &&
options.ctx.defaultNonNullable &&
!options.path?.includes("parameters")) // parameters can’t be required, even with defaults
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems like the dumbest solution to the problem, but I actually think it’s the correct one—parameters go through normal SchemaObject transformation, however, in this one scenario we apply different rules because of where they live (in any parameters object). I can’t think of a single scenario where this wouldn’t be true.

I also feel like the alternative—trying to override ctx.defaultNonNullable conditionally based on the parent—is a worse approach that could lead to other unintentional bugs.

@drwpow drwpow merged commit 91c8ad4 into main Nov 19, 2023
@drwpow drwpow deleted the fix/default-non-nullable branch November 19, 2023 00:14
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