禁用“试一试"在招摇

Disable quot;Try It Outquot; in Swagger(禁用“试一试在招摇)
本文介绍了禁用“试一试"在招摇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题被问了很多不同的语言.经过大量(无果)浏览后,我感觉很愚蠢,但无论如何我都会问

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
    }

这篇关于禁用“试一试"在招摇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)