[swagger ui] how to specify specific response content in case of error ?

4,276 views
Skip to first unread message

Damien Grandemange

unread,
Jun 23, 2014, 7:22:35 AM6/23/14
to swagger-sw...@googlegroups.com
Hi,

First of all, for my first post, hello to everyone, and thank you for your great work on Swagger.
I work with Java 1.7, Swagger 1.3.2 (spec 1.2), and spring mvc rest controllers.

Ok, now my question :

Let's say i have some some method that returns a response (a ProcessedCount.class) when everything is OK.
In case of an error, i not only want to specify i change the HTTP status to some v4xx or 5xx, but also that i hcange the type of the returned content (say for instance, a OpenApiError.class wrapping an error code, a message and a description).

As i work with Java, and Swagger (spec 1.2), and spring mvc, i've tried to set these annotations :

    @ApiOperation(value = "add a list of MSISDN", notes = "TODO", response = ProcessedCount.class)
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "Successfully added"),
            @ApiResponse(code = 416, message = "List is empty", response = OpenApiError.class) })
    public ProcessedCount addMsisdn(@ApiParam(value = "list of ...", required = true) @RequestBody List<String> values) {

        // ...

        return new ProcessedCount(add);
    }

I have also a Spring exception handler method that returns a ErrorDetail instance. Anyway ...

Question is : in swagger UI, here below is what i can see about my api responses

Error Status Codes

HTTP Status Code Reason
200 MSISDN successfully added
416 Posted MSISDN list is empty

Thing is, i would really appreciate if swagger ui also indicates that, in case of a 416 status response, response body model will be a OpenApiError. Asfar as i can see, i don't see this information here.

Ron

unread,
Jun 23, 2014, 7:34:48 AM6/23/14
to swagger-sw...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Damien Grandemange

unread,
Jun 23, 2014, 8:35:20 AM6/23/14
to swagger-sw...@googlegroups.com
My maven dependency indeed points to swagger-ui 2.0.12. Have switched to 2.0.17, and response model now clearly shows up. Fantastic, thank you !
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggersocket+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages