Hello, i have a problem with Compojure-Api it seems that is not generating valid Swagger 2 specs. Why compojure-api generate oneOf tags when is not in the spec of swagger 2?
What is the spec for a formData parameter name. I want to use foo/bar
, but the UI truncates it to bar
only when I use :foo/bar
in the Schema spec
Using a string instead of a keyword works
I might be using stuff wrongly, but I get an assertion-error when using spec-coercions with compojure-api.
The offending function is
(defn nested-key [n k]
#_ (assert (qualified-keyword? n) (str "spec must have a qualified name" n))
(keyword (str (namespace n) "$" (name n)
(if-let [kns (namespace k)]
(str "$" kns)) "/" (name k))))
in 'spec-tools.data-spec)
The offending line (which is commented out over) was added in https://github.com/metosin/spec-tools/commit/1a8dd077c254563367be5ec2ca9b40a561b59421#diff-a7972339bb0aba07594a0747da1a3c12
If there is any interest, I can dig deeper and try to figure out a minimal example to reproduce this.
Oh, and a bonus question:
I'm working on the backend-team, using spec, so we're quite happy writing out specs and maps with lisp-case
keys, as
{:foo-bar-baz "qix"}
Now, our frontend team are not too fond of lisp-case
, so before sending this off to the frontend, we camelCase
it, as such
{:fooBarBaz "qix"}
So when using compojure-api with spec-coercion, the swagger docs say that we're returning {"foo-bar-baz": "qix}
, when in reality we return {"fooBarBaz" : "qix"}
.
Any thoughts on how to make the swagger docs reflect our reality?
the first one, I’m 99% sure that the SpecCoercion uses gensym
to generate names for the anonymous specs, and after the change, keyword is required.
something like:
(defn- ensure-name [?name]
(or ?name (keyword "" (name (gensym "spec")))))
should help.the second, I don’t think there is easy way. But you can do it by modifying the response from the swagger-docs endpoint… if you remove the swagger definitions from the api
and mound swagger-docs
manually, you can wrap the docs with a custom middleware that transforms the models with walk
etc.
Re the second, I was thinking that it would be a possibility to do the walk thingy.