question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to hide `Schemas` section in `/docs`?

See original GitHub issue
from fastapi import FastAPI
from pydantic.main import BaseModel

app = FastAPI()

class Model(BaseModel):
    a: str

@app.get("/", response_model=BaseModel)
def get():
    return {"a": "b"}

After uvicorn app:app, /docs shows this:

Is there any way to hide Schemas section with the BaseModel? I don’t want to remove the schema definitions from the API spec. Instead, I just want to remove them from the render. I’ve checked out Extending OpenAPI, but didn’t find anything related.

I found How to hide the Models section in Swagger UI? which mentions a field called defaultModelsExpandDepth, but not sure how I could configure such a thing through FastAPI.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

21reactions
fdegiercommented, Feb 12, 2022

FastAPI now supports passing swagger parameters, so to hide the schemas you can do it as below:

app = FastAPI(
    title="API",
    swagger_ui_parameters={"defaultModelsExpandDepth": -1}
)
0reactions
KYJiyacommented, Dec 9, 2021

I found out how to do this, I had to add defaultModelsExpandDepth: -1, (like the SO answers say) to https://github.com/tiangolo/fastapi/blob/master/fastapi/openapi/docs.py#L40, and then serve the custom generated HTML myself through https://fastapi.tiangolo.com/advanced/extending-openapi/#serve-the-static-files. Will open formal merge request for this soon, and close issue around then.

it works. thank’s.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to hide the Models section in Swagger UI? - Stack Overflow
To hide the "Models" section, add defaultModelsExpandDepth: -1 to the Swagger UI configuration code in your index.html .
Read more >
Hide Endpoints And Schemas from Swagger / OpenAPI
Remove Swagger endpoints from OpenAPI documentation. Remove schemas from Swagger. Hide swagger endpoints via Swashbuckle filters.
Read more >
Learn About Article Schema Markup | Google Search Central
Learn how adding article schema markup to your news articles and blogs can enhance their appearance in Google Search results.
Read more >
OpenAPI Specification - Version 2.0 - Swagger
Relevant only for Schema "properties" definitions. Declares the property as "read only". This means that it MAY be sent as part of a...
Read more >
OpenAPI 3 Library for spring-boot
/api-docs endpoint custom path springdoc.api-docs.path=/api-docs ... The javadoc comment of an attribute: is resolved as '@Schema' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found