mirror of https://github.com/tiangolo/fastapi.git
🎨 [pre-commit.ci] Auto format from pre-commit.com hooks
This commit is contained in:
parent
60798cb06a
commit
e82a5ce4f7
|
|
@ -3,8 +3,7 @@ import inspect
|
||||||
import warnings
|
import warnings
|
||||||
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union, cast
|
from typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union, cast
|
||||||
|
|
||||||
from fastapi import FastAPI
|
from fastapi import FastAPI, routing
|
||||||
from fastapi import routing
|
|
||||||
from fastapi._compat import (
|
from fastapi._compat import (
|
||||||
GenerateJsonSchema,
|
GenerateJsonSchema,
|
||||||
JsonSchemaValue,
|
JsonSchemaValue,
|
||||||
|
|
@ -549,7 +548,6 @@ def get_openapi(
|
||||||
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
|
return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ConsolidatedOpenAPI:
|
class ConsolidatedOpenAPI:
|
||||||
"""
|
"""
|
||||||
ConsolidatedOpenAPI is a utility class for combining the OpenAPI schemas of a main FastAPI application and multiple sub-applications.
|
ConsolidatedOpenAPI is a utility class for combining the OpenAPI schemas of a main FastAPI application and multiple sub-applications.
|
||||||
|
|
@ -631,16 +629,17 @@ class ConsolidatedOpenAPI:
|
||||||
title=self.title,
|
title=self.title,
|
||||||
version=self.version,
|
version=self.version,
|
||||||
routes=self.app.routes,
|
routes=self.app.routes,
|
||||||
**self.kwargs
|
**self.kwargs,
|
||||||
)
|
)
|
||||||
for sub_app in self.sub_apps:
|
for sub_app in self.sub_apps:
|
||||||
subapp_schema = sub_app.openapi()
|
subapp_schema = sub_app.openapi()
|
||||||
sub_app_mount = [x for x in self.app.routes if x.app == sub_app]
|
sub_app_mount = [x for x in self.app.routes if x.app == sub_app]
|
||||||
assert len(sub_app_mount) == 1, f"Faild to find the sub app {sub_app}, please mount the sub app to the main app using `app.mount(...)` first"
|
assert (
|
||||||
|
len(sub_app_mount) == 1
|
||||||
|
), f"Faild to find the sub app {sub_app}, please mount the sub app to the main app using `app.mount(...)` first"
|
||||||
sub_app_mount_path = sub_app_mount[0].path
|
sub_app_mount_path = sub_app_mount[0].path
|
||||||
for path, path_item in subapp_schema["paths"].items():
|
for path, path_item in subapp_schema["paths"].items():
|
||||||
openapi_schema["paths"][f"{sub_app_mount_path}" + path] = path_item
|
openapi_schema["paths"][f"{sub_app_mount_path}" + path] = path_item
|
||||||
|
|
||||||
self.app.openapi_schema = openapi_schema
|
self.app.openapi_schema = openapi_schema
|
||||||
return self.app.openapi_schema
|
return self.app.openapi_schema
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue