[英]FastAPI - @Schema(hidden=True) not working when trying to hide the schema section on swagger docs
I'm trying to hide the entire schemas section of the FastAPI generated swagger docs.我试图隐藏 FastAPI 生成的 swagger 文档的整个模式部分。 I've checked the docs and tried this but the schema section still shows.
我检查了文档并尝试了这个,但架构部分仍然显示。
@Schema(hidden=True)
class theSchema(BaseModel):
category: str
How do I omit one particular schema or the entire schemas section from the returned swagger docs.如何从返回的 swagger 文档中省略一个特定模式或整个模式部分。
docExpansion does not appear to work either. docExpansion 似乎也不起作用。 What am I missing?
我错过了什么?
app = FastAPI(
openapi_tags=tags_metadata,
title="Documentation",
description="API endpoints",
version="0.1",
docExpansion="None"
)
swagger has the UI parameter "defaultModelsExpandDepth" for controlling models' view in the schema section. swagger 具有 UI 参数“defaultModelsExpandDepth”,用于控制模式部分中模型的视图。
This parameter can be forwarded using "swagger_ui_parameters" parameter on FastApi initialization.可以在 FastApi 初始化时使用“swagger_ui_parameters”参数转发此参数。
app = FastAPI(swagger_ui_parameters={"defaultModelsExpandDepth": -1})
Values:价值观:
More options can be found here: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/更多选项可以在这里找到: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
set include_in_schema=False
in the args to the FastAPI
instance decorator instead将 args 中的
include_in_schema=False
设置为FastAPI
实例装饰器
app = FastAPI(...)
@app.get("/", include_in_schema=False)
async def root():
...
Not sure if I get points for answering my own question but if anyone wants to know, this was resolved by loading the swagger page into an iframe then using json to hide the desired elements within that document's iframe. Not sure if I get points for answering my own question but if anyone wants to know, this was resolved by loading the swagger page into an iframe then using json to hide the desired elements within that document's iframe.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.