有选择地禁用“试用"在 swaggerUI 中 [英] Selectively disable "Try it out" in swaggerUI
问题描述
虽然这里有一个关于这个话题的长时间讨论:https://github.com/swagger-api/swagger-ui/issues/156
Although there is a long discussion on the topic here: https://github.com/swagger-api/swagger-ui/issues/156
我还没有找到一种更简洁的方法来有选择地"禁用试用"按钮.我想为我的 API 的所有 POST 方法禁用它.
I have not found a cleaner way to 'selectively' disable the "Try it out" button. I want to disable it for all the POST methods of my API.
先谢谢你
推荐答案
Swagger UI 3.10.0+ 和 2.x 提供了 supportedSubmitMethods
选项来控制哪些 HTTP 方法启用了试用"(默认 = all).
Swagger UI 3.10.0+ and 2.x provide the supportedSubmitMethods
option to control which HTTP methods have "try it out" enabled (default = all).
要为 POST(但不是 PATCH/PUT)禁用试用":
To disable "try it out" for POST (but not PATCH/PUT):
// index.html (Swagger UI 3.10+)
const ui = SwaggerUIBundle({
url: "http://my.api.com/openapi.yaml",
supportedSubmitMethods: ["get", "delete", "options", "head", "patch", "trace"], // No "post"
...
})
要对除 GET 和 HEAD 之外的所有方法禁用试用":
To disable "try it out" for all methods except GET and HEAD:
supportedSubmitMethods: ["get", "head"],
这篇关于有选择地禁用“试用"在 swaggerUI 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!