Fork me on GitHub
#ring-swagger
<
2016-08-03
>
ikitommi06:08:25

do you have an example of good API errors (in some lib/tech)?

jqmtor10:08:47

I think so, yes. I have a ruby background and one of the web frameworks I used most of the time was grape (https://github.com/ruby-grape/grape). they have a way to validate/coerce params (https://github.com/ruby-grape/grape#parameter-validation-and-coercion), relying both on a library called virtus (https://github.com/solnic/virtus) and on a set of their own validations.

jqmtor10:08:56

if I recall correctly, the messages coming from virtus were somewhat like the ones coming from schema. helpful and understandable, just not prepared for customer-facing use cases.

jqmtor10:08:18

I think they do the error formatting in a rack middleware (quite similar concept to a ring middleware)

jqmtor10:08:59

if compojure api exposed something like this, I imagine that would be an interesting strategy as well?

jqmtor11:08:47

there are more things there than the validation error messages, but I think you can get an idea by looking at the existing validations and looking for the corresponding error messages.

jqmtor11:08:05

maybe this is already too detailed, but showing the messages without giving some context seemed innapropriate

ikitommi12:08:55

so, you can pass any custom function to render the exception messages instead of the default one. If you come up with a better formatter than the custom, let’s pull it in.

jqmtor12:08:21

great! 🙂 I will take a look and I hope I can get back to you with a proposal.

donbonifacio15:08:40

I have a documented route, but I would not like it to validate the schema

donbonifacio15:08:46

can’t find an easy way to do it

ikitommi15:08:39

do you just have one route where you dont want validation? do you still want to destructure the parameters?

ikitommi15:08:00

setting :coercion nil disables the coercion. can be se to api, context or endpoints.

ikitommi15:08:50

BUT still the parameter destructuring is done, do if you ask for :query-params [x :- s/Int, y :- s/Int], the keys still have to be present.

ikitommi15:08:46

to do just documentation, you can use :swagger -destructuring, described here: https://github.com/metosin/compojure-api/wiki/Swagger-integration#non-documented-routes

donbonifacio15:08:10

when I add :coercion nil

donbonifacio15:08:13

I get an exception

donbonifacio15:08:31

I’ like to prevent schema validation for specific routs

donbonifacio15:08:44

but if I have to, we can disable it everywhere

donbonifacio15:08:03

because we already have a validation layer, we’re using compojure-api just for docs

ikitommi15:08:47

what version are you using?

ikitommi15:08:46

ok, the nil needs the latest. just added it ~last week 😉

donbonifacio15:08:48

yes, running ok! 🙂

donbonifacio15:08:11

I’ve seen an issue about spec

donbonifacio15:08:19

any news on that?

ikitommi15:08:32

you can follow that on the ring-swagger (https://github.com/metosin/ring-swagger/issues/95). Miikka just pushed a initial prototype. Looking forward to that. Still, spec doesn’t really support coercions in the way http apis need. Will poke Alex, if we could have that.

cberg18:08:30

Hi! Is there an example somewhere how to define an endpoint (PUT or POST) in compojure-api that accepts binary data? I would like to read directly from the :body stream of the ring request.

ikitommi18:08:25

you can use normal Compojure way to access the request:

(POST “/bin” request
  (dosomethingwith (:body request))

ikitommi18:08:36

For files, there is also the multipart-params handling, either via a temp file or a inputstream, sample here: https://github.com/metosin/compojure-api/blob/master/examples/thingie/src/examples/thingie.clj#L189-L193

cberg18:08:51

Thanks! I'm not sure yet if I want the multipart handling. If I go the first way you showed, how can I generate the right Swagger definition for this?

ikitommi18:08:18

what kind of definition should there be?

ikitommi18:08:12

a map-like schema of the body perhaps?

ikitommi18:08:30

or are you streaming files?

cberg18:08:53

I'm not sure. 🙂 Sorry, I'm still pretty new to Swagger and Schema. Is there a way in Swagger to say "accept any binary data".

ikitommi18:08:30

I don’t think there is.

ikitommi18:08:25

Swagger is originally made for statically typed languages & JSON-type apis.

cberg18:08:38

True. It's not a common case, I guess. I'll just use the standard Compojure way for now.

cberg18:08:50

Thanks for the help!

ikitommi19:08:57

glad to help