You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our use case is using Redoc's codeSamples in our FastAPI, from which we generate a hey-api client. We're including code samples from external code files, which requires specifying $ref. However, when running openapi-ts - it crashes, probably because it tries to parse the example files, thinking they are schemas it should parse, even though it shouldn't care about it...
Here's the error:
The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
TypeError: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined
at new NodeError (node:internal/errors:405:5)
at Function.from (node:buffer:333:9)
at Object.handler (<project_location>/node_modules/@hey-api/json-schema-ref-parser/dist/lib/resolvers/url.js:60:28)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Attached is a very minimal StackBlitz project that demonstrates this. I've recreated the issue with a basic express server that serves a static openapi.json file - which mimics the FastAPI behavior, with the same error. Start by running npm run api to run the express server, then run npm run openapi-ts to fetch the openapi.json from it and generate a client - and you'll get a crash and a log file with the error.
There's another error achievable - if there's no sample-codes (not having the directory, or not mounting it in the API) - running openapi-ts results in a crash where it tried to access the sample code. Again, it shouldn't care about it...
🔥 Unexpected error occurred. Log saved to /home/projects/hey-api-client-fetch-example-cfjyssvs/openapi-ts-error-1747212135509.log
🔥 Unexpected error occurred. Error opening file "/sample-codes/my_example.py"
ENOENT: no such file or directory, open '/sample-codes/my_example.py'
Hey @mrlubos, thanks for the quick response!
You're right, I missed an important part - $ref can be used to point to other schema files, which does make distinguishing $refs we "care" about vs those we don't pretty difficult (or even impossible). So I take it back, sorry 😅
Here are some possible approaches for your consideration:
Gracefully ignore unresolved $refs (potentially with a warning message?)
Ignore $refs inside vendor extensions (like my example's x-codeSamples)
Only parse $ref from specific fields like responses, requestBody, etc
Description
Our use case is using Redoc's codeSamples in our FastAPI, from which we generate a hey-api client. We're including code samples from external code files, which requires specifying
$ref
. However, when runningopenapi-ts
- it crashes, probably because it tries to parse the example files, thinking they are schemas it should parse, even though it shouldn't care about it...Here's the error:
Attached is a very minimal StackBlitz project that demonstrates this. I've recreated the issue with a basic express server that serves a static
openapi.json
file - which mimics the FastAPI behavior, with the same error. Start by runningnpm run api
to run the express server, then runnpm run openapi-ts
to fetch theopenapi.json
from it and generate a client - and you'll get a crash and a log file with the error.There's another error achievable - if there's no
sample-codes
(not having the directory, or not mounting it in the API) - runningopenapi-ts
results in a crash where it tried to access the sample code. Again, it shouldn't care about it...Versions:
By the way, this only started happening after I upgraded
@hey-api/openapi-ts
from0.53.1
to0.67.3
, it worked before upgradingReproducible example or configuration
https://stackblitz.com/edit/hey-api-client-fetch-example-cfjyssvs
OpenAPI specification (optional)
System information (optional)
No response
The text was updated successfully, but these errors were encountered: