-
-
Notifications
You must be signed in to change notification settings - Fork 539
Fix invalid $ref index into path #2185
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
👷 Deploy request for openapi-ts pending review.Visit the deploys page to approve it
|
|
|
I was also not really familiar with that It took a bit of digging, but this portion of the $ref is defined by the JSON Pointer standard.
This ref is created during bundling, allowing the same schema to be used throughout the document without first extracting it to However, this JSON Pointer is indexing into the OpenAPI structure, not the openapi-ts |
{ $ref: "#/components/parameters/query/utm_source" }, | ||
{ $ref: "#/components/parameters/query/utm_email" }, | ||
{ $ref: "#/components/parameters/query/utm_campaign" }, | ||
{ $ref: "#/components/parameters/path/version" }, |
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.
I feel like these refs were artificially-constructed to match the expected ts output, rather than extracted from a real OpenAPI ref.
Therefore, now that the parameter in
is respected, I made them more realistic, and adjusted the custom resolver and expected test output.
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.
Yup that seems right. I‘ve operated off the assumption that parameters in, say, query
vs path
are allowed to share names. But here in #/components/parameters
you’re right there’s no such thing as “query” or “path”
d3c7588
to
75281ba
Compare
75281ba
to
be8590b
Compare
be8590b
to
bd77188
Compare
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.
This was such a tricky bug, great job! Needs a changeset though to bump the release version (patch?)
I’ll merge and add a manual changeset (for this and a few other PRs) |
* Update schema-object.ts * chore(deps): update dependency msw to v2.7.6 (openapi-ts#2287) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @types/node to v22.15.10 (openapi-ts#2293) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @shikijs/vitepress-twoslash to v3.4.0 (openapi-ts#2298) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @arethetypeswrong/cli to ^0.18.0 (openapi-ts#2272) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency execa to v9.5.3 (openapi-ts#2303) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(metadata): fix thunk type detection (openapi-ts#2125) * Don't remove `null` type if a default is present. (openapi-ts#2145) * Don't remove `null` type if a default is present. * Don't remove `null` type from enums if default is present. * Don't remove `null` type if default is present (legacy) * [ci] release (openapi-ts#2307) * [ci] release * Add 2145 manually --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> * chore(deps): update dependency @types/react to v18.3.21 (openapi-ts#2218) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(openapi-fetch): fix overriding baseUrl per request without overriding default baseUrl (openapi-ts#2157) * Support $ref into `paths` (openapi-ts#2185) * React query handle 204 or zero content length (openapi-ts#2235) * fix(openapi-react-query): Handle 204 or zero Content-Length header by returning data as null * fix(openapi-react-query): updated and added 204 & zero Content-Length queryFn tests * chore(openapi-react-query): Fixed linting in test * chore(deps): update dependency @arethetypeswrong/cli to v0.18.1 (openapi-ts#2306) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency msw to v2.8.2 (openapi-ts#2304) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Speakeasy URL (openapi-ts#2302) * chore(deps): update dependency @tanstack/react-query to v5.75.7 (openapi-ts#2301) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency lint-staged to v15.5.2 (openapi-ts#2297) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * feat(swr-openapi): add custom error types to query builder (openapi-ts#2147) * chore(deps): update vitest monorepo to v3 (openapi-ts#2284) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Encode the request body if Content-Type set (openapi-ts#2096) * Improve header handling (openapi-ts#2308) * [ci] release (openapi-ts#2309) * [ci] release * Release additional packages --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> * chore: update openapi-fetch test fixture (openapi-ts#2313) * Build packages with unbuild to improve CJS support (openapi-ts#2310) * [ci] release (openapi-ts#2314) * [ci] release * Fix major bump --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> * Update code of conduct source (openapi-ts#2316) Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com> --------- Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Martin Paucot <contact@martin-paucot.fr> Co-authored-by: Theron Luhn <theron@luhn.com> Co-authored-by: openapi-ts-bot <openapi-ts@googlegroups.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <drew@pow.rs> Co-authored-by: Luis Merino <mail@luismerino.name> Co-authored-by: Duncan Beevers <duncan@dweebd.com> Co-authored-by: Wheelebin <wheelebin@users.noreply.github.com> Co-authored-by: Nolan Di Mare Sullivan <nolan.dm.sullivan@gmail.com> Co-authored-by: しゅーまい <62363188+SSlime-s@users.noreply.github.com> Co-authored-by: Olga Bulat <obulat@gmail.com> Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Refs into the parameters array are turned into invalid indexes into the
paths
structure.🗣️ Discussion
The problematic behavior is triggered using a $ref that points into the
parameters
array.The problematic generated type then tries to index into
["parameters"]["0"]
as though it were an array, when in fact it should be indexing into["parameters"]["query"]
.This particular weird ref was generated when I bundled a big schema with @apidevtools/json-schema-ref-parser.
🔧 Fix
oapiRefs
from parameters arrays, pass the resolved ParameterObject and use itsin
method to index intoparameters
type.This probably doesn't work for more complex $refs, but I think it does slightly improve the semantic awareness of
oapiRef
.