简体   繁体   English

使用在 Swashbuckle 的后期构建操作中生成的 swagger.json 文件,而不是在运行时生成的文件

[英]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.

相关问题 ASP.NET Core - Swashbuckle 未创建 swagger.json 文件 - ASP.NET Core - Swashbuckle not creating swagger.json file 我可以指定 Web-Api 方法需要 Swashbuckle/Swagger 生成的页面/json 中的文件吗 - Can I specify that Web-Api method expects a file in Swashbuckle/Swagger generated page/json Swashbuckle 自动向生成的 Swagger 文件添加 200 OK 响应 - Swashbuckle adding 200 OK response automatically to generated Swagger file Swashbuckle C#swagger插件默认情况下如何使用我自己的个人swagger.json而不是依靠它生成的一个? - Swashbuckle C# swagger plugin how to use my own personal swagger.json by default instead of relying on one it generates? XML内联注释不包含在生成的swagger.json中 - XML inline comments are not included in the generated swagger.json 从基础 controller 继承 controller 操作时生成 swagger.json 文件的问题 - Issue generating swagger.json file when inheriting controller actions from a base controller Swashbuckle生成的Swagger有错误 - Swashbuckle generated Swagger has errors 当本地主机提供 swagger.json 时,Autorest 无法针对文件解析 swagger.json - Autorest Failed resolving swagger.json against file when swagger.json is served by localhost .net 6.0:如何在 .net 6.0 中生成 Swagger.json 文件? - .net 6.0 : How to generate Swagger.json file on build in .net 6.0? Swashbuckle swagger.json 大于 4 mb 净核心 - Swashbuckle swagger.json larger than 4 mb net core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM