Fork me on GitHub
#ring-swagger
<
2017-12-28
>
ikitommi08:12:40

hi @wontheone1, back from the holidays, good that you have mostly resolved all the issues. Does it work if you just use empty map as the response schema? eg. {http-status/created {}

ikitommi08:12:38

and you can use s/Any as the Schema, for “anything”. Not exactly what you want, but works.

ikitommi08:12:49

the :compojure.api.meta/serializable? true is internal stuff, marking that the response should be encoded (to support encoding of primitives). I think the encoder should remove it as it’s not useful info outside of c-api. But, you can ignore it.

ikitommi14:12:17

… and meant {http-status/created {:schema s/Any}}

wontheone114:12:28

@ikitommi Thanks s/Any or {} works ! I am confused, I could swear I tried the empty map and it didn't work yesterday but it's working now

wontheone114:12:40

I proly did something wrong yesterday elsewhere

wontheone114:12:46

I think for the new users, this kind of cases might be not so obvious, so some examples might help... If you agree I might submit PR for some examples or README improvement

wontheone115:12:02

@ikitommi I can easily find out how to generate swagger.json, and expose it with compojure-api but found nothing about it from https://github.com/metosin/ring-swagger. Is similar thing supported? (I mean if you have Swagger definition in clojure map then of course you can generate json/yaml with some library and write using io and stuff but I just assumed this is common case and ring-swagger might as well do all the chores for us)

ikitommi15:12:50

Just expose the result of ring.swagger.swagger2/swagger2 function. If you need JSON String, run cheshire.core/generate-string to it.

wontheone115:12:25

@ikitommi you mean the swagger-json function? result is plain clojure map I think. So putting that in JSON and exposing it as Swagger UI is the work of library user? I got it thanks

wontheone115:12:37

I just thought (similar to compojure-api) there would be automagical way to exposing it to Swagger UI. but nevermind

wontheone115:12:39

I have a few points about compojure-api library, please consider when you have time. I see there is get-spec function used in tests. https://github.com/metosin/compojure-api/blob/4b5e2f8e59ddb915f70b5e75f70a25ea20f142b0/test/compojure/api/sweet_test.clj#L104 I think we can include this function as one of core library function so that compojure-api user can also easily test the validity of their definitions as in https://github.com/metosin/compojure-api/blob/4b5e2f8e59ddb915f70b5e75f70a25ea20f142b0/test/compojure/api/sweet_test.clj#L211

wontheone115:12:55

Using existing function here, https://github.com/metosin/compojure-api/blob/4b5e2f8e59ddb915f70b5e75f70a25ea20f142b0/test/compojure/api/test_utils.clj#L131 to core library, might be enough. If you think this would help, I could try to submit a PR too.

wontheone115:12:49

@ikitommi no Thanks for pointing out !! after seeing test-util get-spec is used I thought there was no way 😄... Documentation could be improved on this one too

ikitommi15:12:20

doc PRs would be most welcome :)

ikitommi15:12:51

(a whole new static doc site would be super)

wontheone115:12:40

I will see what I can do thanks! sorry for spamming the chat, but last thing I want to ask. with value of :responses being a map, there is no duplication of key allowed. so If you want to have 2 (or more) different schemas for the same status code how do you solve it? of course s/Any or anything that accepts all schemas would work. But in the Swagger UI you cannot show them as different responses.

wontheone115:12:52

I don't know having different schema with same status code is really bad thing and I would avoid it when possible but just think there might be some cases that would need to do like that. if responses can have a vector as a value, then this will be solved easily. For example :responses [201 {:schema A] 201 {:schema B}]

wontheone115:12:51

Not urgent issue anyway as in most APIs, one status code will have one schema, but I wanted to discuss if you think this makes sense anyway @ikitommi

ikitommi18:12:17

Sadly, Swagger2 doesn’t support anyOf (see https://github.com/OAI/OpenAPI-Specification/issues/57), but you use something like s/cond-pre or use a abstract schema to desribe that in Clojure. The api-docs won’t show that, but if you send correct data over the wire, the Schema Validation approves it. c-api also supports clojure.spec where you can use something like s/or. OpenApi3 supports this, but haven’t had time to implement that. There are issues in ring-swagger, schema-tools & spec-tools if someone has time to implement those. And, all questions welcome 🙂

wontheone119:12:14

Aha ! sad history ! thanks for kind answers!

wontheone120:12:32

I made a PR to improve docs, please checkout when you have free time.