Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions starlette/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from starlette.requests import Request
from starlette.responses import Response
from starlette.routing import BaseRoute, Mount, Route
from starlette.routing import BaseRoute, Host, Mount, Route

try:
import yaml
Expand Down Expand Up @@ -49,9 +49,12 @@ def get_endpoints(
endpoints_info: list = []

for route in routes:
if isinstance(route, Mount):
path = self._remove_converter(route.path)
if isinstance(route, (Mount, Host)):
routes = route.routes or []
if isinstance(route, Mount):
path = self._remove_converter(route.path)
else:
path = ""
sub_endpoints = [
EndpointInfo(
path="".join((path, sub_endpoint.path)),
Expand Down
15 changes: 14 additions & 1 deletion tests/test_schemas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from starlette.applications import Starlette
from starlette.endpoints import HTTPEndpoint
from starlette.routing import Mount, Route, WebSocketRoute
from starlette.routing import Host, Mount, Route, Router, WebSocketRoute
from starlette.schemas import SchemaGenerator

schemas = SchemaGenerator(
Expand Down Expand Up @@ -123,6 +123,7 @@ def schema(request):
Route("/no-docstring", endpoint=no_docstring),
Route("/schema", endpoint=schema, methods=["GET"], include_in_schema=False),
Mount("/subapp", subapp),
Host("sub.domain.com", app=Router(routes=[Mount("/subapp2", subapp)])),
]
)

Expand Down Expand Up @@ -165,6 +166,13 @@ def test_schema_generation():
}
}
},
"/subapp2/subapp-endpoint": {
"get": {
"responses": {
200: {"description": "This endpoint is part of a subapp."}
}
}
},
"/users": {
"get": {
"responses": {
Expand Down Expand Up @@ -224,6 +232,11 @@ def test_schema_generation():
responses:
200:
description: This endpoint is part of a subapp.
/subapp2/subapp-endpoint:
get:
responses:
200:
description: This endpoint is part of a subapp.
/users:
get:
responses:
Expand Down