RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.69k stars 1.24k forks source link

Add Accept-Language header as optional header to Swagger UI #2139

Open OculiViridi opened 5 years ago

OculiViridi commented 5 years ago

I'm currently using NSwag v12.2.3 for my .NET Core 2.1 Web API project.

Since I support multilanguage for the API, I'd like to add the Accept-Language header to the Swagger UI interface (as optional), so when testing/using aPI through Swagger it is also possible to test/use the localization. Now the header is obviously based on the browser language.

I've seen this issue (#1249) but I think it is a bit old and I wasn't able to adapt to my actual configuration.

Thanks!

RicoSuter commented 5 years ago

With an operation processor you can add a header parameter to each operation... or is there a swagger ui option for that so that you don't have to modify the spec?

OculiViridi commented 5 years ago

or is there a swagger ui option for that so that you don't have to modify the spec?

That was my idea, if possible. Something like the version selector dropdown menu, that shows any language available that is set in the Swagger UI configuration (like versions).

When I select the language, then all the requests are made with the selected value automatically pushed inside the Accept-Language header.

RicoSuter commented 5 years ago

So this is more a question about how to customize Swagger UI itself - if it's ok to do this via spec then you could manually add a header with an enum schema with all allowed values...

OculiViridi commented 5 years ago

So this is more a question about how to customize Swagger UI itself - if it's ok to do this via spec then you could manually add a header with an enum schema with all allowed values...

Ok. Just to be sure, can you please provide some sample code?