compojure-api icon indicating copy to clipboard operation
compojure-api copied to clipboard

Handle Schema default values (was: How to compose parameters)

Open t-jones opened this issue 8 years ago • 8 comments

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.

t-jones avatar Nov 16 '15 22:11 t-jones

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.

Deraen avatar Nov 16 '15 22:11 Deraen

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.

t-jones avatar Nov 17 '15 05:11 t-jones

Ok, answered this myself; you can attach metadata with describe; not sure about defaults. But this gets me about 80% there!

t-jones avatar Nov 17 '15 06:11 t-jones

@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 avatar Nov 19 '15 23:11 t-jones

@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.

Deraen avatar Nov 20 '15 08:11 Deraen

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.

ikitommi avatar Nov 20 '15 09:11 ikitommi

related: https://github.com/metosin/schema-tools/issues/25.

ikitommi avatar Nov 22 '15 16:11 ikitommi

Possibly related: https://github.com/metosin/ring-swagger/issues/138

miikka avatar Nov 02 '19 16:11 miikka