Cody2333 / koa-swagger-decorator

using decorator to automatically generate swagger doc for koa-router
348 stars 81 forks source link

add response body example to responses #153

Open GalTidhar-Deliverr opened 2 years ago

GalTidhar-Deliverr commented 2 years ago

is there a way to define the response body? it's not apart of the interface

GalTidhar-Deliverr commented 2 years ago

found a solution, not pretty but no code duplication is needed , should be either a feature or a part of the documentation the documentation shows how to setup a scheme for the incoming body in the following way @body((UserInfo as any).swaggerDocument this does not work for responses, in order to return the same scheme in the response a it needs to be wrapped, i assume it's a bug and another .swaggerDocument named .swaggerResponseDocument should be created i've created the following utility to encapsulate the 'hack' `const buildResponseSchema = (responseSchema: any) => { return { type: 'object', properties: responseSchema.swaggerDocument }; };

export default { buildResponseSchema, };`

and now using it in the response decorator and it works as expected (minus the scheme name, but it's minor) @responses({ 200: SwaggerResponseUtil.buildResponseSchema(UserInfo), 500: newVar })