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 JSON missing global definitions from schema used in request spec #1002

Closed
mkreis opened this issue Jan 29, 2024 · 8 comments · Fixed by #1059
Closed

Swagger JSON missing global definitions from schema used in request spec #1002

mkreis opened this issue Jan 29, 2024 · 8 comments · Fixed by #1059

Comments

@mkreis
Copy link

mkreis commented Jan 29, 2024

I think I found a bug regarding Swagger Schema generation:

Only definitions from schemas referred to in responses are shown as global definitions in /definitions, but those from requests are missing.

With the following Reitit route config

:parameters {:body [:map [:company ::validation/company1]]}
        :responses {200 {:body ::validation/company2}}

only company2 will be in /definitions (although the ref$ to both def’s are there, thus causing a missing/invalid reference to company1).

I'm using Malli 0.14.0 and Reitit 0.7.0-alpha7

@aviflax
Copy link

aviflax commented Feb 29, 2024

Might be related to metosin/reitit#616

@mkreis
Copy link
Author

mkreis commented Mar 1, 2024

But only very loosely. As far as I understand, metosin/reitit#616 is about the overall location of definitions for the OpenAPI schema, whereas here it is about missing parts in the definition.

@opqdonut
Copy link
Member

Thanks for the report! I only noticed it now since it's in this repo and not reitit. I think I see the where the problem is.

@opqdonut
Copy link
Member

I'm unable to reproduce this with malli 0.16.0 and the latest reitit master. The code in malli does look a bit suspicious. Do you have a working reproduction @mkreis ?

@mkreis
Copy link
Author

mkreis commented Apr 22, 2024

I can try to reproduce it with malli 0.16.0 and add the results here.

@mkreis
Copy link
Author

mkreis commented May 15, 2024

Hi @opqdonut , I managed to recreate it with a simple project: https://github.com/mkreis/malli-issue-1002
As it turned out, the probem is caused by multiple entries in the :parameters map, e.g. parameters for :path, :query and :body at the same time. If there is only one key, then the definitions are exported. With multiple keys, it's broken.
In my sample project above, I have marked the particular section in file service.clj.

@opqdonut
Copy link
Member

Thanks! I'll try to have a look tomorrow.

@mkreis
Copy link
Author

mkreis commented May 15, 2024

Cool, thank you!

Also I just noticed that it works if key :body is the first key in the :parameters map. So it might be easy to fix... I hope.

opqdonut added a commit that referenced this issue May 16, 2024
fixes #1002

kudos to @mkreis for the excellent bug report!
opqdonut added a commit that referenced this issue May 21, 2024
fixes #1002

kudos to @mkreis for the excellent bug report!
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

Successfully merging a pull request may close this issue.

3 participants