Fork me on GitHub
#ring-swagger
<
2018-06-14
>
puneet12:06:05

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"]]]

ikitommi13:06:09

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

puneet13:06:09

nope

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

puneet13:06:23

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.

ikitommi13:06:21

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 []}]})

puneet13:06:59

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

puneet13:06:38

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.

ikitommi14:06:39

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

sammikko16:06:57

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

ikitommi17:06:51

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

sammikko17:06:38

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

ikitommi17:06:59

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

sammikko17:06:35

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

ikitommi17:06:29

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

nickmbailey20:06:48

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

nickmbailey20:06:49

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

nickmbailey20:06:34

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

nickmbailey20:06:35

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

ikitommi21:06:59

@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

ikitommi21:06:39

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

nickmbailey22:06:44

awesome, good to know 🙂

nickmbailey22:06:48

and hint noticed haha

nickmbailey22:06:59

i haven’t had time to dive into spec yet