Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

class annotation @responsesAll has conflict with @responses #95

Closed
raphaelsoul opened this issue Jul 28, 2020 · 0 comments
Closed

class annotation @responsesAll has conflict with @responses #95

raphaelsoul opened this issue Jul 28, 2020 · 0 comments
Milestone

Comments

@raphaelsoul
Copy link

raphaelsoul commented Jul 28, 2020

koa-swagger-decorator=1.6.8
koa=2.5.1

reproduce:

@tagsAll(["授权"])
@responsesAll({
    400: { description: "参数校验失败" },
})
export default class AuthController {
    @summary("登录授权")
    @description("登录授权")
    @body((LoginParameters as any).swaggerDocument)
    @request("post", "/api/auth/local")
    @responses({
        // ...commonResponses,
        200: { description: "授权成功" },
    })
    public static async login(ctx) {
        const data = ctx.validatedBody;
        ctx.body = await AuthenticateService.authenticate(data);
    }
}

this creates only status code 400 in generated swagger ui but expecting both 400 and 200 responses

workaround:

const commonResponses = {
    400: { description: "参数校验失败" },
};

@tagsAll(["授权"])
export default class AuthController {
    @summary("登录授权")
    @description("登录授权")
    @body((LoginParameters as any).swaggerDocument)
    @request("post", "/api/auth/local")
    @responses({
        ...commonResponses,
        200: { description: "授权成功" },
    })
    public static async login(ctx) {
        const data = ctx.validatedBody;
        ctx.body = await AuthenticateService.authenticate(data);
    }
}

Hope this can be resolved in @next milestone #91

@Cody2333 Cody2333 added this to the @next milestone Jul 29, 2020
iamcc added a commit to iamcc/koa-swagger-decorator that referenced this issue Oct 13, 2021
Cody2333 added a commit that referenced this issue Oct 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants