Skip to content
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

Support JSONSchema $defs #1317

Merged
merged 4 commits into from
Aug 20, 2023
Merged

Support JSONSchema $defs #1317

merged 4 commits into from
Aug 20, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Aug 20, 2023

Changes

Fixes #1261 and adds support for JSONSchema $defs that can be defined on any object type or the root schema itself

⚠️ Caveat

Although in JSONSchema, $defs can be defined anywhere, unfortunately TypeScript doesn’t allow you to define keys on anything other than an object. For example, if you tried putting $defs on a string, how would you access them? Keep in mind that only object types (and the root schema itself) will keep their $defs.

How to Review

  • Tests added; 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 Aug 20, 2023

🦋 Changeset detected

Latest commit: 4a4b837

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
openapi-typescript Patch

Not sure what this means? Click here to learn what changesets are.

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

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 20, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4a4b837
Status: ✅  Deploy successful!
Preview URL: https://bc030e61.openapi-ts.pages.dev
Branch Preview URL: https://jsonschema-defs.openapi-ts.pages.dev

View logs

@drwpow drwpow force-pushed the jsonschema-defs branch 6 times, most recently from ef6afaf to 8ce204c Compare August 20, 2023 04:59
subschemaOutput += "{\n";
indentLv++;

outer: for (const [name, schemaObject] of getEntries(subschema.schema!)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Clean up a lot of duplicated transforming of a map of schema objects with transformSchemaObjectMap().

@@ -15704,7 +16002,7 @@ export interface external {
vpcs?: external["resources/vpcs/models/vpc.yml"]["vpc"][];
} & external["shared/pages.yml"]["pagination"] & external["shared/meta.yml"];
};
}
};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

More semi fixes

@@ -14970,8 +15105,92 @@ export interface external {
default: external["shared/responses/unexpected_error.yml"];
};
}
"resources/uptime/models/alert.yml": unknown;
"resources/uptime/models/check.yml": unknown;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also many unknowns were fixed by treating more remote $refs as Schema Object maps

@drwpow drwpow merged commit 5e054db into main Aug 20, 2023
8 checks passed
@drwpow drwpow deleted the jsonschema-defs branch August 20, 2023 05:24
@github-actions github-actions bot mentioned this pull request Aug 20, 2023
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.

Components that define $defs are incorrectly typed as unknown
1 participant