如何使用ServiceStack OpenApiFeatureSwagger与api描述和响应示例?

问题描述 投票:1回答:1

有没有办法在ServiceStack中使用OpenApiFeature为api添加描述(而不仅仅是单个路由)和更新api版本,并添加响应示例resquests?我在文档中找不到任何关于swagger ui这些部分的内容。

我试过使用Api属性来添加描述,但似乎不起作用。

servicestack swagger-ui openapi
1个回答
1
投票

唯一的 声明性属性,可对单个服务进行注释 在Open API docs上有详细的说明。这里有一个完全注释的例子。

[Tag("TheTag")]
[Api("SwaggerTest Service Description")]
[ApiResponse(HttpStatusCode.BadRequest, "Your request was not understood")]
[ApiResponse(HttpStatusCode.InternalServerError, "Oops, something broke")]
[Route("/swagger", "GET", Summary = @"GET / Summary", Notes = "GET / Notes")]
[Route("/swagger/{Name}", "GET", Summary = @"GET Summary", Notes = "GET /Name Notes")]
[Route("/swagger/{Name}", "POST", Summary = @"POST Summary", Notes = "POST /Name Notes")]
public class SwaggerExample
{
    [ApiMember(Description = "Color Description",
               ParameterType = "path", DataType = "string", IsRequired = true)]
    [ApiAllowableValues("Name", typeof(MyColor))] //Enum
    public string Name { get; set; }

    [ApiMember]
    [ApiAllowableValues("Color", typeof(MyColor))] //Enum
    public MyColor Color { get; set; }

    [ApiMember(Description = "Aliased Description", DataType="string", IsRequired=true)]
    [DataMember(Name = "Aliased")]
    public string Original { get; set; }

    [ApiMember(Description = "Not Aliased", DataType="string", IsRequired=true)]
    public string NotAliased { get; set; }

    [ApiMember(IsRequired = false, AllowMultiple = true)]
    public DateTime[] MyDateBetween { get; set; }

    [ApiMember(Description = "Nested model 1", DataType = "SwaggerNestedModel")]
    public SwaggerNestedModel NestedModel1 { get; set; }

    [ApiMember(Description = "Nested model 2", DataType = "SwaggerNestedModel2")]
    public SwaggerNestedModel2 NestedModel2 { get; set; }
}

Open API允许的另一个注解是 按Tag进行逻辑操作分组 在ServiceStack中,您可以使用 [Tag] 属性,然后您可以在注册 OpenApiFeature 插件,例如

Plugins.Add(new OpenApiFeature
{
    Tags =
    {
        new OpenApiTag
        {
            Name = "TheTag",
            Description = "TheTag Description",
            ExternalDocs = new OpenApiExternalDocumentation
            {
                Description = "Link to External Docs Desc",
                Url = "http://example.org/docs/path",
            }
        }
    }
});
© www.soinside.com 2019 - 2024. All rights reserved.