Fork me on GitHub
#ring-swagger
<
2018-02-19
>
logistark12:02:54

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?

borkdude14:02:28

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

borkdude14:02:29

Using a string instead of a keyword works

slipset21:02:48

I might be using stuff wrongly, but I get an assertion-error when using spec-coercions with compojure-api.

slipset21:02:55

The offending function is

slipset21:02:58

(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))))

slipset21:02:20

in 'spec-tools.data-spec)

slipset21:02:04

If there is any interest, I can dig deeper and try to figure out a minimal example to reproduce this.

slipset21:02:54

Oh, and a bonus question:

slipset21:02:33

I'm working on the backend-team, using spec, so we're quite happy writing out specs and maps with lisp-case keys, as

slipset21:02:46

{:foo-bar-baz "qix"}

slipset21:02:57

Now, our frontend team are not too fond of lisp-case, so before sending this off to the frontend, we camelCase it, as such

slipset21:02:09

{:fooBarBaz "qix"}

slipset21:02:24

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"}.

slipset21:02:46

Any thoughts on how to make the swagger docs reflect our reality?

ikitommi21:02:00

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.

ikitommi21:02:22

something like:

(defn- ensure-name [?name]
   (or ?name (keyword "" (name (gensym "spec")))))
should help.

ikitommi21:02:44

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.

slipset21:02:16

Re the second, I was thinking that it would be a possibility to do the walk thingy.