-
-
Notifications
You must be signed in to change notification settings - Fork 209
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
References to "definitions" #337
Comments
Good spot! Are you planning to send a PR to fix this? |
If I somehow find time and get annoyed enough by this, maybe. But this is a thing I'll probably overlook. |
Well, it would be a good contribution for a newcomer! |
Yep getting the same issue here! Resolver error at components.schemas.def-0.properties.resource.$ref
Could not resolve reference: undefined Route GET:/docs/Resource not found
Resolver error at components.schemas.def-0.properties.user.$ref
Could not resolve reference: undefined Route GET:/docs/User not found |
Same here, I was looking to migrate from fastify-oas to fastify-swagger but got blocked by this |
Maybe @climba03003 could take a look? |
I may make a custom container for handle all the related schema, it can solve the encapsulation problem and better delivery for schema in openapi 3. I just need some times to dig inside |
Some updates on this issue. I have been worked on the container structure, but it affect too much on the resolving the Some note on currently usage in
|
@climba03003 regarding this, I review a PR here with some considerations about this merge (we must not forget that we are merging many little schemas to a BIG single one): I must say that we should set the default behaviour as "user doesn't set strange schema's id" since the $id renaming works but it is annoying 😞 |
i managed to get references in schemata working with some more restrictive assumptions. doing so required some "bracketing" steps for my whole server configuration:
key to this working in this way is that destructively mutating the object vended from the assumptions were:
fixup proved somewhat baroque as i navigated through the way these schemata wound up being edited during serializer/validator construction. i observed that:
my fixup steps were basically:
this, together with setting the cwd for json2ts to the flat schemas directory, made it so all the tooling involved played nice, and now i can finally reuse specs directly. |
@jeremy-w could we get a PR to fix this once and for all? Is there anything that could be added to this repo? |
i didn't essay a PR because my solution is a very tight fit for a very restricted circumstance: i'm able to say "all refs are to local files in a single directory with no nesting" and "all objects must have a title" in my local project, and that's enough to let me fix everything up and undo the inlining of object definitions. other things i'm doing come from wanting to get openapi-generator-cli and json2ts to play nice with the generated schema (in the case of openapi-generator) and the original, on-disk schema files (in the case of json2ts). i suspect fixing these next two points would mean fixes to fastify's schema handling itself, rather than something in fastify-swagger:
(re: the renaming, it would be even better if this renaming did not happen, but that would mean updating the module doing the ref resolution, which currently doesn't support controlling or disabling this renaming at all, before anything else could be done about it.) but i don't know about any general solution: the issue that the ref resolution module, and any general solution to this problem, keep running aground on is the richness enabled by references, which can be local or remote, and can even dig into the structure of the referenced document (something i avoided having to support in my situation). this was called out in #337 (comment). that said, if we did impose restrictions like the ones i adopted on refs used with fastify-swagger, then we could unlock that level of reuse for everyone. but it's definitely not "you can use whatever refs you want, and as long as they're valid, you're golden" - it's much more restrictive than that, and requires a specific arrangement and workflow. |
cc @Eomm wdyt? |
I'm not sure if I it is the same problem, but I get the following error when doing a
I have a sample minmal repo here: https://replit.com/@mojo2600/fastify-issue-3181#index.js |
FYI, I have created a drop-in replacement for I've published the code here: https://github.com/davidschmitt/fastify-schema-resolver.git I haven't published the package on |
Where is the Edit: fastify-swagger/lib/util/add-hook.js Line 72 in 5277980
Edit2: Also providing an |
🐛 Bug Report
The "models" builder does not correctly reference embedded "definitions" style references.
To Reproduce
package.json
index.mjs
Expected behavior
The above reproduction will produce the following JSON:
If you were to start the server, instead of performing the
.inject
, and navigate tohttp://127.0.0.1:8000/_swagger/
and then click to expanddef-0
, an error will be presented like:This is due to the
definitions
block in the JSON having a structure likedefinitions.def-0.definitions.hello
. The UI expansion is instead expectingdefinitions.hello
.The text was updated successfully, but these errors were encountered: