Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
This question has been asked a lot for different languages. After a substantial amount of (fruitless) browsing Im feeling rather dumb but, I'll ask anyway
This document refers to adding a Swagger plugin in what appears to be Javascript
https://github.com/swagger-api/swagger-ui/issues/3725
I tried adding that code as an injected Javascript resource:
c.InjectJavaScript(thisAssembly, "MyProject.Scripts.swagger-plugins.js");
Code in the .js file is
const DisableTryItOutPlugin = function() {
return {
statePlugins: {
spec: {
wrapSelectors: {
allowTryItOutFor: () => () => false
const DisableAuthorizePlugin = function () {
return {
wrapComponents: {
AuthorizeBtn: () => () => null
SwaggerUI({
plugins: [
DisableTryItOutPlugin,
DisableAuthorizePlugin
That achieved nothing and I have no idea where to go next.
you can hide Try it out button in swagger (using swashbuckle, C# dotnet core) -
Affected Code Line -
c.SupportedSubmitMethods(new Swashbuckle.AspNetCore.SwaggerUI.SubmitMethod[] { }
Entire code sample - (Add inside configure method)
app.UseSwaggerUI(c =>
c.SwaggerEndpoint("/swagger/test/swagger.json", "test API");
c.SupportedSubmitMethods(new Swashbuckle.AspNetCore.SwaggerUI.SubmitMethod[] { });
This is worked because, we have used SubmitMethod enum which have following values inside that -
public enum SubmitMethod
Get = 0,
Put = 1,
Post = 2,
Delete = 3,
Options = 4,
Head = 5,
Patch = 6,
Trace = 7
You can try with these lines in the Configure method in the startup.cs file
app.UseSwaggerUI(c =>
if (!env.IsDevelopment())
c.SupportedSubmitMethods(new SubmitMethod[] { });
c.SwaggerEndpoint("/swagger/swagger.json", "API");
This works in .Net 6.0 & Swashbuckle.AspNetCore 6.3.1
Note: Following sample only shows the new option to disable try-it-out button but not all the Swagger UI options used.
app.UseSwaggerUI(options =>
options.EnableTryItOutByDefault();
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.