烧瓶集默认安全字段用于验证装饰器

发布于 2025-02-10 21:25:18 字数 296 浏览 0 评论 0原文

我刚刚为烧瓶应用程序添加了Secustreation Decorator的安全性:

@rest.post("/url")
@spectree.validate(json=InputSchema, security=[{"apiKey": "X-API-KEY"}, {"Source": "Authorization"}])
def ep_document(json: InputSchema):
    ...

是否有办法将其设置为默认安全性,以便我不必将此字段添加到所有Spectree Decorator中?

I just finished adding security to my spectree validate decorator for my flask app:

@rest.post("/url")
@spectree.validate(json=InputSchema, security=[{"apiKey": "X-API-KEY"}, {"Source": "Authorization"}])
def ep_document(json: InputSchema):
    ...

Is there a way to set this as a default security so that I don't have to add this field to all my spectree decorators?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十年不长 2025-02-17 21:25:19

事实证明,可以在Spectree Config直接进行此配置:

spectree = SpecTree(
    "flask",
    ...
    security={"x_api_key": "X-API-KEY", "authorization": "Authorization"},
    security_schemes=[
        SecurityScheme(
            name="x_api_key",
            data=SecuritySchemeData(
                **{
                    "type": "apiKey",
                    "name": "X-API-KEY",
                    "in": "header",
                    "scheme": "basic",
                }
            ),
        ),
        SecurityScheme(
            name="authorization",
            data=SecuritySchemeData(
                **{
                    "type": "apiKey",
                    "name": "Authorization",
                    "in": "header",
                    "scheme": "basic",
                }
            ),
        ),
    ],
)

Turns out it's possible to do this config directly in spectree config:

spectree = SpecTree(
    "flask",
    ...
    security={"x_api_key": "X-API-KEY", "authorization": "Authorization"},
    security_schemes=[
        SecurityScheme(
            name="x_api_key",
            data=SecuritySchemeData(
                **{
                    "type": "apiKey",
                    "name": "X-API-KEY",
                    "in": "header",
                    "scheme": "basic",
                }
            ),
        ),
        SecurityScheme(
            name="authorization",
            data=SecuritySchemeData(
                **{
                    "type": "apiKey",
                    "name": "Authorization",
                    "in": "header",
                    "scheme": "basic",
                }
            ),
        ),
    ],
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文