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 for adding additional models for request or response that are not inferred from operations #735
Comments
@cabbonizio Thats a use case that we haven't thought through completely :-o! thanks for reporting it. The good news is that there work around for this
|
Wow, you're right that works perfectly. Currently the only extra piece of code is just having to annotate one of my controller methods and the others can remain without it. This workaround is not that painful at all to be honest. I really like being able to globally use the globalResponseMessage() method I guess in the future it would be a nice to have to specify the model class within that method this way it's less configuration in the controller. In any event, this is working great, doesn't make things really messy in the end I like the results. Have a great weekend and I look forward to any enhancements to this area! |
Reopening so that it can be fixed :) |
Ah...... my bad @dilipkrish thanks for reopening. I will be glad to test this for you guys when something is ready. |
Fixed via f748a6b |
Hi, this is just a question about how to configure a the ModelRef object within the ResponseMessage object. Essentially, I would like to default the ResponseMessages globally within startup of Sprint Boot application such as HTTP 400, 404, and 500. I did figure out how to do this which is to use the
globalResponseMessage() method of the Docket object like such:
@bean
public Docket swaggerApi() {
return new Docket(DocumentationType.SWAGGER_2).select().paths(userOnlyEndpoints()).build()
.pathMapping("/rest/").globalResponseMessage(RequestMethod.GET, getDefaultResponseMessages()).apiInfo(apiInfo());
}
private List getDefaultResponseMessages() {
List defaultResponseMessages = Lists.newArrayList();
defaultResponseMessages.add(new ResponseMessage(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(), new ModelRef("")));
defaultResponseMessages.add(new ResponseMessage(HttpStatus.NOT_FOUND.value(), HttpStatus.NOT_FOUND.getReasonPhrase(), new ModelRef("")));
defaultResponseMessages.add(new ResponseMessage(HttpStatus.INTERNAL_SERVER_ERROR.value(), HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(), new ModelRef("")));
return defaultResponseMessages;
}
It is working defaulting each of the GET methods in my controller with those HTTP status codes, but I want to be able to specify an "error" response object which is different than the response if the return code was a 200. Where I'm getting hung up is how to configure ModelRef() to specify the error object (Error.class). I can actually do this within each controller method using Swaggers @ApiResponses({ @ApiResponse(code = 404, message = "Not Found", response=Error.class) }) but I would prefer to do this in my Spring Boot config class (Application.java) and just trying to determine how do this with the ResponseMessage object.
Any help would be appreciated thanks very much. This is by far one of the best and easiest ways to incorporate Swagger into a Spring (especially Boot) application. Our developers are all having fun using this.
Chris
The text was updated successfully, but these errors were encountered: