compojure-api
compojure-api copied to clipboard
Handle Schema default values (was: How to compose parameters)
I have a set of services with a common set of query parameters. What's the best way to reuse/compose their definition across a set of services? I've been playing with the GET* and friends macro, learning about letk/plumbing, but can't see a way to make it happen at this level of the stack. Is it possible, and what am I missing?
It's entirely possible I'm thinking about this problem incorrectly, so open to feedback on that as well.
I don't think this is possible with letk/plumbing syntax.
You can use :query
to set the Schema using normal Schema: https://github.com/metosin/compojure-api/blob/master/src/compojure/api/meta.clj#L205. Though this doesn't solve destructuring.
Is it still possible to attach swagger meta-data via describe
on the schema element when using :query
? Also, how about default values? I saw a patch for this in Schema, but not sure how to go about it.
Ok, answered this myself; you can attach metadata with describe
; not sure about defaults. But this gets me about 80% there!
@Deraen any thoughts on handling default values? wrapping keys in s/optional-key
provides optional parameters, but it looks like defaults are provided solely by letk. Any chance you'll be using this soon?
https://github.com/Prismatic/plumbing/commit/961fa0d5478074eb1659bcf6644c4b778c7fad17
@t-jones Yes we are planning on using metadata set by plumbing letk. But anyway, that won't help in this case, the metadata is purely for documentation, the default value itself needs to still be handled by destructuring or some other way.
There is a partial solution for handling defaults with custom coercion matcher in the Plumbing google group. Idea is to finalize it and add it to our schema-tools, enabling schema defaults for wider audience. I'm on vacation, so feel free to implement wirh PR.
related: https://github.com/metosin/schema-tools/issues/25.
Possibly related: https://github.com/metosin/ring-swagger/issues/138