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, https://github.com/kongchen/swagger-maven-plugin/issues/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.
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
@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.
@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.
@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.
Most helpful comment
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