简体   繁体   中英

How to specify Response class and return Status Codes using Swagger/ServiceStack

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/ )

在此输入图像描述

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

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

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM