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

Fix malli swagger defs w/ custom registries #589

Merged
merged 8 commits into from
Sep 1, 2023

Conversation

cap10morgan
Copy link
Contributor

Fixes #558

Relies on the changes in metosin/malli#863

Lifts the definitions to the root of the swagger.json document so that all of the $refs to them can resolve. Also fixes some naming / encoding issues with them and a circular ref problem I was noticing where sometimes a definition would just become a ref to itself.

...so that all of the absolute $ref's to them will resolve
@cap10morgan
Copy link
Contributor Author

@opqdonut I can merge master and resolve that conflict. Anything else needed in here?

{:status 200
:body (meta-merge swagger {:paths paths})}))
:body (meta-merge swagger {:paths paths :definitions definitions})}))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please update the existing tests and add a new one that uses a registry!

@opqdonut
Copy link
Member

oh and you also need to bump the malli dep to 0.10.4

@ikitommi
Copy link
Member

bump here: #597

@opqdonut
Copy link
Member

right, that's now merged so @cap10morgan can just re-merge master

@cap10morgan
Copy link
Contributor Author

Locally I'm getting an odd error trying to run the tests on this branch:

ERROR in reitit.swagger-test/swagger-test (core.cljc:138)
Uncaught exception, not in assertion.

clojure.lang.ExceptionInfo: :malli.core/invalid-schema
       data: {:schema nil}
    message: :malli.core/invalid-schema
       type: :malli.core/invalid-schema

If you scroll through the stacktrace to the first mention of the test code, it's coming from here. This is confusing because I'm not sure how my changes would have caused this. Is the clue in the {:schema nil}? Something's just not allowing it to get the schema at all now?

@opqdonut
Copy link
Member

Looks to me like the problem is a response with a :description but no :schema. malli.swagger fails on a nil input.

:responses {500 {:description "fail"}}

A fix and a test for malli is probably the right solution to this.

@opqdonut
Copy link
Member

the malli fix is now out in 0.11.0

dep bump PR for reitit here: #607

@opqdonut
Copy link
Member

Dep bump merged. Please merge master to this PR and the tests should pass!

@cap10morgan
Copy link
Contributor Author

I merged master but still had a couple of test failures. I haven't had a chance to look into them yet but I will when I do.

@cap10morgan
Copy link
Contributor Author

I updated the swagger test expectations in 182524b but let me know if those aren't good expectations (i.e. if you'd rather the actual result were different rather than the expected value).

@opqdonut
Copy link
Member

Yeah the changed assertions are fine! Could you add a test that uses the registry/definitions though? It's useful as documentation and a regression test even though this is mostly tested on the malli level.

@opqdonut
Copy link
Member

... and if you don't feel like working on those tests, just tell me. We can merge this and I'll add some tests.

@cap10morgan
Copy link
Contributor Author

... and if you don't feel like working on those tests, just tell me. We can merge this and I'll add some tests.

Happy to! But I probably won't get to them until tomorrow. If you don't want to wait on me, feel free to add them and merge.

@opqdonut
Copy link
Member

No great rush, but at some point we want to be able to get a release candidate out. I'm happy to wait for you for a week at least.

@cap10morgan
Copy link
Contributor Author

@opqdonut I added a test w/ definitions in 9377686

:x-anyOf [{:type "object"}
{:type "string"}]}
::resp-map {:type "object"}
::resp-string {:type "string", :minLength 1}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the :definitions are now on three levels: inside the :schema, inside :put and at the top level of the swagger spec. Is that what we want? By reading the spec, it seems only the top-level :definitions is supported.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not ideal. Only the top-level one gets used for anything I believe. Want me to explore eliminating the others?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you can find an easy way to do that, it would be nice. I think swagger validators will complain about the intermediate ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The malli side of that work is in metosin/malli#900

@cap10morgan
Copy link
Contributor Author

cap10morgan commented May 2, 2023

I'm not sure how to point a leiningen project (or this leiningen project) at a git commit or a local working directory of malli to test that the new test expectations are correct. I tried adding e.g. "../malli" to the :profiles :dev :source-paths vector but that didn't work.

Can you give me a pointer on how you all usually do that? Otherwise I can write up just enough of a deps.edn to run the tests and submit that too if desired.

@opqdonut
Copy link
Member

opqdonut commented May 3, 2023

Deps-to-deps and lein-to-lein local dependencies would be easy. Unfortunately for deps-to-lein the easiest way is to install the malli jar in your local maven repository. See https://github.com/metosin/malli#installing-locally . I've done something like this:

  1. bump the malli version number
  2. build and install malli locally
  3. bump the malli version in reitit's project.clj (there are two places to do it!)
  4. run tests

@cap10morgan
Copy link
Contributor Author

Deps-to-deps and lein-to-lein local dependencies would be easy. Unfortunately for deps-to-lein the easiest way is to install the malli jar in your local maven repository. See https://github.com/metosin/malli#installing-locally . I've done something like this:

  1. bump the malli version number
  2. build and install malli locally
  3. bump the malli version in reitit's project.clj (there are two places to do it!)
  4. run tests

Hmm... I did all that but I'm still getting the old output w/ non-root definitions in the swagger tests. Any idea why that might be?

@opqdonut
Copy link
Member

opqdonut commented May 5, 2023

The currently-pushed tests fail for me with a new malli. This is what I did:

In the malli repo:

% git diff
diff --git a/pom.xml b/pom.xml
index 374b57a..ed2634a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
   <modelVersion>4.0.0</modelVersion>
   <groupId>metosin</groupId>
   <artifactId>malli</artifactId>
-  <version>0.11.0</version>
+  <version>0.11.1-alpha1</version>
   <name>malli</name>
   <licenses>
     <license>
@@ -15,7 +15,7 @@
     <url>https://github.com/metosin/malli</url>
     <connection>scm:git:git://github.com/metosin/malli.git</connection>
     <developerConnection>scm:git:ssh://git@github.com/metosin/malli.git</developerConnection>
-    <tag>0.11.0</tag>
+    <tag>0.11.1-alpha1</tag>
   </scm>
   <dependencies>
     <dependency>
% clj -Mjar
% clj -Minstall
Installing metosin/malli-0.11.1-alpha1 to your local `.m2`
done.

Then in the reitit repo:

% git show
commit 937768651e659203151c121e119d28c85bf61a32 (HEAD -> fix/malli-swagger-defs)
Author: Wes Morgan <git@wesmorgan.me>
Date:   2023-04-20 12:39:08 -0600

    Add malli swagger test w/ definitions
% git diff
diff --git a/project.clj b/project.clj
index 801a7706..4e019183 100644
--- a/project.clj
+++ b/project.clj
@@ -37,7 +37,7 @@
                          [metosin/muuntaja "0.6.8"]
                          [metosin/jsonista "0.3.7"]
                          [metosin/sieppari "0.0.0-alpha13"]
-                         [metosin/malli "0.11.0"]
+                         [metosin/malli "0.11.1-alpha1"]
 
                          ;; https://clojureverse.org/t/depending-on-the-right-versions-of-jackson-libraries/5111
                          [com.fasterxml.jackson.core/jackson-core "2.14.2"]
@@ -92,7 +92,7 @@
                                   [metosin/muuntaja "0.6.8"]
                                   [metosin/sieppari "0.0.0-alpha13"]
                                   [metosin/jsonista "0.3.7"]
-                                  [metosin/malli "0.11.0"]
+                                  [metosin/malli "0.11.1-alpha1"]
                                   [lambdaisland/deep-diff "0.0-47"]
                                   [meta-merge "1.0.0"]
                                   [com.bhauman/spell-spec "0.1.2"]
% lein test-clj
# an example failure
    diff: - {:paths {"/api/malli/plus/{z}" {:put {:parameters [{:schema {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                                                                                     :x-anyOf [{:type "string"}
                                                                                                                               {:type "string"}]},
                                                                                       :reitit.swagger-test/req-val {:type "object",
                                                                                                                     :x-anyOf [{:type "object"}
                                                                                                                               {:type "string"}]}}}}],
                                                  :responses {200 {:schema {:definitions {:reitit.swagger-test/resp-map {:type "object"},
                                                                                          :reitit.swagger-test/resp-string {:minLength 1,
                                                                                                                            :type "string"}}}}}}}}}
          + {:paths {"/api/malli/plus/{z}" {:get {:parameters [{:schema nil}
                                                               {:schema nil}
                                                               {:schema nil}]},
                                            :post {:parameters [nil
                                                                {:schema nil}]}}}}

@cap10morgan
Copy link
Contributor Author

@opqdonut OK thank you for those detailed steps. I'll look into this again today and hopefully confirm that my local changes to the reitit tests are happy w/ the malli changes.

@cap10morgan
Copy link
Contributor Author

@opqdonut Hmm... I still can't get it to use malli master HEAD for some reason. I'm still seeing non-root :definitions in the actual values when I run the tests. I'll push the test changes here and see if you have better luck with them.

...which should only be at the top level now.
@opqdonut
Copy link
Member

Here are the failures I'm getting for commit 59812a3 (with an unreleased malli).

It looks like a bunch of :definitions nil and :schema nil key-value-pairs are appearing that weren't there previously. Also, :put still has :definitions.

FAIL in reitit.swagger-test/swagger-test (swagger_test.clj:352)
swagger-spec
expected: {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                       :x-anyOf [{:type "string"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/req-val {:type "object",
                                                       :x-anyOf [{:type "object"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/resp-map {:type "object"},
                         :reitit.swagger-test/resp-string {:minLength 1,
                                                           :type "string"}},
           :info {:title "my-api"},
           :paths {"/api/malli/plus/{z}" {:get {:parameters [{:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :x,
                                                              :required true,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :y,
                                                              :required true,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name :z,
                                                              :required true,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:additionalProperties false,
                                                                          :properties {:total {:format "int64",
                                                                                               :type "integer"}},
                                                                          :required [:total],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus"},
                                          :post {:parameters [{:description "",
                                                               :in "body",
                                                               :name "body",
                                                               :required false,
                                                               :schema {:items {:format "int64",
                                                                                :type "integer"},
                                                                        :type "array",
                                                                        :x-nullable true}}
                                                              {:description "",
                                                               :format "int64",
                                                               :in "path",
                                                               :name :z,
                                                               :required true,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {:total {:format "int64",
                                                                                                :type "integer"}},
                                                                           :required [:total],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus with body"},
                                          :put {:parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required true,
                                                              :schema {:additionalProperties {:$ref "#/definitions/reitit.swagger-test~1req-val"},
                                                                       :type "object"}}],
                                                :responses {200 {:description "",
                                                                 :schema {:$ref "#/definitions/reitit.swagger-test~1resp-map",
                                                                          :x-anyOf [{:$ref "#/definitions/reitit.swagger-test~1resp-map"}
                                                                                    {:$ref "#/definitions/reitit.swagger-test~1resp-string"}]}},
                                                            500 {:description "fail"}},
                                                :summary "plus put with definitions"}},
                   "/api/schema/plus/{z}" {:get {:parameters [{:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "x",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "y",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "path",
                                                               :name "z",
                                                               :required true,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {"total" {:format "int32",
                                                                                                 :type "integer"}},
                                                                           :required ["total"],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus"},
                                           :post {:parameters [{:description "",
                                                                :in "body",
                                                                :name "body",
                                                                :required false,
                                                                :schema {:items {:format "int32",
                                                                                 :type "integer"},
                                                                         :type "array",
                                                                         :x-nullable true}}
                                                               {:description "",
                                                                :format "int32",
                                                                :in "path",
                                                                :name "z",
                                                                :required true,
                                                                :type "integer"}],
                                                  :responses {200 {:description "",
                                                                   :schema {:additionalProperties false,
                                                                            :properties {"total" {:format "int32",
                                                                                                  :type "integer"}},
                                                                            :required ["total"],
                                                                            :type "object"}},
                                                              400 {:description "kosh",
                                                                   :schema {:type "string"}},
                                                              500 {:description "fail"}},
                                                  :summary "plus with body"}},
                   "/api/spec/plus/{z}" {:get {:operationId "GetPlus",
                                               :parameters [{:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "x",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "y",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "path",
                                                             :name "z",
                                                             :required true,
                                                             :type "integer"}],
                                               :responses {200 {:description "",
                                                                :schema {:properties {"total" {:format "int64",
                                                                                               :type "integer"}},
                                                                         :required ["total"],
                                                                         :type "object"}},
                                                           400 {:description "kosh",
                                                                :schema {:type "string"}},
                                                           500 {:description "fail"}},
                                               :summary "plus"},
                                         :options {:parameters [],
                                                   :responses {200 {:description "200"}},
                                                   :summary "options"},
                                         :patch {:operationId "Patch",
                                                 :parameters [],
                                                 :responses {:default {:description ""}},
                                                 :summary "patch"},
                                         :post {:parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required false,
                                                              :schema {:items {:format "int64",
                                                                               :type "integer"},
                                                                       :type "array",
                                                                       :x-nullable true}}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name "z",
                                                              :required true,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:properties {"total" {:format "int64",
                                                                                                :type "integer"}},
                                                                          :required ["total"],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus with body"}}},
           :swagger "2.0",
           :x-id #{:reitit.swagger-test/math}}
  actual: {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                       :x-anyOf [{:type "string"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/req-val {:type "object",
                                                       :x-anyOf [{:type "object"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/resp-map {:type "object"},
                         :reitit.swagger-test/resp-string {:minLength 1,
                                                           :type "string"}},
           :info {:title "my-api"},
           :paths {"/api/malli/plus/{z}" {:get {:definitions nil,
                                                :parameters [{:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :x,
                                                              :required true,
                                                              :schema nil,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :y,
                                                              :required true,
                                                              :schema nil,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name :z,
                                                              :required true,
                                                              :schema nil,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:additionalProperties false,
                                                                          :properties {:total {:format "int64",
                                                                                               :type "integer"}},
                                                                          :required [:total],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus"},
                                          :post {:definitions nil,
                                                 :parameters [{:description "",
                                                               :in "body",
                                                               :name "body",
                                                               :required false,
                                                               :schema {:items {:format "int64",
                                                                                :type "integer"},
                                                                        :type "array",
                                                                        :x-nullable true}}
                                                              {:description "",
                                                               :format "int64",
                                                               :in "path",
                                                               :name :z,
                                                               :required true,
                                                               :schema nil,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {:total {:format "int64",
                                                                                                :type "integer"}},
                                                                           :required [:total],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus with body"},
                                          :put {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                                                            :x-anyOf [{:type "string"}
                                                                                                      {:type "string"}]},
                                                              :reitit.swagger-test/req-val {:type "object",
                                                                                            :x-anyOf [{:type "object"}
                                                                                                      {:type "string"}]},
                                                              :reitit.swagger-test/resp-map {:type "object"},
                                                              :reitit.swagger-test/resp-string {:minLength 1,
                                                                                                :type "string"}},
                                                :parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required true,
                                                              :schema {:additionalProperties {:$ref "#/definitions/reitit.swagger-test~1req-val"},
                                                                       :type "object"}}],
                                                :responses {200 {:description "",
                                                                 :schema {:$ref "#/definitions/reitit.swagger-test~1resp-map",
                                                                          :x-anyOf [{:$ref "#/definitions/reitit.swagger-test~1resp-map"}
                                                                                    {:$ref "#/definitions/reitit.swagger-test~1resp-string"}]}},
                                                            500 {:description "fail"}},
                                                :summary "plus put with definitions"}},
                   "/api/schema/plus/{z}" {:get {:parameters [{:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "x",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "y",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "path",
                                                               :name "z",
                                                               :required true,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {"total" {:format "int32",
                                                                                                 :type "integer"}},
                                                                           :required ["total"],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus"},
                                           :post {:parameters [{:description "",
                                                                :in "body",
                                                                :name "body",
                                                                :required false,
                                                                :schema {:items {:format "int32",
                                                                                 :type "integer"},
                                                                         :type "array",
                                                                         :x-nullable true}}
                                                               {:description "",
                                                                :format "int32",
                                                                :in "path",
                                                                :name "z",
                                                                :required true,
                                                                :type "integer"}],
                                                  :responses {200 {:description "",
                                                                   :schema {:additionalProperties false,
                                                                            :properties {"total" {:format "int32",
                                                                                                  :type "integer"}},
                                                                            :required ["total"],
                                                                            :type "object"}},
                                                              400 {:description "kosh",
                                                                   :schema {:type "string"}},
                                                              500 {:description "fail"}},
                                                  :summary "plus with body"}},
                   "/api/spec/plus/{z}" {:get {:operationId "GetPlus",
                                               :parameters [{:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "x",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "y",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "path",
                                                             :name "z",
                                                             :required true,
                                                             :type "integer"}],
                                               :responses {200 {:description "",
                                                                :schema {:properties {"total" {:format "int64",
                                                                                               :type "integer"}},
                                                                         :required ["total"],
                                                                         :type "object"}},
                                                           400 {:description "kosh",
                                                                :schema {:type "string"}},
                                                           500 {:description "fail"}},
                                               :summary "plus"},
                                         :options {:parameters [],
                                                   :responses {200 {:description "200"}},
                                                   :summary "options"},
                                         :patch {:operationId "Patch",
                                                 :parameters [],
                                                 :responses {:default {:description ""}},
                                                 :summary "patch"},
                                         :post {:parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required false,
                                                              :schema {:items {:format "int64",
                                                                               :type "integer"},
                                                                       :type "array",
                                                                       :x-nullable true}}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name "z",
                                                              :required true,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:properties {"total" {:format "int64",
                                                                                                :type "integer"}},
                                                                          :required ["total"],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus with body"}}},
           :swagger "2.0",
           :x-id #{:reitit.swagger-test/math}}
    diff: + {:paths {"/api/malli/plus/{z}" {:get {:definitions nil,
                                                  :parameters [{:schema nil}
                                                               {:schema nil}
                                                               {:schema nil}]},
                                            :post {:definitions nil,
                                                   :parameters [nil
                                                                {:schema nil}]},
                                            :put {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                                                              :x-anyOf [{:type "string"}
                                                                                                        {:type "string"}]},
                                                                :reitit.swagger-test/req-val {:type "object",
                                                                                              :x-anyOf [{:type "object"}
                                                                                                        {:type "string"}]},
                                                                :reitit.swagger-test/resp-map {:type "object"},
                                                                :reitit.swagger-test/resp-string {:minLength 1,
                                                                                                  :type "string"}}}}}}

FAIL in reitit.swagger-test/swagger-test (swagger_test.clj:359)
swagger-spec ring-async swagger-spec
expected: {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                       :x-anyOf [{:type "string"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/req-val {:type "object",
                                                       :x-anyOf [{:type "object"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/resp-map {:type "object"},
                         :reitit.swagger-test/resp-string {:minLength 1,
                                                           :type "string"}},
           :info {:title "my-api"},
           :paths {"/api/malli/plus/{z}" {:get {:parameters [{:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :x,
                                                              :required true,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :y,
                                                              :required true,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name :z,
                                                              :required true,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:additionalProperties false,
                                                                          :properties {:total {:format "int64",
                                                                                               :type "integer"}},
                                                                          :required [:total],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus"},
                                          :post {:parameters [{:description "",
                                                               :in "body",
                                                               :name "body",
                                                               :required false,
                                                               :schema {:items {:format "int64",
                                                                                :type "integer"},
                                                                        :type "array",
                                                                        :x-nullable true}}
                                                              {:description "",
                                                               :format "int64",
                                                               :in "path",
                                                               :name :z,
                                                               :required true,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {:total {:format "int64",
                                                                                                :type "integer"}},
                                                                           :required [:total],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus with body"},
                                          :put {:parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required true,
                                                              :schema {:additionalProperties {:$ref "#/definitions/reitit.swagger-test~1req-val"},
                                                                       :type "object"}}],
                                                :responses {200 {:description "",
                                                                 :schema {:$ref "#/definitions/reitit.swagger-test~1resp-map",
                                                                          :x-anyOf [{:$ref "#/definitions/reitit.swagger-test~1resp-map"}
                                                                                    {:$ref "#/definitions/reitit.swagger-test~1resp-string"}]}},
                                                            500 {:description "fail"}},
                                                :summary "plus put with definitions"}},
                   "/api/schema/plus/{z}" {:get {:parameters [{:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "x",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "y",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "path",
                                                               :name "z",
                                                               :required true,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {"total" {:format "int32",
                                                                                                 :type "integer"}},
                                                                           :required ["total"],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus"},
                                           :post {:parameters [{:description "",
                                                                :in "body",
                                                                :name "body",
                                                                :required false,
                                                                :schema {:items {:format "int32",
                                                                                 :type "integer"},
                                                                         :type "array",
                                                                         :x-nullable true}}
                                                               {:description "",
                                                                :format "int32",
                                                                :in "path",
                                                                :name "z",
                                                                :required true,
                                                                :type "integer"}],
                                                  :responses {200 {:description "",
                                                                   :schema {:additionalProperties false,
                                                                            :properties {"total" {:format "int32",
                                                                                                  :type "integer"}},
                                                                            :required ["total"],
                                                                            :type "object"}},
                                                              400 {:description "kosh",
                                                                   :schema {:type "string"}},
                                                              500 {:description "fail"}},
                                                  :summary "plus with body"}},
                   "/api/spec/plus/{z}" {:get {:operationId "GetPlus",
                                               :parameters [{:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "x",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "y",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "path",
                                                             :name "z",
                                                             :required true,
                                                             :type "integer"}],
                                               :responses {200 {:description "",
                                                                :schema {:properties {"total" {:format "int64",
                                                                                               :type "integer"}},
                                                                         :required ["total"],
                                                                         :type "object"}},
                                                           400 {:description "kosh",
                                                                :schema {:type "string"}},
                                                           500 {:description "fail"}},
                                               :summary "plus"},
                                         :options {:parameters [],
                                                   :responses {200 {:description "200"}},
                                                   :summary "options"},
                                         :patch {:operationId "Patch",
                                                 :parameters [],
                                                 :responses {:default {:description ""}},
                                                 :summary "patch"},
                                         :post {:parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required false,
                                                              :schema {:items {:format "int64",
                                                                               :type "integer"},
                                                                       :type "array",
                                                                       :x-nullable true}}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name "z",
                                                              :required true,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:properties {"total" {:format "int64",
                                                                                                :type "integer"}},
                                                                          :required ["total"],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus with body"}}},
           :swagger "2.0",
           :x-id #{:reitit.swagger-test/math}}
  actual: {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                       :x-anyOf [{:type "string"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/req-val {:type "object",
                                                       :x-anyOf [{:type "object"}
                                                                 {:type "string"}]},
                         :reitit.swagger-test/resp-map {:type "object"},
                         :reitit.swagger-test/resp-string {:minLength 1,
                                                           :type "string"}},
           :info {:title "my-api"},
           :paths {"/api/malli/plus/{z}" {:get {:definitions nil,
                                                :parameters [{:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :x,
                                                              :required true,
                                                              :schema nil,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "query",
                                                              :name :y,
                                                              :required true,
                                                              :schema nil,
                                                              :type "integer"}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name :z,
                                                              :required true,
                                                              :schema nil,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:additionalProperties false,
                                                                          :properties {:total {:format "int64",
                                                                                               :type "integer"}},
                                                                          :required [:total],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus"},
                                          :post {:definitions nil,
                                                 :parameters [{:description "",
                                                               :in "body",
                                                               :name "body",
                                                               :required false,
                                                               :schema {:items {:format "int64",
                                                                                :type "integer"},
                                                                        :type "array",
                                                                        :x-nullable true}}
                                                              {:description "",
                                                               :format "int64",
                                                               :in "path",
                                                               :name :z,
                                                               :required true,
                                                               :schema nil,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {:total {:format "int64",
                                                                                                :type "integer"}},
                                                                           :required [:total],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus with body"},
                                          :put {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                                                            :x-anyOf [{:type "string"}
                                                                                                      {:type "string"}]},
                                                              :reitit.swagger-test/req-val {:type "object",
                                                                                            :x-anyOf [{:type "object"}
                                                                                                      {:type "string"}]},
                                                              :reitit.swagger-test/resp-map {:type "object"},
                                                              :reitit.swagger-test/resp-string {:minLength 1,
                                                                                                :type "string"}},
                                                :parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required true,
                                                              :schema {:additionalProperties {:$ref "#/definitions/reitit.swagger-test~1req-val"},
                                                                       :type "object"}}],
                                                :responses {200 {:description "",
                                                                 :schema {:$ref "#/definitions/reitit.swagger-test~1resp-map",
                                                                          :x-anyOf [{:$ref "#/definitions/reitit.swagger-test~1resp-map"}
                                                                                    {:$ref "#/definitions/reitit.swagger-test~1resp-string"}]}},
                                                            500 {:description "fail"}},
                                                :summary "plus put with definitions"}},
                   "/api/schema/plus/{z}" {:get {:parameters [{:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "x",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "query",
                                                               :name "y",
                                                               :required true,
                                                               :type "integer"}
                                                              {:description "",
                                                               :format "int32",
                                                               :in "path",
                                                               :name "z",
                                                               :required true,
                                                               :type "integer"}],
                                                 :responses {200 {:description "",
                                                                  :schema {:additionalProperties false,
                                                                           :properties {"total" {:format "int32",
                                                                                                 :type "integer"}},
                                                                           :required ["total"],
                                                                           :type "object"}},
                                                             400 {:description "kosh",
                                                                  :schema {:type "string"}},
                                                             500 {:description "fail"}},
                                                 :summary "plus"},
                                           :post {:parameters [{:description "",
                                                                :in "body",
                                                                :name "body",
                                                                :required false,
                                                                :schema {:items {:format "int32",
                                                                                 :type "integer"},
                                                                         :type "array",
                                                                         :x-nullable true}}
                                                               {:description "",
                                                                :format "int32",
                                                                :in "path",
                                                                :name "z",
                                                                :required true,
                                                                :type "integer"}],
                                                  :responses {200 {:description "",
                                                                   :schema {:additionalProperties false,
                                                                            :properties {"total" {:format "int32",
                                                                                                  :type "integer"}},
                                                                            :required ["total"],
                                                                            :type "object"}},
                                                              400 {:description "kosh",
                                                                   :schema {:type "string"}},
                                                              500 {:description "fail"}},
                                                  :summary "plus with body"}},
                   "/api/spec/plus/{z}" {:get {:operationId "GetPlus",
                                               :parameters [{:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "x",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "query",
                                                             :name "y",
                                                             :required true,
                                                             :type "integer"}
                                                            {:description "",
                                                             :format "int64",
                                                             :in "path",
                                                             :name "z",
                                                             :required true,
                                                             :type "integer"}],
                                               :responses {200 {:description "",
                                                                :schema {:properties {"total" {:format "int64",
                                                                                               :type "integer"}},
                                                                         :required ["total"],
                                                                         :type "object"}},
                                                           400 {:description "kosh",
                                                                :schema {:type "string"}},
                                                           500 {:description "fail"}},
                                               :summary "plus"},
                                         :options {:parameters [],
                                                   :responses {200 {:description "200"}},
                                                   :summary "options"},
                                         :patch {:operationId "Patch",
                                                 :parameters [],
                                                 :responses {:default {:description ""}},
                                                 :summary "patch"},
                                         :post {:parameters [{:description "",
                                                              :in "body",
                                                              :name "body",
                                                              :required false,
                                                              :schema {:items {:format "int64",
                                                                               :type "integer"},
                                                                       :type "array",
                                                                       :x-nullable true}}
                                                             {:description "",
                                                              :format "int64",
                                                              :in "path",
                                                              :name "z",
                                                              :required true,
                                                              :type "integer"}],
                                                :responses {200 {:description "",
                                                                 :schema {:properties {"total" {:format "int64",
                                                                                                :type "integer"}},
                                                                          :required ["total"],
                                                                          :type "object"}},
                                                            400 {:description "kosh",
                                                                 :schema {:type "string"}},
                                                            500 {:description "fail"}},
                                                :summary "plus with body"}}},
           :swagger "2.0",
           :x-id #{:reitit.swagger-test/math}}
    diff: + {:paths {"/api/malli/plus/{z}" {:get {:definitions nil,
                                                  :parameters [{:schema nil}
                                                               {:schema nil}
                                                               {:schema nil}]},
                                            :post {:definitions nil,
                                                   :parameters [nil
                                                                {:schema nil}]},
                                            :put {:definitions {:reitit.swagger-test/req-key {:type "string",
                                                                                              :x-anyOf [{:type "string"}
                                                                                                        {:type "string"}]},
                                                                :reitit.swagger-test/req-val {:type "object",
                                                                                              :x-anyOf [{:type "object"}
                                                                                                        {:type "string"}]},
                                                                :reitit.swagger-test/resp-map {:type "object"},
                                                                :reitit.swagger-test/resp-string {:minLength 1,
                                                                                                  :type "string"}}}}}}

FAIL in reitit.swagger-test/multipart-test (swagger_test.clj:499)
#'reitit.coercion.malli/coercion
expected: [{:description "",
            :in "formData",
            :name "file",
            :required true,
            :type "file"}
           {:description "",
            :in "formData",
            :name "more",
            :required true,
            :type "string"}]
  actual: [{:description "",
            :in "formData",
            :name "file",
            :required true,
            :schema nil,
            :type "file"}
           {:description "",
            :in "formData",
            :name "more",
            :required true,
            :schema nil,
            :type "string"}]
    diff: + [{:schema nil} {:schema nil}]

Ran 109 tests in 22.809 seconds
14088 assertions, 3 failures, 0 errors.

@opqdonut
Copy link
Member

opqdonut commented Jun 1, 2023

FYI I'm going on a long vacation, but I hope @ikitommi will pick up reviewing this.

@hti-andre
Copy link

Hi, any news on this pull request being merged to reitit/master?

Is there something I can do to assist?

1 similar comment
@hti-andre
Copy link

Hi, any news on this pull request being merged to reitit/master?

Is there something I can do to assist?

@opqdonut
Copy link
Member

opqdonut commented Aug 8, 2023

This PR is still waiting for someone to fix the test failures (see my long comment above). I've been assuming @cap10morgan will do it, but if they're stuck, I can also have a look at some point.

@cap10morgan
Copy link
Contributor Author

Yeah I wasn't sure what else to try here short of just using tools.deps everywhere to integrate the local library modifications. It seemed like it was using the locally-installed libs but then exhibiting the pre-modification behavior.

@opqdonut
Copy link
Member

This conflicts with Tommi's #628. I'll rework this PR and get it in.

@opqdonut
Copy link
Member

My pr #642 replaces this. No need to close this one, github will mark this as merged once #642 goes in.

@opqdonut opqdonut merged commit f1d2679 into metosin:master Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Malli -> Swagger transformation fails with custom registries
4 participants