[英]Use swagger.json file generated in post build actions in Swashbuckle instead of the file generated at runtime
In my .NET 6 microservice I am generating the swagger.json file with Swashbuckle CLI package and the post build commands.在我的 .NET 6 微服务中,我正在生成 swagger.json 文件与 Swashbuckle post CLI ZEFE90A8E604A7F6B7D 构建命令 ZEFE90A8E604A7F6B78 8 和 8D704A7C840E 构建命令Now I would like to use this json instead of the one generated at runtime by the Swashbuckle package so that the response is faster than the current one.现在我想使用这个 json 而不是 Swashbuckle package 在运行时生成的那个,这样响应比当前的更快。 Is there a way to achieve this?有没有办法做到这一点?
You can include the generated file in the build output and use the "UseStaticFiles()" method to serve it.您可以在构建 output 中包含生成的文件,并使用“UseStaticFiles()”方法来提供它。
For example include the generated file in the output under a new directory called "swaggerfiles", then in the configuration you can have (for example):例如在名为“swaggerfiles”的新目录下包含output中生成的文件,然后在配置中可以有(例如):
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swaggerfiles/swagger.json", "My microservice v1"));
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(env.ContentRootPath, "swaggerfiles")),
RequestPath = "/swaggerfiles"
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.