I'm using NSwagStudio to generate a client for my WebAPI (.NET Core 2.0). Unfortunately the generated client is useless.
For example:
[Route("v1/documentsets")]
.
.
.
[Route("")]
[HttpGet]
[Authorize(Policy = AuthorizationPolicyKeys.ReadOnly)]
[ProducesResponseType(typeof(ResponseContainer<PagingInfo, IList<GetDocumentSetsResponseDto>>), 200)]
public async Task<IActionResult> GetAll(...)
becomes:
public System.Threading.Tasks.Task V1DocumentsetsGetAsync(...)
This is because - swagger.json (what I use for the generation) is also invalid (I think):
"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 seems to be invalid here... PagingInfo and ResponseContainer types are from a Nuget package.
The generated method name - V1DocumentsetsGetAsync - seems strange as well. The operationId from swagger.json: "operationId": "V1DocumentsetsGet" - this is strange too. Why is the version number is in the generated id?
Swagger settings:
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" });
});
What should I change?