Skip to content
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

Swagger "Could not resolve pointer" with namespaced keys #1172

Open
arichiardi opened this issue Mar 11, 2025 · 8 comments
Open

Swagger "Could not resolve pointer" with namespaced keys #1172

arichiardi opened this issue Mar 11, 2025 · 8 comments

Comments

@arichiardi
Copy link

Hi there, from Slack, opening a bug report for a problem we have when using reitit.swagger/create-swagger-handler.

We register malli spec with a namespace:

(r/register! :survey/site-type [:enum ...])

and we use it in another schema, say:

(def survey
  [:map [:type :survey/type])

The generated ref for the parent object is "#ref": "$ref":"#/definitions/survey~1site-type" while in "definitions" we see {"survey/site-type": ...}.

This results in a Swagger error: Could not resolve reference: Could not resolve pointer: #/definitions/survey~1site-type.

Thanks for taking a look - let me know if you want me to test the fix locally.

@frenchy64
Copy link
Collaborator

This seems like the correct output. Are you able to post a more complete (but minimal) example? Or at least the relevant parts of the swagger.json?

@arichiardi
Copy link
Author

I can try yes to have a minimal example but I guess it cannot be correct if swagger is returning a big red error.

@arichiardi
Copy link
Author

arichiardi commented Mar 14, 2025

Oh I see what you mean now. I somehow thought the two would need to match.

To put it another way you are saying that #/definitions/survey~1site-type should correctly refer to survey/site-type (as per first link).

Thanks btw - I have just read that I guess we probably should not use them anyway (see swagger-api/swagger-ui#4161 (comment)).

@frenchy64
Copy link
Collaborator

Maybe they do need to match in some tooling, and probably openapi.

I see that even reitit's openapi support does exactly the same thing ~1 https://github.com/metosin/reitit/blob/58195eed68bc3413704c20e95b4bf7bd7abb8c7e/test/cljc/reitit/openapi_test.clj#L1002

Though it mentions this is banned in openapi https://github.com/metosin/reitit/blob/58195eed68bc3413704c20e95b4bf7bd7abb8c7e/test/cljc/reitit/openapi_test.clj#L1023-L1025

@opqdonut
Copy link
Member

Yes this whole thing with / is very unfortunate. The best thing for our users would probably be to map / to something like _ or . instead.

@arichiardi
Copy link
Author

@opqdonut the problem is that if you use namespaced keys in your malli schema you would get / in your swagger...that is why I would probably rather see the malli swagger transformer do that conversion for you if it is against the spec (or some version, for instance 3.1 or something)

@opqdonut
Copy link
Member

Yes! To be clear, what I meant was: malli should replace / with something else when generating swagger / json-schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants