ring-swagger

ring-swagger & compojure-api
2018-06-14T12:55:05.000329Z

how can i write a recursive schema like:

(s/defschema TaskTemplateSubmission
  {:name        s/Str
   :description s/Str
   :children    [TaskTemplateSubmission]})
which is basically a tree. The error i get is:
ERROR error converting to swagger schema [:children [#object[clojure.lang.Var$Unbound 0x363d3f4b "Unbound: #'api.schema/TaskTemplateSubmission"]]]
java.lang.IllegalArgumentException: error converting to swagger schema [:children [#object[clojure.lang.Var$Unbound 0x363d3f4b "Unbound: #'api.schema/TaskTemplateSubmission"]]]

ikitommi 2018-06-14T13:18:09.000497Z

@er.puneetpahuja would :children [(s/recursive TaskTemplateSubmission)] work?

2018-06-14T13:21:09.000434Z

nope

Exception in thread "main" java.lang.RuntimeException: Not an IDeref: Unbound: #'api.schema/TaskTemplateSubmission, compiling:(schema.clj:304:18)

2018-06-14T13:35:23.000009Z

this was with [metosin/compojure-api "1.1.11"]. when i switched to "2.0.0-alpha20", only the UI breaks (https://imgur.com/a/cjuJksA) but there is no error on console.

ikitommi 2018-06-14T13:38:21.000788Z

Looking at the schema docs, here's the syntax:

;; recursive
(def Tree {:value s/Int :children [(s/recursive #'Tree)]})
(s/validate Tree {:value 0, :children [{:value 1, :children []}]})

2018-06-14T13:48:59.000769Z

Worked. Thanks a lot 🙂 Can you share the link of the docs.

ikitommi 2018-06-14T13:53:37.000371Z

https://github.com/plumatic/schema 😉

jdt 2018-06-14T13:56:33.000476Z

Sure thing, I'll put that on my to-do list as soon as I finish the 64 bit conversion to accommodate more items.

2018-06-14T13:57:38.000218Z

Thanks again 🙂 Saw something similar here : https://stackoverflow.com/questions/36866035/how-to-refer-to-enclosing-type-definition-recursively-in-yaml-swagger-io But i thought its a yaml specific thing.

jdt 2018-06-14T13:59:38.000060Z

More seriously, is there some simple fix you already know about that someone unfamiliar with the innards of compojure-api might submit a PR for? My point in asking is as much a question of whether I'm doing it wrong, or whether it's a known bug, at this point, using alpha compojure-api support on top of alpha-spec support. Most of our APIs use compojure-api+Plumatic schema, I've undertaken a new API as the guinnea pig for compjure-api+spec. It's ... rough ... comparatively speaking.

ikitommi 2018-06-14T14:59:39.000131Z

swagger doesn’t support those very well, but at least it doesn’t blow up.

sammikko 2018-06-14T16:45:57.000020Z

Are multipart-forms supported in ring-swagger? I have a multipart-form where I'm uploading the file along with some string parameters and looking to document this with Ring Swagger.. I found some example using compojure api, but I'm using ring-swagger directly

ikitommi 2018-06-14T17:01:51.000582Z

should be, just check the swagger data that compojure-api emits. I think it required setting :consumes. and https://github.com/metosin/ring-swagger/blob/master/src/ring/swagger/upload.clj has the schemas for different upload types

ikitommi 2018-06-14T17:02:29.000713Z

you can mix them with other (form-)parameters.

sammikko 2018-06-14T17:12:38.000522Z

this is some internal format of compojure-api, not swagger data yet?

ikitommi 2018-06-14T17:16:59.000138Z

code to generate the ring-swagger compatible definition, e.g. the :consumes & the parameter type.

sammikko 2018-06-14T17:32:35.000162Z

thanks! I had to add the :consumes and the parameters part was something like :parameters {:formData {:file upload/TempFileUpload}}

ikitommi 2018-06-14T17:57:20.000635Z

👍

2018-06-14T20:24:48.000260Z

so i have a lot of schema definitions that have example data added to them with ring.swagger.json-schema/describe. i’m now trying to use those schema definitions from clojurescript but it seems like describe isn’t clojurescript compatible

2018-06-14T20:26:49.000258Z

i’m pretty new to clojurescript but is there a reason that shouldn’t work? clojurescript seems to support attaching metadata

2018-06-14T20:28:34.000068Z

i guess the rest of that namespace is pretty jvm-centric so maybe it just hasn’t been worth to make all of that clojurescript friendly

2018-06-14T20:29:35.000566Z

i’m thinking i should just be able to implement my own wrapper for describe that does nothing for clojurescript and dispatches to the real describe for clojure

ikitommi 2018-06-14T21:55:59.000444Z

@nickmbailey we have been porting stuff from ring-swagger to both schema-tools and spec-tools - for both coercion & swagger2-transformation. It’s not complete, but grand goal is to have unified api for Schema/Spec and for Clojure/ClojureScript. With this, the describe will be replaced with something like https://github.com/metosin/schema-tools/issues/32 and https://github.com/metosin/spec-tools/issues/23

ikitommi 2018-06-14T21:58:39.000339Z

might not help you just now, but wanted you to know. there are lot of “help wanted” issues too… 😉

2018-06-14T22:58:44.000182Z

awesome, good to know 🙂

2018-06-14T22:58:48.000161Z

and hint noticed haha

2018-06-14T22:58:59.000268Z

i haven’t had time to dive into spec yet