Browse Source

add possibility to customize the JSONResponse class for openapi.json

pull/9499/head
Aleksandr Germ 2 years ago
committed by Alexander Gherm
parent
commit
04719a1c91
  1. 4
      fastapi/applications.py

4
fastapi/applications.py

@ -58,6 +58,7 @@ class FastAPI(Starlette):
version: str = "0.1.0", version: str = "0.1.0",
openapi_url: Optional[str] = "/openapi.json", openapi_url: Optional[str] = "/openapi.json",
openapi_tags: Optional[List[Dict[str, Any]]] = None, openapi_tags: Optional[List[Dict[str, Any]]] = None,
openapi_response_class: Type[JSONResponse] = JSONResponse,
servers: Optional[List[Dict[str, Union[str, Any]]]] = None, servers: Optional[List[Dict[str, Union[str, Any]]]] = None,
dependencies: Optional[Sequence[Depends]] = None, dependencies: Optional[Sequence[Depends]] = None,
default_response_class: Type[Response] = Default(JSONResponse), default_response_class: Type[Response] = Default(JSONResponse),
@ -100,6 +101,7 @@ class FastAPI(Starlette):
self.license_info = license_info self.license_info = license_info
self.openapi_url = openapi_url self.openapi_url = openapi_url
self.openapi_tags = openapi_tags self.openapi_tags = openapi_tags
self.openapi_response_class = openapi_response_class
self.root_path_in_servers = root_path_in_servers self.root_path_in_servers = root_path_in_servers
self.docs_url = docs_url self.docs_url = docs_url
self.redoc_url = redoc_url self.redoc_url = redoc_url
@ -228,7 +230,7 @@ class FastAPI(Starlette):
if root_path and self.root_path_in_servers: if root_path and self.root_path_in_servers:
self.servers.insert(0, {"url": root_path}) self.servers.insert(0, {"url": root_path})
server_urls.add(root_path) server_urls.add(root_path)
return JSONResponse(self.openapi()) return self.openapi_response_class(self.openapi())
self.add_route(self.openapi_url, openapi, include_in_schema=False) self.add_route(self.openapi_url, openapi, include_in_schema=False)
if self.openapi_url and self.docs_url: if self.openapi_url and self.docs_url:

Loading…
Cancel
Save