-
-
Notifications
You must be signed in to change notification settings - Fork 512
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
Fix invalid $ref index into path #2185
base: main
Are you sure you want to change the base?
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.
d3c7588
to
75281ba
Compare
75281ba
to
be8590b
Compare
be8590b
to
bd77188
Compare
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
.