简体   繁体   中英

Custom Index Swashbuckle/Swagger

this is my first time using Swagger, I'm currently using Swashbuckle.AspNetCore v2.4.0 and trying to implement a custom index page. In this version they have removed the possibility of injecting javascript, and I'm essentially stuck with the only option of making a custom index.html page just to edit some links (most specifically the navigation icon link). I'm trying to get my custom index page to work but I'm having trouble getting it to load.

app.UseSwaggerUI(c =>
{
    c.IndexStream = () => GetType().GetTypeInfo().Assembly
        .GetManifestResourceStream("customSwaggerIndex.html"); // requires file to be added as an embedded resource
});

I have the following in my code with the customSwaggerIndex.html saved on the wwwroot folder and its Build Action set as Embedded resource, but I keep running into the error System.ArgumentNullException: Value cannot be null . This is most likely due to me not properly writing the GetManifestResourceStream("string"). Any help?

Figured out why it wasn't working. First thing is that it needs the name of the solution, and instead of \\ its .

So for example a file located in my wwwroot folder would look like this.

c.IndexStream = () => GetType().GetTypeInfo().Assembly
        .GetManifestResourceStream("MySolution.wwwroot.customSwaggerIndex.html");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM