C# ASP.NET核心:NSwag与Swashback
我们目前正在使用Swashback.AspNetCore来编写API文档,但在生成客户端模型(Typescript)时,它似乎有一个主要缺点 作为示例,我使用基类增强了已知的ASP.NET默认项目(WeatherForecast)C# ASP.NET核心:NSwag与Swashback,c#,.net,nswag,swashbuckle.aspnetcore,C#,.net,Nswag,Swashbuckle.aspnetcore,我们目前正在使用Swashback.AspNetCore来编写API文档,但在生成客户端模型(Typescript)时,它似乎有一个主要缺点 作为示例,我使用基类增强了已知的ASP.NET默认项目(WeatherForecast) public class InfoEntryBase { public string Name { get; set; } public string Description { get; set; } } public clas
public class InfoEntryBase
{
public string Name { get; set; }
public string Description { get; set; }
}
public class WeatherForecast : InfoEntryBase
{
public DateTime Date { get; set; }
public int TemperatureC { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
public string Summary { get; set; }
}
然后,它公开了天气预报
WeatherForecast{
name string
nullable: true
description string
nullable: true
date string($date-time)
temperatureC integer($int32)
temperatureF integer($int32)
readOnly: true
summary string
nullable: true
}
遗产也会丢失。
这将使从服务器端代码自动生成客户端模型变得不可能,因为我们自然喜欢将继承移植到Typescript代码
在调查NSwag.AspNetCore时,我发现它很关心继承问题。它揭示了:
WeatherForecast{
name string
description string
date* string($date-time)
temperatureC* integer($int32)
temperatureF* integer($int32)
summary string
}
InfoEntryBase{
name string
description string
}
我是否忽略了有关Swashback的内容,或者没有其他选择可以从它切换到NSwag
您可以在上查看代码
然而,NSwag实现驻留在主分支中。这解决了它
services.AddSwaggerGen(options =>
{
options.UseAllOfForInheritance();