Dynamic OpenAPI (Swagger/ReDoc) documents based on route prefix
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi import FastAPI
prefix = "v1" # But it could be v2, v3, and so on.
app = FastAPI(
title="Content Manager",
openapi_url=f"{prefix}/docs/openapi.json",
docs_url=f"/{prefix}/docs/",
redoc_url=f"/{prefix}/docs/redoc",
)
Description
So I’m writing a API that’s surely going to scale through versioning of my routes. Since FastAPI offers the OpenAPI integration so beautifuly, I wondered if my prefix versions could show only the document of the “route prefix” version.
I’ve tried to instantiate dynamically as inputted, but as the prefix is a fixed variable, it could not get it.
Has anybody achieved some thing sort of equal to what I’m wanting?
Operating System
macOS
Operating System Details
No response
FastAPI Version
0.68.0
Python Version
3.9.5
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Paths and Operations - Swagger
OpenAPI 3.0 supports operation parameters passed via path, query string, headers, and cookies. You can also define the request body for operations that...
Read more >Using OpenAPI and Swagger UI - Quarkus
An OpenAPI document that conforms to the OpenAPI Specification is itself a valid JSON object, that can be represented in yaml or json...
Read more >Extending OpenAPI - FastAPI - tiangolo
As part of the application object creation, a path operation for ... title : The OpenAPI title, shown in the docs. version :...
Read more >c# - Dynamic route prefix for controllers in separate library
A custom route attribute based on IRouteTemplateProvider on the Controller classes will not work because I need the prefix injected from an options...
Read more >OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
3.1 OpenAPI Document; 3.2 Path Templating; 3.3 Media Types ... Data types in the OAS are based on the types supported by the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh! That’s nice @Kludex! That’s perfect btw!
Thanks for the help guys!
Hi @dust63! I’ve created a good way using @Kludex method. Have a look here