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.

Sub-Application routes are not shown in root routes

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 the docs : https://fastapi.tiangolo.com/advanced/sub-applications/
from fastapi import FastAPI

app = FastAPI()


@app.get("/app")
def read_main():
    return {"message": "Hello World from main app"}


subapi = FastAPI()


@subapi.get("/sub")
def read_sub():
    return {"message": "Hello World from sub API"}


app.mount("/subapi", subapi)

Description

The sub Apis routes are not shown in the root docs.

I’m adding dynamically multiple sub Apis in my root app and it’s hard to keep track of which is mounted and on which names.

Is there a way to show at least the name of the sub API route in the root app?

Example Docs at the root :

/app # (exists) Description of  /app route in root
/subapi # (Do not exists) Description of /subapi (at least to know another app is mounted)

Nother Exemple of Docs at the root :

/app # Description of  /app route in root
# SubApi Tag to know there is another app 
/docs # Know that there is docs inside subapp
/sub  # Know that there is sub route inside sub app

Operating System

Linux

Operating System Details

Archlinux Kernel 5.13.10

FastAPI Version

0.66.0

Python Version

3.9.6

Additional Context

Thanks for this beautiful library !

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
frerikandriessencommented, Sep 22, 2021

I would also like to have an overview of all the mounted routes on the root docs. Is this something FastAPI is willing to accept a PR for?

2reactions
kauedgcommented, Aug 25, 2021

I’ve been using subapps to manage different API versions and these versions are listed by a “information” endpoint.

import starlette
from fastapi import FastAPI, Request
from versions import v0, v1

class ApiInfo(object):
    """docstring for ApiInfo."""

    def __init__(
        self,
        app: FastAPI,
        request: Request):

        super(ApiInfo, self).__init__()

        self.url = str(request.url)

        self.autodocs = {
            'swagger': str(request.url) + app.docs_url.strip("/"),
            'redoc': str(request.url) + app.redoc_url.strip("/"),
        }

        # Gera a lista de versões
        self.versions = {}
        for version in app.routes:
            if type(versions) is starlette.routing.Mount:
                self.versions[version.name] =  str(request.url) + version.name


app = FastAPI(
    title="Root app",
)

app.mount("/v0", v0.app, "v0")
app.mount("/v1", v1.app, "v1")

@app.get(
   '/',
   summary='API Information',
   tags=['API'],
)
def info(
   request: Request,
):
   apiInfo = ApiInfo(app, request)

   apiInfo.versions['stable'] = apiInfo.versions['v0']
   apiInfo.versions['develop'] = apiInfo.versions['v1']
   # whatever other label/mount name you want
   
   return apiInfo.__dict__

It will return something like this

{
  "url": "http://192.168.0.20:8686/",
  "versions": {
    "v0": "http://192.168.0.20:8686/v0",
    "v1": "http://192.168.0.20:8686/v1",
    "stable": "http://192.168.0.20:8686/v0"
    "develop": "http://192.168.0.20:8686/v1"
  },
  "autodocs": {
    "swagger": "http://192.168.0.20:8686/docs",
    "redoc": "http://192.168.0.20:8686/redoc"
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

IIS and C# making use of root route in a sub application
In my opinion, you could write a asp.net application e.g webform or MVC or else at the root of the example.com website in...
Read more >
FAQ - qiankun - UmiJS
The js itself of the sub-application has syntax compatibility issues in the current runtime environment. How to load micro apps on a routing...
Read more >
5 Advanced Features of FastAPI You Should Try
Therefore, all the routes from all the APIRouters will be listed in the main application documentation. These APIRouters can have separate prefixes to...
Read more >
View alternate routes - Waze Help - Google Support
When searching for a route, Waze will often provide multiple options. To see alternate routes: Tap on the ETA bar at the bottom...
Read more >
Combining Multiple Angular Applications into a Single One
app1: The source code for your first custom sub application; app1/app: The ... Note here I did not set up a catch all...
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