Search code examples
swaggerswashbuckle

Not able to Inject Javascript in Swagger


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


Solution

  • 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")