-
-
Notifications
You must be signed in to change notification settings - Fork 156
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
Duplicate remote $ref
paths not resolved correctly
#1135
Comments
|
Nice catch, thanks for reporting @SimonLudwigNeteleven! |
@SimonLudwigNeteleven quick update, I found that this is most likely an issue with the underlying dependency https://github.com/APIDevTools/json-schema-ref-parser. Maybe there's a configuration for this, but a quick search didn't return anything. For context, this is what happens internally. The first reference gets correctly bundled, for example: {
"type": "object",
"properties": { "foo": { "enum": [], "type": "string" } }
} while the second one produces this faulty reference. {
"$ref": "#/paths/~1a/get/responses/default/content/application~1json/schema"
} I do plan to vertically integrate this tool eventually. Most people don't compose their schemas like this so it has not been reported before. Could you provide more context about your setup? How would you expect the remote reference to be resolved? Inline them or should they also create a reusable component and reference that? |
$ref
paths not resolved correctly
@mmospanenko could you check the question above too? |
we have enough complicated flow, as source builds 300k lines yml file and has a lot of mistakes. I use as reference, giving ability to override some nodes ($ref) and as result we have template with tons of refs like your ("$ref": "#/paths/ Now I use multi-file structure (from Redocly with their CLI) and it solves my case. So I have source file, it splits by files, then devs can add another copy of this file structure as 'overrides' folder, we prepare 'template' output file only with required paths, it merges and builds as result. So TS in my case builds only from output, correct file, without complicated references. And this flow is better for my case now, not sure that TS generator should care about this, but it is definitely a bug from OAS perspective. |
Hey all, the good news is there's now https://github.com/hey-api/json-schema-ref-parser so the fix is a bit closer than before, I just need to find time to prioritise it |
@mrlubos Thanks! And also cudos for hey API itself, I really like it :) So is there something I can currently do in my project to fix this or do I have to wait until hey-api/json-schema-ref-parser is integrated by you? |
Nothing you can do on your end to fix this I am afraid, this is a bug with how those $refs are resolved. I am not sure how much effort it will be to fix at this point. A workaround on your end would be to bundle the schema yourself into a single file and pass that to |
Hey @mrlubos was there any update on this? By the way, really love the lib. |
If anyone wants to NOT Bundle schemas and still have it work, add the same component in the yaml and then make it ref the actual external schema. eg. components:
schemas:
# hey-api's having a dependency breaking thats breaking generated types
# when the same external ref is repeated .
# Temporary fix is to create a schema that points to the external ref and then use it.
TeamSize:
$ref: "./company.yaml#/components/schemas/TeamSize"
|
I followed @mrlubos 's advice but it took me a few to try to figure it out, so I thought I'd share. I was having a lot of trouble (honestly a lot of similar issues) using the bundler that comes with Anyway, here's my bundle -> createClient step: execSync(`redocly bundle ${inputUrl} --output ./.tmp/bundled.yml`);
await createClient({
input: './.tmp/bundled.yml',
//...
}) |
Description
The command "yarn generate" should create all generated files including "types.gen.ts" without any issues.
The files are generated, but the response type of “B” is broken after the command finishes. This only happens, if both path references in the yaml file are the same for both paths. The first correct one wins, if both are the same.
This behavior breaks the type generation and I could only work around it, by making one path beginning with “http” instead of “https” in my project. This workaround is obviously more hack then a solution and works only for two paths maximum.
You can’t test the hack solution with “http” in stackblitz, because only “https” is allowed for the ref path, but you can reproduce the error.
Steps to reproduce the behavior
Expected behavior
AResponse and BResponse should be “(unknown)”.
Reproducible example or configuration
https://stackblitz.com/edit/vitejs-vite-6tvzvt?file=packages%2Ftest-api%2Fopenapi-spec%2Fnavigation-api.yaml
OpenAPI specification (optional)
No response
System information (optional)
No response
The text was updated successfully, but these errors were encountered: