NSwagStudio生成的客户端无效

时间:2018-09-04 14:57:36

标签: .net-core swagger nswag

我正在使用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" });
    });

我应该改变什么?

0 个答案:

没有答案