Cody2333/koa-swagger-decorator

add response body example to responses

Opened this issue · 1 comments

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

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 })