openapi-typescript icon indicating copy to clipboard operation
openapi-typescript copied to clipboard

Fix invalid $ref index into path

Open duncanbeevers opened this issue 9 months ago • 4 comments

⚠️ The Error

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.

:wrench: Fix

  • While parsing oapiRefs from parameters arrays, pass the resolved ParameterObject and use its in method to index into parameters type.

This probably doesn't work for more complex $refs, but I think it does slightly improve the semantic awareness of oapiRef.

duncanbeevers avatar Feb 28 '25 04:02 duncanbeevers