reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
Ykä 2021-02-05T12:34:38.080800Z

Moro again: is there a way to add custom matchers for Reitit Schema coercion like there is for ring swagger: https://github.com/metosin/ring-swagger#custom-coercions ? I found the current coercions in https://github.com/metosin/schema-tools/blob/master/src/schema_tools/coerce.cljc, but could not figure out a clean way to add more. More specifically, we’d like to corce date strings to OffsetDateTime instances.

juhoteperi 2021-02-05T12:51:37.081500Z

@yka depends on which schema lib you are using. For Plumatic: https://github.com/metosin/reitit/blob/0.3.10/modules/reitit-schema/src/reitit/coercion/schema.cljc#L39

Ykä 2021-02-05T12:53:45.081700Z

Yeah. We are using Prismatic schema. So is the idea to override the default-coercion-matcher with an own implementation?

juhoteperi 2021-02-05T12:54:49.081900Z

Yeah. IIRC it's a map of type => coercion fn, so you'd probably merge your coercers to the existing

juhoteperi 2021-02-05T12:57:07.082100Z

Aha, Malli has maps. Schema-tools has these functions: https://github.com/metosin/schema-tools/blob/master/src/schema_tools/coerce.cljc#L284-L287

juhoteperi 2021-02-05T12:57:23.082400Z

so you could merge your own impl by using some-fn with existing matcher and your own

Ykä 2021-02-05T13:00:58.082600Z

Ok. In my case we’d need the matcher for json requests, so I guess I’d need to build on that json-coercion-matcher and add my own implementation on top of that with some-fn? I’ll try that approach. Thanks!

wombawomba 2021-02-05T23:47:16.085600Z

So I'm using Reitit and Ring, and I have an endpoint where I need to close a resource when the response has been fully sent (I'm returning an input-stream that's being read from a database, and I need to close the associated transaction). How can I do this?