-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Conversation
2cfc5de
to
1624899
Compare
expect(generated).toBe(`{ | ||
"user-created": { | ||
parameters: { | ||
query: { | ||
signature: string; | ||
} & (Pick<NonNullable<components["parameters"]["query"]>, "utm_source" | "utm_email" | "utm_campaign">); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 () => { |
There was a problem hiding this comment.
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
@@ -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)) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
Changes
Fixes #984. Supercedes #997.
How to Review
👀 See example changes
Checklist
examples/
directory updated (if applicable)