Fork me on GitHub
#yada
<
2018-03-05
>
mmer16:03:33

Is there a way to generate a ya da server from a swagger definition?

jholkeboer19:03:20

How to i tell yada which http status code to return, depending on the request content? Or depending on what error is caught?

jholkeboer19:03:02

i tried "declaring" a 400 in my handler, and returning {400 "message}, but it just returned a 200 with {400 "message"} as the body

danielcompton21:03:38

@jholkeboer there's different ways depending on how much control you need

danielcompton21:03:13

If you follow the happy path of yada, then you never need to explicitly set status codes as it will do it all for you, based on it's understanding of the HTTP spec

danielcompton21:03:31

e.g. if a form request doesn't pass the Schema then it will return a 400 without you having to do anything

danielcompton21:03:19

I had to read this a few times to really get it, I would like to make a PR to explain it better

danielcompton21:03:13

There are three ways to return a response, explicit responses, declared responses, and status responses

danielcompton21:03:45

Explicit responses let you return the full response from the context (assoc (:response ctx) :status 418) along with any response you would like

danielcompton21:03:45

A status response is used for overriding Yada's default responses for a particular status code

danielcompton21:03:17

So if you would have got a 404 for a particular request, you can override the 404 response with your own response entry

danielcompton21:03:48

There is a difference between 10.2 Declared responses and 10.3 Status responses, but I can't remember what they are

danielcompton21:03:38

For you, you probably want to use Schema validation if you can validate the request being bad up front