I’m trying to build a Pyramid equivalent to flask-apispec. I’d like to attach a schema to a view (marshmallow is the schema library I’m using) to validate the return value of the view and marshal it into something more readily JSON serializable.
My first thought was to use a view deriver, but calling the view outputs a fully-formed Response object, so that’s a no-go.
I looked at using a view mapper, but I’m not sure I want to mess with Pyramid’s default mapper.
I tried utilizing the BeforeRender hook, but that doesn’t offer a way to replace the dictionary being passed into the renderer. I could hack it by emptying the dictionary and inserting the new keys.
I considered building a custom renderer, but I can’t figure how I’d pass the schema into it.
I could also just use a vanilla decorator, but that covers up the view call signature. Not the end of the world, so this is looking like the best option so far.
Any suggestions on the best way to achieve this?