Skip to content

Improve composition #1383

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
Oct 9, 2023
Merged

Improve composition #1383

merged 1 commit into from
Oct 9, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Oct 9, 2023

Changes

Fixes allOf bug raised in #1368, and adds tests for this improvement in behavior. No changeset because this is likely a regression caused from the rewrite.

How to Review

Tests should pass

Checklist

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

@changeset-bot
Copy link

changeset-bot bot commented Oct 9, 2023

⚠️ No Changeset found

Latest commit: 3df822b

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

@drwpow drwpow force-pushed the improve-composition branch from ddef580 to 86d5889 Compare October 9, 2023 22:44
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 9, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3df822b
Status: ✅  Deploy successful!
Preview URL: https://7e0756e4.openapi-ts.pages.dev
Branch Preview URL: https://improve-composition.openapi-ts.pages.dev

View logs

@drwpow drwpow force-pushed the improve-composition branch 4 times, most recently from 5cb1664 to 95a3bcc Compare October 9, 2023 22:54
@drwpow drwpow force-pushed the improve-composition branch from 95a3bcc to 3df822b Compare October 9, 2023 23:14
"required" in schemaObject &&
Array.isArray(schemaObject.required)
) {
allOf = tsWithRequired(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change: don’t indiscriminately add WithRequired<…>; instead, only add it when it’s actually needed, and with the proper keys

) {
// don’t try and make keys required if the $ref doesn’t have them
const validRequired = (required ?? []).filter(
(key) => !!resolved.properties![key],
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 is probably brittle across multiple nested compositions, but that’s OK for now. I don’t think that’s a common scenario to need to specify required keys on a different schema object from a deeply-nested allOf chain

// options: DEFAULT_OPTIONS,
},
],
[
"allOf > core properties",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New test

@drwpow drwpow merged commit 679b954 into main Oct 9, 2023
@drwpow drwpow deleted the improve-composition branch October 9, 2023 23:19
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