We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Enhancement: Add a way to override default OpenAPI response descriptions
**What's the feature you'd like to ask for.**
Currently there is no way to replace the default OpenAPI description for HTTP 400 errors. For example, you currently can't do this:

```python
@starlite.post(
    "/path",
    responses={
        400: starlite.ResponseSpec(
            model=MyErrorModel, description="A more detailed error description"
        )
    },
)
async def login() -> starlite.Response:
    ...
```

If you do, you will get this error on startup:

```console
starlite.exceptions.http_exceptions.ImproperlyConfiguredException: 500: Additional response for status code 400 already exists in success or error responses
```

This makes it impossible to add more detailed error descriptions or properly document response shapes if you want your endpoint to return a different error shape.

**Additional context**
Removing this bit of code would allow the default HTTP 400 description to be replaced:
https://github.com/seladb/starlite/blob/51ae7eebda3e6834a6520471bfdb9cad2ab790c5/starlite/openapi/responses.py#L217-L220


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `starlite/_openapi/responses.py`
Content:
```
1 from copy import copy
2 from http import HTTPStatus
3 from operator import attrgetter
4 from typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Type
5 
6 from pydantic_openapi_schema.v3_1_0 import Response
7 from pydantic_openapi_schema.v3_1_0.header import Header
8 from pydantic_openapi_schema.v3_1_0.media_type import MediaType as OpenAPISchemaMediaType
9 from pydantic_openapi_schema.v3_1_0.schema import Schema
10 from typing_extensions import get_args, get_origin
11 
12 from starlite._openapi.enums import OpenAPIFormat, OpenAPIType
13 from starlite._openapi.schema import create_schema
14 from starlite._openapi.utils import pascal_case_to_text
15 from starlite._signature.models import SignatureField
16 from starlite.enums import MediaType
17 from starlite.exceptions import HTTPException, ImproperlyConfiguredException, ValidationException
18 from starlite.response import Response as StarliteResponse
19 from starlite.response_containers import File, Redirect, Stream, Template
20 from starlite.utils import get_enum_string_value, get_name, is_class_and_subclass
21 
22 __all__ = (
23     "create_additional_responses",
24     "create_cookie_schema",
25     "create_error_responses",
26     "create_responses",
27     "create_success_response",
28 )
29 
30 
31 if TYPE_CHECKING:
32     from pydantic_openapi_schema.v3_1_0.responses import Responses
33 
34     from starlite.datastructures.cookie import Cookie
35     from starlite.handlers.http_handlers import HTTPRouteHandler
36     from starlite.plugins.base import OpenAPISchemaPluginProtocol
37 
38 
39 def create_cookie_schema(cookie: "Cookie") -> Schema:
40     """Given a Cookie instance, return its corresponding OpenAPI schema.
41 
42     Args:
43         cookie: Cookie
44 
45     Returns:
46         Schema
47     """
48     cookie_copy = copy(cookie)
49     cookie_copy.value = "<string>"
50     value = cookie_copy.to_header(header="")
51     return Schema(description=cookie.description or "", example=value)
52 
53 
54 def create_success_response(
55     route_handler: "HTTPRouteHandler", generate_examples: bool, plugins: List["OpenAPISchemaPluginProtocol"]
56 ) -> Response:
57     """Create the schema for a success response."""
58     signature = route_handler.signature
59     default_descriptions: Dict[Any, str] = {
60         Stream: "Stream Response",
61         Redirect: "Redirect Response",
62         File: "File Download",
63     }
64     description = (
65         route_handler.response_description
66         or default_descriptions.get(signature.return_annotation)
67         or HTTPStatus(route_handler.status_code).description
68     )
69 
70     if signature.return_annotation not in {signature.empty, None, Redirect, File, Stream}:
71         return_annotation = signature.return_annotation
72         if signature.return_annotation is Template:
73             return_annotation = str  # since templates return str
74             route_handler.media_type = get_enum_string_value(MediaType.HTML)
75         elif is_class_and_subclass(get_origin(signature.return_annotation), StarliteResponse):
76             return_annotation = get_args(signature.return_annotation)[0] or Any
77 
78         schema = create_schema(
79             field=SignatureField.create(field_type=return_annotation),
80             generate_examples=generate_examples,
81             plugins=plugins,
82         )
83         schema.contentEncoding = route_handler.content_encoding
84         schema.contentMediaType = route_handler.content_media_type
85         response = Response(
86             content={
87                 route_handler.media_type: OpenAPISchemaMediaType(
88                     media_type_schema=schema,
89                 )
90             },
91             description=description,
92         )
93 
94     elif signature.return_annotation is Redirect:
95         response = Response(
96             content=None,
97             description=description,
98             headers={
99                 "location": Header(
100                     param_schema=Schema(type=OpenAPIType.STRING), description="target path for the redirect"
101                 )
102             },
103         )
104 
105     elif signature.return_annotation in (File, Stream):
106         response = Response(
107             content={
108                 route_handler.media_type: OpenAPISchemaMediaType(
109                     media_type_schema=Schema(
110                         type=OpenAPIType.STRING,
111                         contentEncoding=route_handler.content_encoding or "application/octet-stream",
112                         contentMediaType=route_handler.content_media_type,
113                     ),
114                 )
115             },
116             description=description,
117             headers={
118                 "content-length": Header(
119                     param_schema=Schema(type=OpenAPIType.STRING), description="File size in bytes"
120                 ),
121                 "last-modified": Header(
122                     param_schema=Schema(type=OpenAPIType.STRING, schema_format=OpenAPIFormat.DATE_TIME),
123                     description="Last modified data-time in RFC 2822 format",
124                 ),
125                 "etag": Header(param_schema=Schema(type=OpenAPIType.STRING), description="Entity tag"),
126             },
127         )
128 
129     else:
130         response = Response(
131             content=None,
132             description=description,
133         )
134 
135     if response.headers is None:
136         response.headers = {}
137 
138     for response_header in route_handler.resolve_response_headers():
139         header = Header()
140         for attribute_name, attribute_value in response_header.dict(exclude_none=True).items():
141             if attribute_name == "value":
142                 header.param_schema = create_schema(
143                     field=SignatureField.create(field_type=type(attribute_value)),
144                     generate_examples=False,
145                     plugins=plugins,
146                 )
147 
148             elif attribute_name != "documentation_only":
149                 setattr(header, attribute_name, attribute_value)
150         response.headers[response_header.name] = header
151 
152     if cookies := route_handler.resolve_response_cookies():
153         response.headers["Set-Cookie"] = Header(
154             param_schema=Schema(
155                 allOf=[create_cookie_schema(cookie=cookie) for cookie in sorted(cookies, key=attrgetter("key"))]
156             )
157         )
158 
159     return response
160 
161 
162 def create_error_responses(exceptions: List[Type[HTTPException]]) -> Iterator[Tuple[str, Response]]:
163     """Create the schema for error responses, if any."""
164     grouped_exceptions: Dict[int, List[Type[HTTPException]]] = {}
165     for exc in exceptions:
166         if not grouped_exceptions.get(exc.status_code):
167             grouped_exceptions[exc.status_code] = []
168         grouped_exceptions[exc.status_code].append(exc)
169     for status_code, exception_group in grouped_exceptions.items():
170         exceptions_schemas = [
171             Schema(
172                 type=OpenAPIType.OBJECT,
173                 required=["detail", "status_code"],
174                 properties={
175                     "status_code": Schema(type=OpenAPIType.INTEGER),
176                     "detail": Schema(type=OpenAPIType.STRING),
177                     "extra": Schema(
178                         type=[OpenAPIType.NULL, OpenAPIType.OBJECT, OpenAPIType.ARRAY], additionalProperties=Schema()
179                     ),
180                 },
181                 description=pascal_case_to_text(get_name(exc)),
182                 examples=[{"status_code": status_code, "detail": HTTPStatus(status_code).phrase, "extra": {}}],
183             )
184             for exc in exception_group
185         ]
186         if len(exceptions_schemas) > 1:  # noqa: SIM108
187             schema = Schema(oneOf=exceptions_schemas)  # type:ignore[arg-type]
188         else:
189             schema = exceptions_schemas[0]
190         yield str(status_code), Response(
191             description=HTTPStatus(status_code).description,
192             content={MediaType.JSON: OpenAPISchemaMediaType(media_type_schema=schema)},
193         )
194 
195 
196 def create_additional_responses(
197     route_handler: "HTTPRouteHandler", plugins: List["OpenAPISchemaPluginProtocol"]
198 ) -> Iterator[Tuple[str, Response]]:
199     """Create the schema for additional responses, if any."""
200     if not route_handler.responses:
201         return
202 
203     for status_code, additional_response in route_handler.responses.items():
204         schema = create_schema(
205             field=SignatureField.create(field_type=additional_response.model),
206             generate_examples=additional_response.generate_examples,
207             plugins=plugins,
208         )
209         yield str(status_code), Response(
210             description=additional_response.description,
211             content={additional_response.media_type: OpenAPISchemaMediaType(media_type_schema=schema)},
212         )
213 
214 
215 def create_responses(
216     route_handler: "HTTPRouteHandler",
217     raises_validation_error: bool,
218     generate_examples: bool,
219     plugins: List["OpenAPISchemaPluginProtocol"],
220 ) -> Optional["Responses"]:
221     """Create a Response model embedded in a `Responses` dictionary for the given RouteHandler or return None."""
222 
223     responses: "Responses" = {
224         str(route_handler.status_code): create_success_response(
225             route_handler=route_handler,
226             generate_examples=generate_examples,
227             plugins=plugins,
228         ),
229     }
230 
231     exceptions = list(route_handler.raises or [])
232     if raises_validation_error and ValidationException not in exceptions:
233         exceptions.append(ValidationException)
234     for status_code, response in create_error_responses(exceptions=exceptions):
235         responses[status_code] = response
236 
237     for status_code, response in create_additional_responses(route_handler, plugins):
238         if status_code in responses:
239             raise ImproperlyConfiguredException(
240                 f"Additional response for status code {status_code} already exists in success or error responses"
241             )
242 
243         responses[status_code] = response
244 
245     return responses or None
246
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/starlite/_openapi/responses.py b/starlite/_openapi/responses.py
--- a/starlite/_openapi/responses.py
+++ b/starlite/_openapi/responses.py
@@ -14,7 +14,7 @@
 from starlite._openapi.utils import pascal_case_to_text
 from starlite._signature.models import SignatureField
 from starlite.enums import MediaType
-from starlite.exceptions import HTTPException, ImproperlyConfiguredException, ValidationException
+from starlite.exceptions import HTTPException, ValidationException
 from starlite.response import Response as StarliteResponse
 from starlite.response_containers import File, Redirect, Stream, Template
 from starlite.utils import get_enum_string_value, get_name, is_class_and_subclass
@@ -235,11 +235,6 @@
         responses[status_code] = response
 
     for status_code, response in create_additional_responses(route_handler, plugins):
-        if status_code in responses:
-            raise ImproperlyConfiguredException(
-                f"Additional response for status code {status_code} already exists in success or error responses"
-            )
-
         responses[status_code] = response
 
     return responses or None

{"golden_diff": "diff --git a/starlite/_openapi/responses.py b/starlite/_openapi/responses.py\n--- a/starlite/_openapi/responses.py\n+++ b/starlite/_openapi/responses.py\n@@ -14,7 +14,7 @@\n from starlite._openapi.utils import pascal_case_to_text\n from starlite._signature.models import SignatureField\n from starlite.enums import MediaType\n-from starlite.exceptions import HTTPException, ImproperlyConfiguredException, ValidationException\n+from starlite.exceptions import HTTPException, ValidationException\n from starlite.response import Response as StarliteResponse\n from starlite.response_containers import File, Redirect, Stream, Template\n from starlite.utils import get_enum_string_value, get_name, is_class_and_subclass\n@@ -235,11 +235,6 @@\n         responses[status_code] = response\n \n     for status_code, response in create_additional_responses(route_handler, plugins):\n-        if status_code in responses:\n-            raise ImproperlyConfiguredException(\n-                f\"Additional response for status code {status_code} already exists in success or error responses\"\n-            )\n-\n         responses[status_code] = response\n \n     return responses or None\n", "issue": "Enhancement: Add a way to override default OpenAPI response descriptions\n**What's the feature you'd like to ask for.**\r\nCurrently there is no way to replace the default OpenAPI description for HTTP 400 errors. For example, you currently can't do this:\r\n\r\n```python\r\n@starlite.post(\r\n    \"/path\",\r\n    responses={\r\n        400: starlite.ResponseSpec(\r\n            model=MyErrorModel, description=\"A more detailed error description\"\r\n        )\r\n    },\r\n)\r\nasync def login() -> starlite.Response:\r\n    ...\r\n```\r\n\r\nIf you do, you will get this error on startup:\r\n\r\n```console\r\nstarlite.exceptions.http_exceptions.ImproperlyConfiguredException: 500: Additional response for status code 400 already exists in success or error responses\r\n```\r\n\r\nThis makes it impossible to add more detailed error descriptions or properly document response shapes if you want your endpoint to return a different error shape.\r\n\r\n**Additional context**\r\nRemoving this bit of code would allow the default HTTP 400 description to be replaced:\r\nhttps://github.com/seladb/starlite/blob/51ae7eebda3e6834a6520471bfdb9cad2ab790c5/starlite/openapi/responses.py#L217-L220\r\n\n", "before_files": [{"content": "from copy import copy\nfrom http import HTTPStatus\nfrom operator import attrgetter\nfrom typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Type\n\nfrom pydantic_openapi_schema.v3_1_0 import Response\nfrom pydantic_openapi_schema.v3_1_0.header import Header\nfrom pydantic_openapi_schema.v3_1_0.media_type import MediaType as OpenAPISchemaMediaType\nfrom pydantic_openapi_schema.v3_1_0.schema import Schema\nfrom typing_extensions import get_args, get_origin\n\nfrom starlite._openapi.enums import OpenAPIFormat, OpenAPIType\nfrom starlite._openapi.schema import create_schema\nfrom starlite._openapi.utils import pascal_case_to_text\nfrom starlite._signature.models import SignatureField\nfrom starlite.enums import MediaType\nfrom starlite.exceptions import HTTPException, ImproperlyConfiguredException, ValidationException\nfrom starlite.response import Response as StarliteResponse\nfrom starlite.response_containers import File, Redirect, Stream, Template\nfrom starlite.utils import get_enum_string_value, get_name, is_class_and_subclass\n\n__all__ = (\n    \"create_additional_responses\",\n    \"create_cookie_schema\",\n    \"create_error_responses\",\n    \"create_responses\",\n    \"create_success_response\",\n)\n\n\nif TYPE_CHECKING:\n    from pydantic_openapi_schema.v3_1_0.responses import Responses\n\n    from starlite.datastructures.cookie import Cookie\n    from starlite.handlers.http_handlers import HTTPRouteHandler\n    from starlite.plugins.base import OpenAPISchemaPluginProtocol\n\n\ndef create_cookie_schema(cookie: \"Cookie\") -> Schema:\n    \"\"\"Given a Cookie instance, return its corresponding OpenAPI schema.\n\n    Args:\n        cookie: Cookie\n\n    Returns:\n        Schema\n    \"\"\"\n    cookie_copy = copy(cookie)\n    cookie_copy.value = \"<string>\"\n    value = cookie_copy.to_header(header=\"\")\n    return Schema(description=cookie.description or \"\", example=value)\n\n\ndef create_success_response(\n    route_handler: \"HTTPRouteHandler\", generate_examples: bool, plugins: List[\"OpenAPISchemaPluginProtocol\"]\n) -> Response:\n    \"\"\"Create the schema for a success response.\"\"\"\n    signature = route_handler.signature\n    default_descriptions: Dict[Any, str] = {\n        Stream: \"Stream Response\",\n        Redirect: \"Redirect Response\",\n        File: \"File Download\",\n    }\n    description = (\n        route_handler.response_description\n        or default_descriptions.get(signature.return_annotation)\n        or HTTPStatus(route_handler.status_code).description\n    )\n\n    if signature.return_annotation not in {signature.empty, None, Redirect, File, Stream}:\n        return_annotation = signature.return_annotation\n        if signature.return_annotation is Template:\n            return_annotation = str  # since templates return str\n            route_handler.media_type = get_enum_string_value(MediaType.HTML)\n        elif is_class_and_subclass(get_origin(signature.return_annotation), StarliteResponse):\n            return_annotation = get_args(signature.return_annotation)[0] or Any\n\n        schema = create_schema(\n            field=SignatureField.create(field_type=return_annotation),\n            generate_examples=generate_examples,\n            plugins=plugins,\n        )\n        schema.contentEncoding = route_handler.content_encoding\n        schema.contentMediaType = route_handler.content_media_type\n        response = Response(\n            content={\n                route_handler.media_type: OpenAPISchemaMediaType(\n                    media_type_schema=schema,\n                )\n            },\n            description=description,\n        )\n\n    elif signature.return_annotation is Redirect:\n        response = Response(\n            content=None,\n            description=description,\n            headers={\n                \"location\": Header(\n                    param_schema=Schema(type=OpenAPIType.STRING), description=\"target path for the redirect\"\n                )\n            },\n        )\n\n    elif signature.return_annotation in (File, Stream):\n        response = Response(\n            content={\n                route_handler.media_type: OpenAPISchemaMediaType(\n                    media_type_schema=Schema(\n                        type=OpenAPIType.STRING,\n                        contentEncoding=route_handler.content_encoding or \"application/octet-stream\",\n                        contentMediaType=route_handler.content_media_type,\n                    ),\n                )\n            },\n            description=description,\n            headers={\n                \"content-length\": Header(\n                    param_schema=Schema(type=OpenAPIType.STRING), description=\"File size in bytes\"\n                ),\n                \"last-modified\": Header(\n                    param_schema=Schema(type=OpenAPIType.STRING, schema_format=OpenAPIFormat.DATE_TIME),\n                    description=\"Last modified data-time in RFC 2822 format\",\n                ),\n                \"etag\": Header(param_schema=Schema(type=OpenAPIType.STRING), description=\"Entity tag\"),\n            },\n        )\n\n    else:\n        response = Response(\n            content=None,\n            description=description,\n        )\n\n    if response.headers is None:\n        response.headers = {}\n\n    for response_header in route_handler.resolve_response_headers():\n        header = Header()\n        for attribute_name, attribute_value in response_header.dict(exclude_none=True).items():\n            if attribute_name == \"value\":\n                header.param_schema = create_schema(\n                    field=SignatureField.create(field_type=type(attribute_value)),\n                    generate_examples=False,\n                    plugins=plugins,\n                )\n\n            elif attribute_name != \"documentation_only\":\n                setattr(header, attribute_name, attribute_value)\n        response.headers[response_header.name] = header\n\n    if cookies := route_handler.resolve_response_cookies():\n        response.headers[\"Set-Cookie\"] = Header(\n            param_schema=Schema(\n                allOf=[create_cookie_schema(cookie=cookie) for cookie in sorted(cookies, key=attrgetter(\"key\"))]\n            )\n        )\n\n    return response\n\n\ndef create_error_responses(exceptions: List[Type[HTTPException]]) -> Iterator[Tuple[str, Response]]:\n    \"\"\"Create the schema for error responses, if any.\"\"\"\n    grouped_exceptions: Dict[int, List[Type[HTTPException]]] = {}\n    for exc in exceptions:\n        if not grouped_exceptions.get(exc.status_code):\n            grouped_exceptions[exc.status_code] = []\n        grouped_exceptions[exc.status_code].append(exc)\n    for status_code, exception_group in grouped_exceptions.items():\n        exceptions_schemas = [\n            Schema(\n                type=OpenAPIType.OBJECT,\n                required=[\"detail\", \"status_code\"],\n                properties={\n                    \"status_code\": Schema(type=OpenAPIType.INTEGER),\n                    \"detail\": Schema(type=OpenAPIType.STRING),\n                    \"extra\": Schema(\n                        type=[OpenAPIType.NULL, OpenAPIType.OBJECT, OpenAPIType.ARRAY], additionalProperties=Schema()\n                    ),\n                },\n                description=pascal_case_to_text(get_name(exc)),\n                examples=[{\"status_code\": status_code, \"detail\": HTTPStatus(status_code).phrase, \"extra\": {}}],\n            )\n            for exc in exception_group\n        ]\n        if len(exceptions_schemas) > 1:  # noqa: SIM108\n            schema = Schema(oneOf=exceptions_schemas)  # type:ignore[arg-type]\n        else:\n            schema = exceptions_schemas[0]\n        yield str(status_code), Response(\n            description=HTTPStatus(status_code).description,\n            content={MediaType.JSON: OpenAPISchemaMediaType(media_type_schema=schema)},\n        )\n\n\ndef create_additional_responses(\n    route_handler: \"HTTPRouteHandler\", plugins: List[\"OpenAPISchemaPluginProtocol\"]\n) -> Iterator[Tuple[str, Response]]:\n    \"\"\"Create the schema for additional responses, if any.\"\"\"\n    if not route_handler.responses:\n        return\n\n    for status_code, additional_response in route_handler.responses.items():\n        schema = create_schema(\n            field=SignatureField.create(field_type=additional_response.model),\n            generate_examples=additional_response.generate_examples,\n            plugins=plugins,\n        )\n        yield str(status_code), Response(\n            description=additional_response.description,\n            content={additional_response.media_type: OpenAPISchemaMediaType(media_type_schema=schema)},\n        )\n\n\ndef create_responses(\n    route_handler: \"HTTPRouteHandler\",\n    raises_validation_error: bool,\n    generate_examples: bool,\n    plugins: List[\"OpenAPISchemaPluginProtocol\"],\n) -> Optional[\"Responses\"]:\n    \"\"\"Create a Response model embedded in a `Responses` dictionary for the given RouteHandler or return None.\"\"\"\n\n    responses: \"Responses\" = {\n        str(route_handler.status_code): create_success_response(\n            route_handler=route_handler,\n            generate_examples=generate_examples,\n            plugins=plugins,\n        ),\n    }\n\n    exceptions = list(route_handler.raises or [])\n    if raises_validation_error and ValidationException not in exceptions:\n        exceptions.append(ValidationException)\n    for status_code, response in create_error_responses(exceptions=exceptions):\n        responses[status_code] = response\n\n    for status_code, response in create_additional_responses(route_handler, plugins):\n        if status_code in responses:\n            raise ImproperlyConfiguredException(\n                f\"Additional response for status code {status_code} already exists in success or error responses\"\n            )\n\n        responses[status_code] = response\n\n    return responses or None\n", "path": "starlite/_openapi/responses.py"}], "after_files": [{"content": "from copy import copy\nfrom http import HTTPStatus\nfrom operator import attrgetter\nfrom typing import TYPE_CHECKING, Any, Dict, Iterator, List, Optional, Tuple, Type\n\nfrom pydantic_openapi_schema.v3_1_0 import Response\nfrom pydantic_openapi_schema.v3_1_0.header import Header\nfrom pydantic_openapi_schema.v3_1_0.media_type import MediaType as OpenAPISchemaMediaType\nfrom pydantic_openapi_schema.v3_1_0.schema import Schema\nfrom typing_extensions import get_args, get_origin\n\nfrom starlite._openapi.enums import OpenAPIFormat, OpenAPIType\nfrom starlite._openapi.schema import create_schema\nfrom starlite._openapi.utils import pascal_case_to_text\nfrom starlite._signature.models import SignatureField\nfrom starlite.enums import MediaType\nfrom starlite.exceptions import HTTPException, ValidationException\nfrom starlite.response import Response as StarliteResponse\nfrom starlite.response_containers import File, Redirect, Stream, Template\nfrom starlite.utils import get_enum_string_value, get_name, is_class_and_subclass\n\n__all__ = (\n    \"create_additional_responses\",\n    \"create_cookie_schema\",\n    \"create_error_responses\",\n    \"create_responses\",\n    \"create_success_response\",\n)\n\n\nif TYPE_CHECKING:\n    from pydantic_openapi_schema.v3_1_0.responses import Responses\n\n    from starlite.datastructures.cookie import Cookie\n    from starlite.handlers.http_handlers import HTTPRouteHandler\n    from starlite.plugins.base import OpenAPISchemaPluginProtocol\n\n\ndef create_cookie_schema(cookie: \"Cookie\") -> Schema:\n    \"\"\"Given a Cookie instance, return its corresponding OpenAPI schema.\n\n    Args:\n        cookie: Cookie\n\n    Returns:\n        Schema\n    \"\"\"\n    cookie_copy = copy(cookie)\n    cookie_copy.value = \"<string>\"\n    value = cookie_copy.to_header(header=\"\")\n    return Schema(description=cookie.description or \"\", example=value)\n\n\ndef create_success_response(\n    route_handler: \"HTTPRouteHandler\", generate_examples: bool, plugins: List[\"OpenAPISchemaPluginProtocol\"]\n) -> Response:\n    \"\"\"Create the schema for a success response.\"\"\"\n    signature = route_handler.signature\n    default_descriptions: Dict[Any, str] = {\n        Stream: \"Stream Response\",\n        Redirect: \"Redirect Response\",\n        File: \"File Download\",\n    }\n    description = (\n        route_handler.response_description\n        or default_descriptions.get(signature.return_annotation)\n        or HTTPStatus(route_handler.status_code).description\n    )\n\n    if signature.return_annotation not in {signature.empty, None, Redirect, File, Stream}:\n        return_annotation = signature.return_annotation\n        if signature.return_annotation is Template:\n            return_annotation = str  # since templates return str\n            route_handler.media_type = get_enum_string_value(MediaType.HTML)\n        elif is_class_and_subclass(get_origin(signature.return_annotation), StarliteResponse):\n            return_annotation = get_args(signature.return_annotation)[0] or Any\n\n        schema = create_schema(\n            field=SignatureField.create(field_type=return_annotation),\n            generate_examples=generate_examples,\n            plugins=plugins,\n        )\n        schema.contentEncoding = route_handler.content_encoding\n        schema.contentMediaType = route_handler.content_media_type\n        response = Response(\n            content={\n                route_handler.media_type: OpenAPISchemaMediaType(\n                    media_type_schema=schema,\n                )\n            },\n            description=description,\n        )\n\n    elif signature.return_annotation is Redirect:\n        response = Response(\n            content=None,\n            description=description,\n            headers={\n                \"location\": Header(\n                    param_schema=Schema(type=OpenAPIType.STRING), description=\"target path for the redirect\"\n                )\n            },\n        )\n\n    elif signature.return_annotation in (File, Stream):\n        response = Response(\n            content={\n                route_handler.media_type: OpenAPISchemaMediaType(\n                    media_type_schema=Schema(\n                        type=OpenAPIType.STRING,\n                        contentEncoding=route_handler.content_encoding or \"application/octet-stream\",\n                        contentMediaType=route_handler.content_media_type,\n                    ),\n                )\n            },\n            description=description,\n            headers={\n                \"content-length\": Header(\n                    param_schema=Schema(type=OpenAPIType.STRING), description=\"File size in bytes\"\n                ),\n                \"last-modified\": Header(\n                    param_schema=Schema(type=OpenAPIType.STRING, schema_format=OpenAPIFormat.DATE_TIME),\n                    description=\"Last modified data-time in RFC 2822 format\",\n                ),\n                \"etag\": Header(param_schema=Schema(type=OpenAPIType.STRING), description=\"Entity tag\"),\n            },\n        )\n\n    else:\n        response = Response(\n            content=None,\n            description=description,\n        )\n\n    if response.headers is None:\n        response.headers = {}\n\n    for response_header in route_handler.resolve_response_headers():\n        header = Header()\n        for attribute_name, attribute_value in response_header.dict(exclude_none=True).items():\n            if attribute_name == \"value\":\n                header.param_schema = create_schema(\n                    field=SignatureField.create(field_type=type(attribute_value)),\n                    generate_examples=False,\n                    plugins=plugins,\n                )\n\n            elif attribute_name != \"documentation_only\":\n                setattr(header, attribute_name, attribute_value)\n        response.headers[response_header.name] = header\n\n    if cookies := route_handler.resolve_response_cookies():\n        response.headers[\"Set-Cookie\"] = Header(\n            param_schema=Schema(\n                allOf=[create_cookie_schema(cookie=cookie) for cookie in sorted(cookies, key=attrgetter(\"key\"))]\n            )\n        )\n\n    return response\n\n\ndef create_error_responses(exceptions: List[Type[HTTPException]]) -> Iterator[Tuple[str, Response]]:\n    \"\"\"Create the schema for error responses, if any.\"\"\"\n    grouped_exceptions: Dict[int, List[Type[HTTPException]]] = {}\n    for exc in exceptions:\n        if not grouped_exceptions.get(exc.status_code):\n            grouped_exceptions[exc.status_code] = []\n        grouped_exceptions[exc.status_code].append(exc)\n    for status_code, exception_group in grouped_exceptions.items():\n        exceptions_schemas = [\n            Schema(\n                type=OpenAPIType.OBJECT,\n                required=[\"detail\", \"status_code\"],\n                properties={\n                    \"status_code\": Schema(type=OpenAPIType.INTEGER),\n                    \"detail\": Schema(type=OpenAPIType.STRING),\n                    \"extra\": Schema(\n                        type=[OpenAPIType.NULL, OpenAPIType.OBJECT, OpenAPIType.ARRAY], additionalProperties=Schema()\n                    ),\n                },\n                description=pascal_case_to_text(get_name(exc)),\n                examples=[{\"status_code\": status_code, \"detail\": HTTPStatus(status_code).phrase, \"extra\": {}}],\n            )\n            for exc in exception_group\n        ]\n        if len(exceptions_schemas) > 1:  # noqa: SIM108\n            schema = Schema(oneOf=exceptions_schemas)  # type:ignore[arg-type]\n        else:\n            schema = exceptions_schemas[0]\n        yield str(status_code), Response(\n            description=HTTPStatus(status_code).description,\n            content={MediaType.JSON: OpenAPISchemaMediaType(media_type_schema=schema)},\n        )\n\n\ndef create_additional_responses(\n    route_handler: \"HTTPRouteHandler\", plugins: List[\"OpenAPISchemaPluginProtocol\"]\n) -> Iterator[Tuple[str, Response]]:\n    \"\"\"Create the schema for additional responses, if any.\"\"\"\n    if not route_handler.responses:\n        return\n\n    for status_code, additional_response in route_handler.responses.items():\n        schema = create_schema(\n            field=SignatureField.create(field_type=additional_response.model),\n            generate_examples=additional_response.generate_examples,\n            plugins=plugins,\n        )\n        yield str(status_code), Response(\n            description=additional_response.description,\n            content={additional_response.media_type: OpenAPISchemaMediaType(media_type_schema=schema)},\n        )\n\n\ndef create_responses(\n    route_handler: \"HTTPRouteHandler\",\n    raises_validation_error: bool,\n    generate_examples: bool,\n    plugins: List[\"OpenAPISchemaPluginProtocol\"],\n) -> Optional[\"Responses\"]:\n    \"\"\"Create a Response model embedded in a `Responses` dictionary for the given RouteHandler or return None.\"\"\"\n\n    responses: \"Responses\" = {\n        str(route_handler.status_code): create_success_response(\n            route_handler=route_handler,\n            generate_examples=generate_examples,\n            plugins=plugins,\n        ),\n    }\n\n    exceptions = list(route_handler.raises or [])\n    if raises_validation_error and ValidationException not in exceptions:\n        exceptions.append(ValidationException)\n    for status_code, response in create_error_responses(exceptions=exceptions):\n        responses[status_code] = response\n\n    for status_code, response in create_additional_responses(route_handler, plugins):\n        responses[status_code] = response\n\n    return responses or None\n", "path": "starlite/_openapi/responses.py"}]}