Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

424
Visualizações
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. 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.

docExpansion does not appear to work either. What am I missing?

app = FastAPI(
    openapi_tags=tags_metadata,
    title="Documentation",
    description="API endpoints",
    version="0.1",
    docExpansion="None"
) 
over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

swagger has the UI parameter "defaultModelsExpandDepth" for controlling models' view in the schema section.

This parameter can be forwarded using "swagger_ui_parameters" parameter on FastApi initialization.

app = FastAPI(swagger_ui_parameters={"defaultModelsExpandDepth": -1})

Values:

  • -1: schema section hidden
  • 0: schema section is closed
  • 1: schema section is open (default)

More options can be found here: https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/

over 4 years ago · Santiago Trujillo Relatório

0

set include_in_schema=False in the args to the FastAPI instance decorator instead

app = FastAPI(...)

@app.get("/", include_in_schema=False)
async def root():
    ...
over 4 years ago · Santiago Trujillo Relatório

0

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 js to hide the desired elements within that document's iframe.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda