简体   繁体   English

如何使用Swagger / ServiceStack指定Response类并返回状态代码

[英]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 ? ServiceStack.Api.Swagger v3.9.33是否可以使用Swagger描述API操作的响应和返回的状态代码? 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/ ) 与宠物商店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 我只能看到HTTP方法和请求DTOS可以在https://github.com/ServiceStack/ServiceStack/wiki/Swagger-API上进行修饰,快速浏览代码看起来可能还不支持, https:// github。 COM / ServiceStack / ServiceStack /树/主/ src目录/ ServiceStack.Api.Swagger

As of now, it's possible if you pull the head of the ServiceStack repo. 截至目前,如果你拉开ServiceStack仓库的头部,它是可能的。 I just got a pull request merged that adds the option to decorate your request DTOs with an [ApiResponse] attribute. 我刚刚获得了一个合并的pull请求,它添加了用[ApiResponse]属性来装饰您的请求DTO的选项。 See here for details: 详情请见此处:

https://github.com/ServiceStack/ServiceStack/issues/590#issuecomment-17575292 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. 尝试使您的请求(您已应用RouteAttribute的地方)实现ServiceStack.ServiceHost.IReturn<TResponseType> ,其中TResponseType是您的响应类型。

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 IReturn<List<Todo>>正是您要找的

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 我已经得出结论,它目前尚未实现 - >请参阅: https//github.com/ServiceStack/ServiceStack/blob/master/src/ServiceStack.Api.Swagger/SwaggerApiService.cs进行证明

So, currently there is no integration of the response Models or Status Codes. 因此,目前没有响应模型或状态代码的集成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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