我在使用自定义index.html和其他资产时遇到了困难。Swashbuckle / Swagger似乎根本无法识别或使用它们。我确实设置了app.UseDefaultFiles()和app.UseStaticFiles()。我试图了解我做错了什么。
我试图设置与Microsoft文章中定义的配置有些类似的配置,但没有成功。(https://docs.microsoft.com/zh-cn/aspnet/core/tutorials/web-api-help-pages-using-swagger?tabs=visual-studio)
我目前正在使用文章(https://github.com/swagger-api/swagger-ui/tree/2.x/dist)中引用的dist文件夹中的文件,以及提供的自定义css文件。
我的index.html文件位于/ wwwroot / swagger / ui下。自定义css文件位于/ wwwroot / swagger / ui / css下(作为custom.css)
这是我的Startup.cs类。
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc()
.AddJsonOptions(options =>
{
// Swagger - Format JSON
options.SerializerSettings.Formatting = Formatting.Indented;
});
// Register the Swagger …Run Code Online (Sandbox Code Playgroud)