APIFlask 怎么把密码保护加到 OpenAPI spec 文件?

读了文档,只说了能把basic authentication, token 加到路径里,那要怎么样做,才能把basic authenctication加到schema文件,比如 http://localhost:5000/openapi.json 或者 http://localhost:5000/openapi.yaml

暂时不支持。不太确定怎么实现比较好。可以在 GitHub 上创建一个 feature request issue。

在APIFlask 里面生成 schema file (json, yaml) 源代码在哪里?

这里有个例子怎么用basic auth 保护schema file。他用的是flasgger package,和APIFLask差不多,也能自动生成 swagger portal https://github.com/flasgger/flasgger/blob/master/examples/basic_auth.py
他就是做了一个 Basic auth decorator 的,然后把它加到Swagger里。我装了 flasgger ,测了一下可以用。所以我想看看 APIFlask 里能不能也这样用。
swag = Swagger(app,
decorators=[ requires_basic_auth ]

Flasgger: https://github.com/flasgger/flasgger

你可以试试自己创建一个视图函数来提供 spec,在内部调用 app._get_spec() 生成 spec。然后创建另一个视图函数来渲染 Swagger UI,在模板里里引入你自己提供的 spec。