metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.44k stars 204 forks source link

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

Closed mkreis closed 1 month ago

mkreis commented 5 months ago

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 commented 4 months ago

Might be related to https://github.com/metosin/reitit/issues/616

mkreis commented 4 months ago

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

opqdonut commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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

mkreis commented 1 month ago

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 commented 1 month ago

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

mkreis commented 1 month ago

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.