Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request]: Remove inline code in Swagger UI index.html #2881

Closed
cremor opened this issue May 14, 2024 · 1 comment · Fixed by #2965
Closed

[Feature request]: Remove inline code in Swagger UI index.html #2881

cremor opened this issue May 14, 2024 · 1 comment · Fixed by #2965
Labels
feature suggestion help-wanted A change up for grabs for contributions from the community

Comments

@cremor
Copy link
Contributor

cremor commented May 14, 2024

Is your feature request related to a specific problem? Or an existing feature?

Not really a problem, but I noticed something:
2 years ago Swagger UI removed their inline CSS and JavaScript from the index.html file. The current file is here, the reason for the change can be found in swagger-api/swagger-ui#7295

It would be nice if Swashbuckle.AspNetCore.SwaggerUI would also do it this way.

Describe the solution you'd like

The inline CSS can simply be replaced by a link to the index.css file, just like the original index.html does it now. This also has the benefit that future updates in the index.css file are available in Swashbuckle.AspNetCore.SwaggerUI automatically.

The inline JavaScript code in Swashbuckle.AspNetCore.SwaggerUI is heavily modified compared to the original code (now in the file swagger-initializer.js). The modified code could be extracted to a custom js file, but then SwaggerUIMiddleware would need to be changed to process that file instead of index.html.
Note: This might need additional consideration concerning Browser-side caching.

Additional context

The same might be true for Redoc UI, I haven't checked that.

@martincostello
Copy link
Collaborator

I think that would be a reasonable change to make provided it didn't break anything. Non-inlined files would be better from a Content Security Policy perspective for those who are concerned about such things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature suggestion help-wanted A change up for grabs for contributions from the community
Projects
None yet
2 participants