servicestack,swagger,C#,Rest,servicestack,Swagger" /> servicestack,swagger,C#,Rest,servicestack,Swagger" />

C# 如何使用ServiceStack swagger api(1.2)在ServiceStack中记录服务响应

C# 如何使用ServiceStack swagger api(1.2)在ServiceStack中记录服务响应,c#,rest,servicestack,swagger,C#,Rest,servicestack,Swagger,我正在使用ServiceStack web服务的文档,它工作得非常好。但是,我没有找到一种方法来添加关于这些web服务(json)响应的任何信息。因此,当我的服务的GET方法如下所示: public object Get(CustomerData customers) { List<CustomerDAO> customers = DataProvider.GetAllCustomers(); return customers;

我正在使用ServiceStack web服务的文档,它工作得非常好。但是,我没有找到一种方法来添加关于这些web服务(json)响应的任何信息。因此,当我的服务的
GET
方法如下所示:

    public object Get(CustomerData customers)
    {
         List<CustomerDAO> customers = DataProvider.GetAllCustomers();
         return customers;
    }


 public class CustomerDAO
 {
     // this is important information which needs to be visible in swagger-ui
    public string Name { get; set; }
    public string SomeImportantProperty { get; set; }    
    public string AnotherPropery { get; set; }
    public string AlsoWorthDocumenting { get; set; }
    // and so on...
  }
public class CustomerData : IReturn<List<CustomerDAO>>
{
}
公共对象获取(CustomerData客户)
{
List customers=DataProvider.GetAllCustomers();
返回客户;
}
公共类客户道
{
//这是需要在swagger ui中可见的重要信息
公共字符串名称{get;set;}
公共字符串SomeImportantProperty{get;set;}
公共字符串另一个属性{get;set;}
公共字符串也值得记录{get;set;}
//等等。。。
}
我需要对文档(swagger ui)中的每个属性进行简短描述,这对于使用这些web服务是必不可少的

我正在使用ServiceStack 3.9.74,但这也应适用于最新的ServiceStack版本。如果没有,请告诉我


我想知道如何才能大摇大摆地获得这些信息,或者如果没有,如何向那些必须使用我的web服务的开发人员提供如此重要的信息。我也愿意接受在ServiceStack环境下工作的任何其他方法或最佳实践。

我不确定您的ServiceStack版本。在最新版本中,您的请求dto将被放入IRT
IReturn
,这将告诉swagger查看该返回类

因此,您的CustomerData类将如下所示:

    public object Get(CustomerData customers)
    {
         List<CustomerDAO> customers = DataProvider.GetAllCustomers();
         return customers;
    }


 public class CustomerDAO
 {
     // this is important information which needs to be visible in swagger-ui
    public string Name { get; set; }
    public string SomeImportantProperty { get; set; }    
    public string AnotherPropery { get; set; }
    public string AlsoWorthDocumenting { get; set; }
    // and so on...
  }
public class CustomerData : IReturn<List<CustomerDAO>>
{
}
公共类客户数据:IReturn
{
}

尽管为您的响应设置另一个dto可能会更好,它将被返回。也许像
CustomerDataResponse

@stout01这样的回答是正确的,也强烈建议您遵循以下建议,始终为您的服务创建专用的响应对象。更好的是,尽量不要公开您的ORM(OrmLite?)使用的类型,因为它在您的数据访问和您的API之间创建了一个紧密耦合,而您的API现在已公开给您的API客户机。这使得您很难在不破坏API合同和客户机的情况下更改数据库模型。还应该创建另一个表示
客户的类型。不幸的是,这在1.2中不起作用。我还将
ApiMember
属性添加到响应的属性中,但斯威格没有选择它。我想这个特性不是1.2的一部分。