We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
StaticFilesConfig and virtual directories
I'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. 

This is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.

https://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `litestar/_openapi/responses.py`
Content:
```
1 from __future__ import annotations
2 
3 import re
4 from copy import copy
5 from dataclasses import asdict
6 from http import HTTPStatus
7 from inspect import Signature
8 from operator import attrgetter
9 from typing import TYPE_CHECKING, Any, Iterator
10 
11 from litestar._openapi.schema_generation import create_schema
12 from litestar._signature.field import SignatureField
13 from litestar.enums import MediaType
14 from litestar.exceptions import HTTPException, ValidationException
15 from litestar.openapi.spec import OpenAPIResponse
16 from litestar.openapi.spec.enums import OpenAPIFormat, OpenAPIType
17 from litestar.openapi.spec.header import OpenAPIHeader
18 from litestar.openapi.spec.media_type import OpenAPIMediaType
19 from litestar.openapi.spec.schema import Schema
20 from litestar.response import (
21     File,
22     Redirect,
23     Stream,
24     Template,
25 )
26 from litestar.response import (
27     Response as LitestarResponse,
28 )
29 from litestar.response.base import ASGIResponse
30 from litestar.types.builtin_types import NoneType
31 from litestar.utils import get_enum_string_value, get_name
32 
33 if TYPE_CHECKING:
34     from litestar.datastructures.cookie import Cookie
35     from litestar.handlers.http_handlers import HTTPRouteHandler
36     from litestar.openapi.spec.responses import Responses
37     from litestar.plugins import OpenAPISchemaPluginProtocol
38 
39 
40 __all__ = (
41     "create_additional_responses",
42     "create_cookie_schema",
43     "create_error_responses",
44     "create_responses",
45     "create_success_response",
46 )
47 
48 CAPITAL_LETTERS_PATTERN = re.compile(r"(?=[A-Z])")
49 
50 
51 def pascal_case_to_text(string: str) -> str:
52     """Given a 'PascalCased' string, return its split form- 'Pascal Cased'."""
53     return " ".join(re.split(CAPITAL_LETTERS_PATTERN, string)).strip()
54 
55 
56 def create_cookie_schema(cookie: Cookie) -> Schema:
57     """Given a Cookie instance, return its corresponding OpenAPI schema.
58 
59     Args:
60         cookie: Cookie
61 
62     Returns:
63         Schema
64     """
65     cookie_copy = copy(cookie)
66     cookie_copy.value = "<string>"
67     value = cookie_copy.to_header(header="")
68     return Schema(description=cookie.description or "", example=value)
69 
70 
71 def create_success_response(  # noqa: C901
72     route_handler: HTTPRouteHandler,
73     generate_examples: bool,
74     plugins: list[OpenAPISchemaPluginProtocol],
75     schemas: dict[str, Schema],
76 ) -> OpenAPIResponse:
77     """Create the schema for a success response."""
78     return_type = route_handler.parsed_fn_signature.return_type
79     return_annotation = return_type.annotation
80     default_descriptions: dict[Any, str] = {
81         Stream: "Stream Response",
82         Redirect: "Redirect Response",
83         File: "File Download",
84     }
85     description = (
86         route_handler.response_description
87         or default_descriptions.get(return_annotation)
88         or HTTPStatus(route_handler.status_code).description
89     )
90 
91     if return_annotation is not Signature.empty and not return_type.is_subclass_of(
92         (NoneType, File, Redirect, Stream, ASGIResponse)
93     ):
94         if return_annotation is Template:
95             return_annotation = str
96             route_handler.media_type = get_enum_string_value(MediaType.HTML)
97         elif return_type.is_subclass_of(LitestarResponse):
98             return_annotation = return_type.inner_types[0].annotation if return_type.inner_types else Any
99             if not route_handler.media_type:
100                 route_handler.media_type = get_enum_string_value(MediaType.JSON)
101 
102         if dto := route_handler.resolve_return_dto():
103             result = dto.create_openapi_schema("return", str(route_handler), generate_examples, schemas, False)
104         else:
105             result = create_schema(
106                 field=SignatureField.create(field_type=return_annotation),
107                 generate_examples=generate_examples,
108                 plugins=plugins,
109                 schemas=schemas,
110                 prefer_alias=False,
111             )
112 
113         schema = result if isinstance(result, Schema) else schemas[result.value]
114 
115         schema.content_encoding = route_handler.content_encoding
116         schema.content_media_type = route_handler.content_media_type
117 
118         response = OpenAPIResponse(
119             content={route_handler.media_type: OpenAPIMediaType(schema=result)},
120             description=description,
121         )
122 
123     elif return_type.is_subclass_of(Redirect):
124         response = OpenAPIResponse(
125             content=None,
126             description=description,
127             headers={
128                 "location": OpenAPIHeader(
129                     schema=Schema(type=OpenAPIType.STRING), description="target path for the redirect"
130                 )
131             },
132         )
133 
134     elif return_type.is_subclass_of((File, Stream)):
135         response = OpenAPIResponse(
136             content={
137                 route_handler.media_type: OpenAPIMediaType(
138                     schema=Schema(
139                         type=OpenAPIType.STRING,
140                         content_encoding=route_handler.content_encoding or "application/octet-stream",
141                         content_media_type=route_handler.content_media_type,
142                     ),
143                 )
144             },
145             description=description,
146             headers={
147                 "content-length": OpenAPIHeader(
148                     schema=Schema(type=OpenAPIType.STRING), description="File size in bytes"
149                 ),
150                 "last-modified": OpenAPIHeader(
151                     schema=Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.DATE_TIME),
152                     description="Last modified data-time in RFC 2822 format",
153                 ),
154                 "etag": OpenAPIHeader(schema=Schema(type=OpenAPIType.STRING), description="Entity tag"),
155             },
156         )
157 
158     else:
159         response = OpenAPIResponse(
160             content=None,
161             description=description,
162         )
163 
164     if response.headers is None:
165         response.headers = {}
166 
167     for response_header in route_handler.resolve_response_headers():
168         header = OpenAPIHeader()
169         for attribute_name, attribute_value in ((k, v) for k, v in asdict(response_header).items() if v is not None):
170             if attribute_name == "value":
171                 header.schema = create_schema(
172                     field=SignatureField.create(field_type=type(attribute_value)),
173                     generate_examples=False,
174                     plugins=plugins,
175                     schemas=schemas,
176                     prefer_alias=False,
177                 )
178 
179             elif attribute_name != "documentation_only":
180                 setattr(header, attribute_name, attribute_value)
181 
182         response.headers[response_header.name] = header
183 
184     if cookies := route_handler.resolve_response_cookies():
185         response.headers["Set-Cookie"] = OpenAPIHeader(
186             schema=Schema(
187                 all_of=[create_cookie_schema(cookie=cookie) for cookie in sorted(cookies, key=attrgetter("key"))]
188             )
189         )
190 
191     return response
192 
193 
194 def create_error_responses(exceptions: list[type[HTTPException]]) -> Iterator[tuple[str, OpenAPIResponse]]:
195     """Create the schema for error responses, if any."""
196     grouped_exceptions: dict[int, list[type[HTTPException]]] = {}
197     for exc in exceptions:
198         if not grouped_exceptions.get(exc.status_code):
199             grouped_exceptions[exc.status_code] = []
200         grouped_exceptions[exc.status_code].append(exc)
201     for status_code, exception_group in grouped_exceptions.items():
202         exceptions_schemas = [
203             Schema(
204                 type=OpenAPIType.OBJECT,
205                 required=["detail", "status_code"],
206                 properties={
207                     "status_code": Schema(type=OpenAPIType.INTEGER),
208                     "detail": Schema(type=OpenAPIType.STRING),
209                     "extra": Schema(
210                         type=[OpenAPIType.NULL, OpenAPIType.OBJECT, OpenAPIType.ARRAY], additional_properties=Schema()
211                     ),
212                 },
213                 description=pascal_case_to_text(get_name(exc)),
214                 examples=[{"status_code": status_code, "detail": HTTPStatus(status_code).phrase, "extra": {}}],
215             )
216             for exc in exception_group
217         ]
218         if len(exceptions_schemas) > 1:  # noqa: SIM108
219             schema = Schema(one_of=exceptions_schemas)
220         else:
221             schema = exceptions_schemas[0]
222         yield str(status_code), OpenAPIResponse(
223             description=HTTPStatus(status_code).description,
224             content={MediaType.JSON: OpenAPIMediaType(schema=schema)},
225         )
226 
227 
228 def create_additional_responses(
229     route_handler: HTTPRouteHandler,
230     plugins: list[OpenAPISchemaPluginProtocol],
231     schemas: dict[str, Schema],
232 ) -> Iterator[tuple[str, OpenAPIResponse]]:
233     """Create the schema for additional responses, if any."""
234     if not route_handler.responses:
235         return
236 
237     for status_code, additional_response in route_handler.responses.items():
238         schema = create_schema(
239             field=SignatureField.create(field_type=additional_response.data_container),
240             generate_examples=additional_response.generate_examples,
241             plugins=plugins,
242             schemas=schemas,
243             prefer_alias=False,
244         )
245         yield str(status_code), OpenAPIResponse(
246             description=additional_response.description,
247             content={additional_response.media_type: OpenAPIMediaType(schema=schema)},
248         )
249 
250 
251 def create_responses(
252     route_handler: HTTPRouteHandler,
253     raises_validation_error: bool,
254     generate_examples: bool,
255     plugins: list[OpenAPISchemaPluginProtocol],
256     schemas: dict[str, Schema],
257 ) -> Responses | None:
258     """Create a Response model embedded in a `Responses` dictionary for the given RouteHandler or return None."""
259 
260     responses: Responses = {
261         str(route_handler.status_code): create_success_response(
262             generate_examples=generate_examples, plugins=plugins, route_handler=route_handler, schemas=schemas
263         ),
264     }
265 
266     exceptions = list(route_handler.raises or [])
267     if raises_validation_error and ValidationException not in exceptions:
268         exceptions.append(ValidationException)
269     for status_code, response in create_error_responses(exceptions=exceptions):
270         responses[status_code] = response
271 
272     for status_code, response in create_additional_responses(
273         route_handler=route_handler, plugins=plugins, schemas=schemas
274     ):
275         responses[status_code] = response
276 
277     return responses or None
278
```
--- 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/litestar/_openapi/responses.py b/litestar/_openapi/responses.py
--- a/litestar/_openapi/responses.py
+++ b/litestar/_openapi/responses.py
@@ -91,13 +91,13 @@
     if return_annotation is not Signature.empty and not return_type.is_subclass_of(
         (NoneType, File, Redirect, Stream, ASGIResponse)
     ):
+        media_type = route_handler.media_type
         if return_annotation is Template:
             return_annotation = str
-            route_handler.media_type = get_enum_string_value(MediaType.HTML)
+            media_type = media_type or MediaType.HTML
         elif return_type.is_subclass_of(LitestarResponse):
             return_annotation = return_type.inner_types[0].annotation if return_type.inner_types else Any
-            if not route_handler.media_type:
-                route_handler.media_type = get_enum_string_value(MediaType.JSON)
+            media_type = media_type or MediaType.JSON
 
         if dto := route_handler.resolve_return_dto():
             result = dto.create_openapi_schema("return", str(route_handler), generate_examples, schemas, False)
@@ -116,8 +116,7 @@
         schema.content_media_type = route_handler.content_media_type
 
         response = OpenAPIResponse(
-            content={route_handler.media_type: OpenAPIMediaType(schema=result)},
-            description=description,
+            content={get_enum_string_value(media_type): OpenAPIMediaType(schema=result)}, description=description
         )
 
     elif return_type.is_subclass_of(Redirect):

{"golden_diff": "diff --git a/litestar/_openapi/responses.py b/litestar/_openapi/responses.py\n--- a/litestar/_openapi/responses.py\n+++ b/litestar/_openapi/responses.py\n@@ -91,13 +91,13 @@\n     if return_annotation is not Signature.empty and not return_type.is_subclass_of(\n         (NoneType, File, Redirect, Stream, ASGIResponse)\n     ):\n+        media_type = route_handler.media_type\n         if return_annotation is Template:\n             return_annotation = str\n-            route_handler.media_type = get_enum_string_value(MediaType.HTML)\n+            media_type = media_type or MediaType.HTML\n         elif return_type.is_subclass_of(LitestarResponse):\n             return_annotation = return_type.inner_types[0].annotation if return_type.inner_types else Any\n-            if not route_handler.media_type:\n-                route_handler.media_type = get_enum_string_value(MediaType.JSON)\n+            media_type = media_type or MediaType.JSON\n \n         if dto := route_handler.resolve_return_dto():\n             result = dto.create_openapi_schema(\"return\", str(route_handler), generate_examples, schemas, False)\n@@ -116,8 +116,7 @@\n         schema.content_media_type = route_handler.content_media_type\n \n         response = OpenAPIResponse(\n-            content={route_handler.media_type: OpenAPIMediaType(schema=result)},\n-            description=description,\n+            content={get_enum_string_value(media_type): OpenAPIMediaType(schema=result)}, description=description\n         )\n \n     elif return_type.is_subclass_of(Redirect):\n", "issue": "StaticFilesConfig and virtual directories\nI'm trying to write a ``FileSystemProtocol`` to load files from the package data using [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/using.html#). But because ``directories`` is defined as ``DirectoryPath``, pydantic checks if the given directories exist in the local filesystem. \r\n\r\nThis is not generally true, especially in any kind of virtual filesystem (e.g. a zipped package). I think this condition should be relaxed to support virtual filesystems.\r\n\r\nhttps://github.com/starlite-api/starlite/blob/9bb6dcd57c10a591377cf8e3a537e9292566d5b9/starlite/config/static_files.py#L32\n", "before_files": [{"content": "from __future__ import annotations\n\nimport re\nfrom copy import copy\nfrom dataclasses import asdict\nfrom http import HTTPStatus\nfrom inspect import Signature\nfrom operator import attrgetter\nfrom typing import TYPE_CHECKING, Any, Iterator\n\nfrom litestar._openapi.schema_generation import create_schema\nfrom litestar._signature.field import SignatureField\nfrom litestar.enums import MediaType\nfrom litestar.exceptions import HTTPException, ValidationException\nfrom litestar.openapi.spec import OpenAPIResponse\nfrom litestar.openapi.spec.enums import OpenAPIFormat, OpenAPIType\nfrom litestar.openapi.spec.header import OpenAPIHeader\nfrom litestar.openapi.spec.media_type import OpenAPIMediaType\nfrom litestar.openapi.spec.schema import Schema\nfrom litestar.response import (\n    File,\n    Redirect,\n    Stream,\n    Template,\n)\nfrom litestar.response import (\n    Response as LitestarResponse,\n)\nfrom litestar.response.base import ASGIResponse\nfrom litestar.types.builtin_types import NoneType\nfrom litestar.utils import get_enum_string_value, get_name\n\nif TYPE_CHECKING:\n    from litestar.datastructures.cookie import Cookie\n    from litestar.handlers.http_handlers import HTTPRouteHandler\n    from litestar.openapi.spec.responses import Responses\n    from litestar.plugins import OpenAPISchemaPluginProtocol\n\n\n__all__ = (\n    \"create_additional_responses\",\n    \"create_cookie_schema\",\n    \"create_error_responses\",\n    \"create_responses\",\n    \"create_success_response\",\n)\n\nCAPITAL_LETTERS_PATTERN = re.compile(r\"(?=[A-Z])\")\n\n\ndef pascal_case_to_text(string: str) -> str:\n    \"\"\"Given a 'PascalCased' string, return its split form- 'Pascal Cased'.\"\"\"\n    return \" \".join(re.split(CAPITAL_LETTERS_PATTERN, string)).strip()\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(  # noqa: C901\n    route_handler: HTTPRouteHandler,\n    generate_examples: bool,\n    plugins: list[OpenAPISchemaPluginProtocol],\n    schemas: dict[str, Schema],\n) -> OpenAPIResponse:\n    \"\"\"Create the schema for a success response.\"\"\"\n    return_type = route_handler.parsed_fn_signature.return_type\n    return_annotation = return_type.annotation\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(return_annotation)\n        or HTTPStatus(route_handler.status_code).description\n    )\n\n    if return_annotation is not Signature.empty and not return_type.is_subclass_of(\n        (NoneType, File, Redirect, Stream, ASGIResponse)\n    ):\n        if return_annotation is Template:\n            return_annotation = str\n            route_handler.media_type = get_enum_string_value(MediaType.HTML)\n        elif return_type.is_subclass_of(LitestarResponse):\n            return_annotation = return_type.inner_types[0].annotation if return_type.inner_types else Any\n            if not route_handler.media_type:\n                route_handler.media_type = get_enum_string_value(MediaType.JSON)\n\n        if dto := route_handler.resolve_return_dto():\n            result = dto.create_openapi_schema(\"return\", str(route_handler), generate_examples, schemas, False)\n        else:\n            result = create_schema(\n                field=SignatureField.create(field_type=return_annotation),\n                generate_examples=generate_examples,\n                plugins=plugins,\n                schemas=schemas,\n                prefer_alias=False,\n            )\n\n        schema = result if isinstance(result, Schema) else schemas[result.value]\n\n        schema.content_encoding = route_handler.content_encoding\n        schema.content_media_type = route_handler.content_media_type\n\n        response = OpenAPIResponse(\n            content={route_handler.media_type: OpenAPIMediaType(schema=result)},\n            description=description,\n        )\n\n    elif return_type.is_subclass_of(Redirect):\n        response = OpenAPIResponse(\n            content=None,\n            description=description,\n            headers={\n                \"location\": OpenAPIHeader(\n                    schema=Schema(type=OpenAPIType.STRING), description=\"target path for the redirect\"\n                )\n            },\n        )\n\n    elif return_type.is_subclass_of((File, Stream)):\n        response = OpenAPIResponse(\n            content={\n                route_handler.media_type: OpenAPIMediaType(\n                    schema=Schema(\n                        type=OpenAPIType.STRING,\n                        content_encoding=route_handler.content_encoding or \"application/octet-stream\",\n                        content_media_type=route_handler.content_media_type,\n                    ),\n                )\n            },\n            description=description,\n            headers={\n                \"content-length\": OpenAPIHeader(\n                    schema=Schema(type=OpenAPIType.STRING), description=\"File size in bytes\"\n                ),\n                \"last-modified\": OpenAPIHeader(\n                    schema=Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.DATE_TIME),\n                    description=\"Last modified data-time in RFC 2822 format\",\n                ),\n                \"etag\": OpenAPIHeader(schema=Schema(type=OpenAPIType.STRING), description=\"Entity tag\"),\n            },\n        )\n\n    else:\n        response = OpenAPIResponse(\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 = OpenAPIHeader()\n        for attribute_name, attribute_value in ((k, v) for k, v in asdict(response_header).items() if v is not None):\n            if attribute_name == \"value\":\n                header.schema = create_schema(\n                    field=SignatureField.create(field_type=type(attribute_value)),\n                    generate_examples=False,\n                    plugins=plugins,\n                    schemas=schemas,\n                    prefer_alias=False,\n                )\n\n            elif attribute_name != \"documentation_only\":\n                setattr(header, attribute_name, attribute_value)\n\n        response.headers[response_header.name] = header\n\n    if cookies := route_handler.resolve_response_cookies():\n        response.headers[\"Set-Cookie\"] = OpenAPIHeader(\n            schema=Schema(\n                all_of=[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, OpenAPIResponse]]:\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], additional_properties=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(one_of=exceptions_schemas)\n        else:\n            schema = exceptions_schemas[0]\n        yield str(status_code), OpenAPIResponse(\n            description=HTTPStatus(status_code).description,\n            content={MediaType.JSON: OpenAPIMediaType(schema=schema)},\n        )\n\n\ndef create_additional_responses(\n    route_handler: HTTPRouteHandler,\n    plugins: list[OpenAPISchemaPluginProtocol],\n    schemas: dict[str, Schema],\n) -> Iterator[tuple[str, OpenAPIResponse]]:\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.data_container),\n            generate_examples=additional_response.generate_examples,\n            plugins=plugins,\n            schemas=schemas,\n            prefer_alias=False,\n        )\n        yield str(status_code), OpenAPIResponse(\n            description=additional_response.description,\n            content={additional_response.media_type: OpenAPIMediaType(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    schemas: dict[str, Schema],\n) -> Responses | None:\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            generate_examples=generate_examples, plugins=plugins, route_handler=route_handler, schemas=schemas\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(\n        route_handler=route_handler, plugins=plugins, schemas=schemas\n    ):\n        responses[status_code] = response\n\n    return responses or None\n", "path": "litestar/_openapi/responses.py"}], "after_files": [{"content": "from __future__ import annotations\n\nimport re\nfrom copy import copy\nfrom dataclasses import asdict\nfrom http import HTTPStatus\nfrom inspect import Signature\nfrom operator import attrgetter\nfrom typing import TYPE_CHECKING, Any, Iterator\n\nfrom litestar._openapi.schema_generation import create_schema\nfrom litestar._signature.field import SignatureField\nfrom litestar.enums import MediaType\nfrom litestar.exceptions import HTTPException, ValidationException\nfrom litestar.openapi.spec import OpenAPIResponse\nfrom litestar.openapi.spec.enums import OpenAPIFormat, OpenAPIType\nfrom litestar.openapi.spec.header import OpenAPIHeader\nfrom litestar.openapi.spec.media_type import OpenAPIMediaType\nfrom litestar.openapi.spec.schema import Schema\nfrom litestar.response import (\n    File,\n    Redirect,\n    Stream,\n    Template,\n)\nfrom litestar.response import (\n    Response as LitestarResponse,\n)\nfrom litestar.response.base import ASGIResponse\nfrom litestar.types.builtin_types import NoneType\nfrom litestar.utils import get_enum_string_value, get_name\n\nif TYPE_CHECKING:\n    from litestar.datastructures.cookie import Cookie\n    from litestar.handlers.http_handlers import HTTPRouteHandler\n    from litestar.openapi.spec.responses import Responses\n    from litestar.plugins import OpenAPISchemaPluginProtocol\n\n\n__all__ = (\n    \"create_additional_responses\",\n    \"create_cookie_schema\",\n    \"create_error_responses\",\n    \"create_responses\",\n    \"create_success_response\",\n)\n\nCAPITAL_LETTERS_PATTERN = re.compile(r\"(?=[A-Z])\")\n\n\ndef pascal_case_to_text(string: str) -> str:\n    \"\"\"Given a 'PascalCased' string, return its split form- 'Pascal Cased'.\"\"\"\n    return \" \".join(re.split(CAPITAL_LETTERS_PATTERN, string)).strip()\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(  # noqa: C901\n    route_handler: HTTPRouteHandler,\n    generate_examples: bool,\n    plugins: list[OpenAPISchemaPluginProtocol],\n    schemas: dict[str, Schema],\n) -> OpenAPIResponse:\n    \"\"\"Create the schema for a success response.\"\"\"\n    return_type = route_handler.parsed_fn_signature.return_type\n    return_annotation = return_type.annotation\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(return_annotation)\n        or HTTPStatus(route_handler.status_code).description\n    )\n\n    if return_annotation is not Signature.empty and not return_type.is_subclass_of(\n        (NoneType, File, Redirect, Stream, ASGIResponse)\n    ):\n        media_type = route_handler.media_type\n        if return_annotation is Template:\n            return_annotation = str\n            media_type = media_type or MediaType.HTML\n        elif return_type.is_subclass_of(LitestarResponse):\n            return_annotation = return_type.inner_types[0].annotation if return_type.inner_types else Any\n            media_type = media_type or MediaType.JSON\n\n        if dto := route_handler.resolve_return_dto():\n            result = dto.create_openapi_schema(\"return\", str(route_handler), generate_examples, schemas, False)\n        else:\n            result = create_schema(\n                field=SignatureField.create(field_type=return_annotation),\n                generate_examples=generate_examples,\n                plugins=plugins,\n                schemas=schemas,\n                prefer_alias=False,\n            )\n\n        schema = result if isinstance(result, Schema) else schemas[result.value]\n\n        schema.content_encoding = route_handler.content_encoding\n        schema.content_media_type = route_handler.content_media_type\n\n        response = OpenAPIResponse(\n            content={get_enum_string_value(media_type): OpenAPIMediaType(schema=result)}, description=description\n        )\n\n    elif return_type.is_subclass_of(Redirect):\n        response = OpenAPIResponse(\n            content=None,\n            description=description,\n            headers={\n                \"location\": OpenAPIHeader(\n                    schema=Schema(type=OpenAPIType.STRING), description=\"target path for the redirect\"\n                )\n            },\n        )\n\n    elif return_type.is_subclass_of((File, Stream)):\n        response = OpenAPIResponse(\n            content={\n                route_handler.media_type: OpenAPIMediaType(\n                    schema=Schema(\n                        type=OpenAPIType.STRING,\n                        content_encoding=route_handler.content_encoding or \"application/octet-stream\",\n                        content_media_type=route_handler.content_media_type,\n                    ),\n                )\n            },\n            description=description,\n            headers={\n                \"content-length\": OpenAPIHeader(\n                    schema=Schema(type=OpenAPIType.STRING), description=\"File size in bytes\"\n                ),\n                \"last-modified\": OpenAPIHeader(\n                    schema=Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.DATE_TIME),\n                    description=\"Last modified data-time in RFC 2822 format\",\n                ),\n                \"etag\": OpenAPIHeader(schema=Schema(type=OpenAPIType.STRING), description=\"Entity tag\"),\n            },\n        )\n\n    else:\n        response = OpenAPIResponse(\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 = OpenAPIHeader()\n        for attribute_name, attribute_value in ((k, v) for k, v in asdict(response_header).items() if v is not None):\n            if attribute_name == \"value\":\n                header.schema = create_schema(\n                    field=SignatureField.create(field_type=type(attribute_value)),\n                    generate_examples=False,\n                    plugins=plugins,\n                    schemas=schemas,\n                    prefer_alias=False,\n                )\n\n            elif attribute_name != \"documentation_only\":\n                setattr(header, attribute_name, attribute_value)\n\n        response.headers[response_header.name] = header\n\n    if cookies := route_handler.resolve_response_cookies():\n        response.headers[\"Set-Cookie\"] = OpenAPIHeader(\n            schema=Schema(\n                all_of=[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, OpenAPIResponse]]:\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], additional_properties=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(one_of=exceptions_schemas)\n        else:\n            schema = exceptions_schemas[0]\n        yield str(status_code), OpenAPIResponse(\n            description=HTTPStatus(status_code).description,\n            content={MediaType.JSON: OpenAPIMediaType(schema=schema)},\n        )\n\n\ndef create_additional_responses(\n    route_handler: HTTPRouteHandler,\n    plugins: list[OpenAPISchemaPluginProtocol],\n    schemas: dict[str, Schema],\n) -> Iterator[tuple[str, OpenAPIResponse]]:\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.data_container),\n            generate_examples=additional_response.generate_examples,\n            plugins=plugins,\n            schemas=schemas,\n            prefer_alias=False,\n        )\n        yield str(status_code), OpenAPIResponse(\n            description=additional_response.description,\n            content={additional_response.media_type: OpenAPIMediaType(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    schemas: dict[str, Schema],\n) -> Responses | None:\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            generate_examples=generate_examples, plugins=plugins, route_handler=route_handler, schemas=schemas\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(\n        route_handler=route_handler, plugins=plugins, schemas=schemas\n    ):\n        responses[status_code] = response\n\n    return responses or None\n", "path": "litestar/_openapi/responses.py"}]}