1

我正在使用 NSwagStudio 为我的 WebAPI (.NET Core 2.0) 生成客户端。不幸的是,生成的客户端是无用的。

例如:

[Route("v1/documentsets")]
.
.
.
[Route("")]
[HttpGet]
[Authorize(Policy = AuthorizationPolicyKeys.ReadOnly)]
[ProducesResponseType(typeof(ResponseContainer<PagingInfo, IList<GetDocumentSetsResponseDto>>), 200)]
public async Task<IActionResult> GetAll(...)

变成:

公共 System.Threading.Tasks.Task V1DocumentsetsGetAsync(...)

这是因为 - swagger.json (我用于生成的)也是无效的(我认为):

"responses": {
  "200": {
    "description": "Success",
    "schema": {
      "$ref": "#/definitions/Comp.Shared.Helpers.ResponseContainer`2[[Comp.Shared.Helpers.PagingInfo, Comp.Shared, Version=2.0.16.0, Culture=neutral, PublicKeyToken=null],[System.Collections.Generic.IList`1[[Comp.Documents.Private.DataTransferObjects.Documents.GetDocumentsResponseDto, Comp.Documents.Private, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]"
    }
  }
}

$ref 似乎在这里无效... PagingInfo 和 ResponseContainer 类型来自 Nuget 包。

生成的方法名称 - V1DocumentsetsGetAsync - 似乎也很奇怪。来自 swagger.json 的 operationId: "operationId": "V1DocumentsetsGet" - 这也很奇怪。为什么版本号在生成的id中?

招摇设置:

    services.AddSwaggerGen(c =>
    {
        c.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info { Title = "Documents API", Version = "v1" });                
        var xmlPath = $@"{AppDomain.CurrentDomain.BaseDirectory}\bin\{Assembly.GetExecutingAssembly().GetName().Name}.XML";
        if (File.Exists(xmlPath))
        {
            c.IncludeXmlComments(xmlPath);
        }
        c.DescribeAllEnumsAsStrings();
        c.CustomSchemaIds((type) => type.FullName);
        c.MapType<RequestedFieldDictionary>(() => new Schema { Type = "string" });
    });

我应该改变什么?

4

0 回答 0