😇
Swashbuckle.AspNetCore v 5.0.0 以降は扱うオプションの型が変わっているので注意
Swagger の名前が OpenAPI 仕様(OAS)と変わって Microsoft 名前空間の下にも用意された影響だろうか
Microsoft の公式リファレンスを追いかけていれば情報がアップデートされている
- Swashbuckle と ASP .NET Core の概要
Swashbuckle.AspNetCore v 5.0.0 以降は SwaggerDoc で扱うオプションの型が変わっているので注意
Swashbuckle.AspNetCore version 5.0.0 未満
Startup.cs
// 前略
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
{
Version = "v1",
Title = "Example API",
Description = "A simple example ASP.NET Core Web API",
TermsOfService = "https://example.com/term",
Contact = new Contact
{
Name = "Hoge Fuga",
Email = string.Empty,
Url = "https://example.com/hoge"
},
License = new License
{
Name = "Use under LICX",
Url = "https://example.com/license"
}
});
});
}
// 後略
Swashbuckle.AspNetCore version 5.0.0 以上
Startup.cs
using Microsoft.OpenApi.Models; // 追加で必要
// 中略
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "Example API",
Description = "A simple example ASP.NET Core Web API",
TermsOfService = new Uri("https://example.com/term"),
Contact = new OpenApiContact
{
Name = "Hoge Fuga",
Email = string.Empty,
Url = new Uri("https://example.com/hoge")
},
License = new OpenApiLicense
{
Name = "Use under LICX",
Url = new Uri("https://example.com/license")
}
});
});
}
// 後略
参考
- Why Swashbuckle.aspnet.core.swagger not being recognized - stackoverflow
- cannot convert from 'Microsoft.OpenApi.Models.OpenApiInfo' to 'Swashbuckle.AspNetCore.Swagger.Info'
- Get started with Swashbuckle and ASP .NET Core
Discussion