swagger-api / swagger-ui

Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
https://swagger.io
Apache License 2.0
26.34k stars 8.92k forks source link

Swagger UI - Set HTTP Response Headers for swagger.index.html .NEt Core #6222

Closed StephanieKeown closed 4 years ago

StephanieKeown commented 4 years ago

Q&A (please complete the following information)

Content & configuration

I am running Swagger via .Net Core in visual studio. In my startup.cs:

Configure(){ ... services.AddSwaggerGen((options) => { options.SwaggerDoc("v1", new OpenApiInfo { Title = "MarineData", Version = "v1" }); }); ... }

ConfigureServices(){ app.UseSwagger();

app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("../swagger/v1/swagger.json", "Marine Data");
});

app.UseHsts();

}

How can we help?

I have to get an API past PEN testing. We have been left with one issue - the swagger.index.html UI does not describe the desired headers, in this instance it is the hsts header. It appears The UI for swagger does not obey any middleware compenents called in the startup.cs(I am using .NetCore, so no web.config). I have tried using NWebSec, and using some suggestions I have found online for adding custom headers. I have been here: https://swagger.io/docs/specification/2-0/describing-responses/ but I cannot how to implement it! There are a few properties i suspect I can configure in the UseSwaggerUI() method but I do not know the syntax or exactly which out of path, schema, and responses, I should be calling.

hkosova commented 4 years ago

This looks like a question for Swashbuckle (the .NET library that you use to generate the API definition from code), not Swagger UI https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues