Fork me on GitHub
#reitit
<
2022-09-27
>
DrLjótsson07:09:26

What is the best way to write a malli spec for an empty 200 response in :responses, like for successful authentication? {200 {:body any?}}seems to work but I suppose there is a better way?

valtteri15:09:35

If I recall, Ring uses empty string "" as empty response. So you could check that the response body value equals to "" if that makes sense.

valtteri15:09:12

Or maybe it makes more sense to send an explicit HTTP204 “No Content” response in this case.

valtteri15:09:49

Dunno how much value the validation actually brings here. Unless you’re generating swagger from the routes & schemas.

DrLjótsson15:09:28

Thanks! I considered using 204 but I think it may break my tests. I'm generating Swagger!

valtteri16:09:20

Hmm swagger docs encourage to leave the content key undefined if empty response is expected https://swagger.io/docs/specification/describing-responses/

valtteri16:09:45

Perhaps if you don’t have any schema for the body it will be just fine for Swagger? 🙂

DrLjótsson16:09:42

I'll try that out!

👍 1
valtteri16:09:10

Please let me know if that works as expected. 🙂 Just throwing things from the top of my mind, didn’t test

👍 1
DrLjótsson17:09:04

:responses {200 {}} works fine with swagger!

💪 1
DrLjótsson17:09:23

Is it possible to provide a`:description` for tags as specified in the Swagger docs in reitit? https://swagger.io/docs/specification/grouping-operations-with-tags/ "Optionally, you can specify description and externalDocs for each tag by using the global tags section on the root level. The tag names here should match those used in operations."

valtteri18:09:10

Here’s an example how you can define / override what goes to the swagger spec https://github.com/metosin/reitit/blob/master/examples/ring-malli-swagger/src/example/server.clj#L25-L29

🙏 1
DrLjótsson19:09:11

Thanks! I guess that it's not possible to add this "downstream" in the route data? My routes are collected from different namespaces and it would be great if tags could be described locally in each ns rather than at the top level.

valtteri18:09:27

I think you can place :swagger {:tags ...} under any routes and reitit will collect & merge them. (again from the top of my head and didn’t try)