问题描述
这个问题被问了很多不同的语言.经过大量(无果)浏览后,我感觉很愚蠢,但无论如何我都会问
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
本文档指的是在看似 Javascript 的内容中添加 Swagger 插件https://github.com/swagger-api/swagger-ui/issues/3725
This document refers to adding a Swagger plugin in what appears to be Javascript https://github.com/swagger-api/swagger-ui/issues/3725
我尝试将该代码添加为注入的 Javascript 资源:
I tried adding that code as an injected Javascript resource:
c.InjectJavaScript(thisAssembly, "MyProject.Scripts.swagger-plugins.js");
.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.
推荐答案
可以在swagger中隐藏Try it out按钮(使用swashbuckle,C# dotnet core) -
you can hide Try it out button in swagger (using swashbuckle, C# dotnet core) -
受影响的代码行 -
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[] { });
});
这是可行的,因为我们使用了 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
}
这篇关于禁用“试一试"在招摇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!