6
votes

Is it possible with ServiceStack.Api.Swagger v3.9.33 to describe the response of an API operation and the returned status codes using Swagger? Perhaps by attribute decoration on the Response class/properties, etc.

Like the highlighted sections for the following example operation from the pet store API: (http://petstore.swagger.wordnik.com/)

enter image description here

I can only see the HTTP methods and Request DTOS can be decorated on https://github.com/ServiceStack/ServiceStack/wiki/Swagger-API and quick glance at code looks like may not yet be supported, https://github.com/ServiceStack/ServiceStack/tree/master/src/ServiceStack.Api.Swagger

3

3 Answers

3
votes

As of now, it's possible if you pull the head of the ServiceStack repo. I just got a pull request merged that adds the option to decorate your request DTOs with an [ApiResponse] attribute. See here for details:

https://github.com/ServiceStack/ServiceStack/issues/590#issuecomment-17575292

2
votes

Try to make your Request (where you have applied the RouteAttribute) to implement ServiceStack.ServiceHost.IReturn<TResponseType> where TResponseType is your response type.

So the example should look something like:

[Route("/todos")]
[Route("/todos/{Ids}")]
public class Todos : IReturn<List<Todo>>

IReturn<List<Todo>> is what you are looking for

1
votes

I'm currently searching for a solution to the same problem.

I've come to the finding, that it's currently not implemented --> see: https://github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Api.Swagger/SwaggerApiService.cs for proof

So, currently there is no integration of the response Models or Status Codes.