diff --git a/fastapi/openapi/models.py b/fastapi/openapi/models.py index 0444aef50..40b26086c 100644 --- a/fastapi/openapi/models.py +++ b/fastapi/openapi/models.py @@ -227,11 +227,13 @@ class Example(TypedDict, total=False): class Config: extra = "allow" + class DefaultErrorSchema(BaseModel): status: int description: Optional[str] = None model: BaseModel + class ParameterInType(Enum): query = "query" header = "header" diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index 429809380..2e555e336 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -419,14 +419,16 @@ def get_openapi_path( openapi_response["description"] = description http422 = str(HTTP_422_UNPROCESSABLE_ENTITY) all_route_params = get_flat_params(route.dependant) - if(default_error_schema is not None): + if default_error_schema is not None: operation["responses"][default_error_schema["status"]] = { "description": default_error_schema["description"], "content": { "application/json": { - "schema": {"$ref": REF_PREFIX + default_error_schema["name"] } + "schema": { + "$ref": REF_PREFIX + default_error_schema["name"] + } }, - } + }, } definitions.update( { @@ -434,7 +436,7 @@ def get_openapi_path( "title": default_error_schema["name"], "type": "object", "properties": default_error_schema["properties"], - "required": default_error_schema["required"] + "required": default_error_schema["required"], } } ) @@ -547,7 +549,7 @@ def get_openapi( model_name_map=model_name_map, field_mapping=field_mapping, separate_input_output_schemas=separate_input_output_schemas, - default_error_schema=default_error_schema + default_error_schema=default_error_schema, ) if result: path, security_schemes, path_definitions = result