Skip to content

Fix parameters with references #1061

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
Mar 30, 2023
Merged

Fix parameters with references #1061

merged 1 commit into from
Mar 30, 2023

Conversation

drwpow
Copy link
Contributor

@drwpow drwpow commented Mar 30, 2023

Changes

Fixes #984. Supercedes #997.

How to Review

👀 See example changes

Checklist

  • Unit tests updated
  • README updated
  • examples/ directory updated (if applicable)

@drwpow drwpow force-pushed the fix/param-refs branch 3 times, most recently from 2cfc5de to 1624899 Compare March 30, 2023 23:39
expect(generated).toBe(`{
"user-created": {
parameters: {
query: {
signature: string;
} & (Pick<NonNullable<components["parameters"]["query"]>, "utm_source" | "utm_email" | "utm_campaign">);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this changes parameters instead to exist in the original objects, rather than trying to “cheat” and infer their position based on path. The former way of doing it doesn’t work across deeply-nested subschemas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting rid of Pick<> wasn’t exactly necessary, but one object is arguably cleaner and easier to introspect

`);
});

test("parameter $refs", async () => {
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 regression test for this

@drwpow drwpow merged commit c10ac5e into main Mar 30, 2023
@drwpow drwpow deleted the fix/param-refs branch March 30, 2023 23:46
@@ -288,7 +291,18 @@ export default async function load(
}
}

// 4. scan for discriminators (after everything’s resolved in one file)
// 4. collect parameters (which must be hoisted to the top)
for (const k of Object.keys(options.schemas)) {
Copy link
Contributor Author

@drwpow drwpow Mar 30, 2023

Choose a reason for hiding this comment

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

The fix for this was adding an entire additional pass over all subschemas 😞. This PR does make openapi-typescript noticably slower (don’t worry—we’re still only talking milliseconds), however, it’s still faster than 5.x by an order of magnitude (not needing Prettier to run).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But slow + correct is better than fast + broken.

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.

$ref in parameters not being transpiled
1 participant