Not able to Inject Javascript in Swagger

coder32 picture coder32 · Jan 5, 2017 · Viewed 7.1k times · Source

I get a 404 for a JavaScript file that I am trying to inject in my swagger. Following is my swagger config

var thisAssembly = typeof(SwaggerConfig).Assembly;

GlobalConfiguration.Configuration 
    .EnableSwagger(c =>
        {
            c.SingleApiVersion("v1", "A title for your API");
        })
    .EnableSwaggerUi(c =>
        {
            c.InjectJavaScript(thisAssembly,"MyApi.Api.SwaggerExtensions.inject.js");   
        });

For inject.js build action is set to embedded resource and logical path is correct as my project name is MyApi.Api and the file is in a folder within the project named SwaggerExtensions

Answer

venerik picture venerik · Jan 6, 2017

When using custom resources the resource name should contain the default namespace of your project as described here. In your case the configuration should be:

c.InjectJavaScript(thisAssembly, "AcctMgmt.SwaggerExtensions.inject.js")