sails-swagger icon indicating copy to clipboard operation
sails-swagger copied to clipboard

Way to customize json output

Open sylwit opened this issue 8 years ago • 3 comments

Hi guys

I'd like to know about how do you customize your output.

Let's say you want to return a 400 or 403, or if you want to return a custom model which is not persist in database or also how do you define query parameters ?

How do you deal with that and have you ever think about adding some more customization. If no, I'll be glad to help

Thank you

sylwit avatar Jul 02 '16 18:07 sylwit

You can build your custom route like this:

'POST /api/v2/products': { controller: 'products', action: 'create', swagger: { methods: ['POST'], summary: 'Create Products', description: 'Create Products ... bla bla bla', produces: [ 'application/json' ], tags: [ 'Products' ], responses: { '201': { description: 'Product created', schema: 'products' //model } }/*, parameters: [ 'products' ]*/ }

This works if you don't use the npm package because, at the moment, it's outdated and don't support this kind of spec on the route.

I've forked this repo to tweak the response code on a POST success. Instead of returning 200, my code returns 201 on a successful post request.

[https://github.com/Magikevolution/sails-swagger]

Hope this helps.

joseasrocha avatar Aug 13 '16 14:08 joseasrocha

How to add authentication

praveen4554 avatar Oct 11 '17 11:10 praveen4554

my fork supports adding custom definitions in the swagger config file.

Alino avatar Mar 21 '18 15:03 Alino