trailsjs / sails-swagger

Swagger integration for sails.js
107 stars 47 forks source link

Way to customize json output #28

Open sylwit opened 8 years ago

sylwit commented 8 years ago

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

joseasrocha commented 8 years ago

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.

praveen4554 commented 7 years ago

How to add authentication

Alino commented 6 years ago

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