[英]Get Swasbuckle 5 to output Swagger 2.0 Json instead of OpenAPI 3.0
I have upgraded my Swashbuckle to version 5 and everything is much better.我已将 Swashbuckle 升级到第 5 版,一切都变得更好了。
Now I have a problem that my consumers need the Swagger Json formattet as Swagger 2.0 instead of the default in Swashbuckle 5 that outputs the swagger in the Openapi 3.0.1 format.现在我有一个问题,我的消费者需要 Swagger Json 格式作为 Swagger 2.0 而不是 Swashbuckle 5 中的默认值,它以 Openapi 3.0.1 格式输出 swagger。
My config is as follows:我的配置如下:
public static void ConfigureSwagger(SwaggerGenOptions c)
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Gdpr Api",
Version = "v1",
Description ="This API is for GDPR ."
});
c.EnableAnnotations();
}
public static void ConfigureSwaggerUi(this IApplicationBuilder app)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "GDPR - Version 1");
c.DocumentTitle = "Gdpr Swagger";
});
}
I thought this was impossible until I found that you can do the following with the help of Helen and the Release Notes for RC4 .我认为这是不可能的,直到我发现您可以在 Helen 和RC4 发行说明的帮助下执行以下操作。 The solution is to set SerializeAsV2 = true
.解决方案是设置SerializeAsV2 = true
。
public static void ConfigureSwaggerUi(this IApplicationBuilder app)
{
app.UseSwagger(p => p.SerializeAsV2 = true);
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "GDPR - Version 1");
c.DocumentTitle = "Gdpr Swagger";
});
}
This will output the Swagger JSON in the 2.0 format.这将以 2.0 格式输出 Swagger JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.