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.

Dynamic OpenAPI (Swagger/ReDoc) documents based on route prefix

See original GitHub issue

First 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:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
DevLuccacommented, Aug 23, 2021

Oh! That’s nice @Kludex! That’s perfect btw!

Thanks for the help guys!

0reactions
DevLuccacommented, Oct 4, 2021

Hi @dust63! I’ve created a good way using @Kludex method. Have a look here

Read more comments on GitHub >

github_iconTop 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 >

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