Reputation: 420
Currently the OpenAPI documentation looks like this:
Is it possible to separate it into multiple sections?
For example, 2 sections, one being the "books" section that contains the methods from "/api/bookcollection/books/" endpoints and the other containing the endpoints with "/api/bookcollection/authors/".
I have consulted the FastApi documentation, but I do not find anything close to the operation I want to do.
Upvotes: 4
Views: 3869
Reputation: 420
Another solution for this would be just to create different routers for every resource that you want to have in different documentation sections.
Upvotes: 1
Reputation: 32233
The OpenAPI
allows the use of tags to group endpoints. FastAPI
also supports this feature. The documentation section can be found here.
Example:
from fastapi import FastAPI
tags_metadata = [
{
"name": "users",
"description": "Operations with users. The **login** logic is also here.",
},
{
"name": "items",
"description": "Manage items. So _fancy_ they have their own docs.",
"externalDocs": {
"description": "Items external docs",
"url": "https://fastapi.tiangolo.com/",
},
},
]
app = FastAPI(openapi_tags=tags_metadata)
@app.get("/users/", tags=["users"])
async def get_users():
return [{"name": "Harry"}, {"name": "Ron"}]
@app.get("/items/", tags=["items"])
async def get_items():
return [{"name": "wand"}, {"name": "flying broom"}]
Upvotes: 9