yada icon indicating copy to clipboard operation
yada copied to clipboard

Response schemas

Open kendru opened this issue 8 years ago • 3 comments

Is there any support or planned support for response schemas, similar to the current support for request parameter schemas?

This would be helpful in swagger generation, and it would also allow for the trivial creation of interceptors that could, for example, coerce the response body to the given schema.

kendru avatar Jun 21 '17 16:06 kendru

I've been looking for the same but for reasons that have more to do with security than swagger; I'd like to use response schemas to ensure that all responses adhere to my own specification as a way to guard against unintentional data leaks.

I naively tried just adding another key to my resource with the intention of using an interceptor (set up by a wrapper for yada.yada/resource) to validate the output schema, but that conflicts with yada.schema/resource-coercer. I'm not sure what the easiest way would be to avoid this, but there are other ways...

I've implemented it as a wrapper on yada.yada/resource. Before passing it to resource it walks the resource model and looks for any :schema keys under HTTP methods. If found it replaces the :response fn with a wrapper that takes the schema and it then dissocs the schema to avoid conflicts with the resource coercer.

runejuhl avatar Jul 03 '17 20:07 runejuhl

@runejuhl I have done something similar in my application, but it would be great to see support for this baked in.

kendru avatar Jul 03 '17 20:07 kendru

Agreed. Adding it to the swagger output would be really nice as well.

runejuhl avatar Jul 03 '17 21:07 runejuhl