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

Support of multiple @ApiResponse with the same HTTP code #3379

Closed
Garamda opened this issue Dec 9, 2019 · 4 comments
Closed

Support of multiple @ApiResponse with the same HTTP code #3379

Garamda opened this issue Dec 9, 2019 · 4 comments

Comments

@Garamda
Copy link

Garamda commented Dec 9, 2019

I want to make API spec doc which can have multiple @ApiResponse with the same HTTP code, like below.

    @ApiOperation(value = "Process request for login by user", response = Iterable.class)
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Login success"),
            @ApiResponse(code = 400, message = "Login fail by wrong ID"),
            @ApiResponse(code = 400, message = "Login fail by wrong password"),
            @ApiResponse(code = 400, message = "Login fail by withdrawn ID")
    })

This would be useful as many users want (you can check here, kongchen/swagger-maven-plugin#199)

If this feature becomes available in swagger-core, it would be applied to any plugins.

If it seems that it does not many sense, please give a comment.
I appreciate it in advance.

@seshidharg
Copy link

In you case @ApiResponse(code = 400, message = "Login fail by wrong ID"),
@ApiResponse(code = 400, message = "Login fail by wrong password"),
@ApiResponse(code = 400, message = "Login fail by withdrawn ID")
this messages will override and you can only see one message for response code 400
you can modify like

@ApiOperation(value = "Process request for login by user", response = Iterable.class)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Login success"),
@ApiResponse(code = 400, message = "Login fail by wrong ID \t\n Login fail by wrong password \t\n Login fail by withdrawn ID"),
})

This will display all the three messages under 400

@Garamda
Copy link
Author

Garamda commented Dec 16, 2019

@pavan-eidiko If it is impossible to adapt the modification, the duplicated usage of @ApiResponse which I suggest, then your recommendation would be the best. I appreciate it! I will follow your suggestion right away.

However, I will not close this issue on my own. I still want to check the modification does make sense to the contributers. I will still make it open so I can hear any news in the future.

@webron
Copy link
Contributor

webron commented Dec 16, 2019

@Garamda I'm afraid the OpenAPI specification does not allow you to specify the same HTTP Code multiple times with different messages. You can technically support different response types for a single code, but not multiple descriptions. This is a spec restriction and there's no real way for us to overcome it. I think that if we appended the strings ourselves, it would end up giving a surprising result to the users, making them think there's a bug here.

@Garamda
Copy link
Author

Garamda commented Dec 18, 2019

@webron Now I fully understand. I didn't know that Swagger is based on OpenAPI spec. I appreciate your kind explanation.

Since the member of Swagger project fully explained why the suggestion can't be accepted, I'll close this issue. I appreciate it again.

@Garamda Garamda closed this as completed Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants