Repository: litestar-org/litestar

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


Discussion:
I agree. Do you want to submit a PR?

Resolving patch:
diff --git a/litestar/_openapi/schema_generation/schema.py b/litestar/_openapi/schema_generation/schema.py
--- a/litestar/_openapi/schema_generation/schema.py
+++ b/litestar/_openapi/schema_generation/schema.py
@@ -265,12 +265,8 @@
     time: Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.DURATION),
     timedelta: Schema(type=OpenAPIType.STRING, format=OpenAPIFormat.DURATION),
     tuple: Schema(type=OpenAPIType.ARRAY),
-    # litestar types,
-    # the following is a hack -https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
-    # the format for OA 3.1 is type + contentMediaType, for 3.0.* is type + format, we do both.
     UploadFile: Schema(
         type=OpenAPIType.STRING,
-        format="binary",  # type: ignore
         content_media_type="application/octet-stream",
     ),
     # pydantic types
diff --git a/litestar/datastructures/upload_file.py b/litestar/datastructures/upload_file.py
--- a/litestar/datastructures/upload_file.py
+++ b/litestar/datastructures/upload_file.py
@@ -119,6 +119,4 @@ def __modify_schema__(cls, field_schema: dict[str, Any], field: ModelField | Non
             None
         """
         if field:
-            field_schema.update(
-                {"type": OpenAPIType.STRING.value, "contentMediaType": "application/octet-stream", "format": "binary"}
-            )
+            field_schema.update({"type": OpenAPIType.STRING.value, "contentMediaType": "application/octet-stream"})
diff --git a/litestar/openapi/controller.py b/litestar/openapi/controller.py
--- a/litestar/openapi/controller.py
+++ b/litestar/openapi/controller.py
@@ -1,6 +1,5 @@
 from __future__ import annotations
 
-from copy import copy
 from functools import cached_property
 from typing import TYPE_CHECKING, Callable, Literal
 
@@ -32,7 +31,7 @@ class OpenAPIController(Controller):
     """Base styling of the html body."""
     redoc_version: str = "next"
     """Redoc version to download from the CDN."""
-    swagger_ui_version: str = "4.15.5"
+    swagger_ui_version: str = "5.0.0"
     """SwaggerUI version to download from the CDN."""
     stoplight_elements_version: str = "7.7.5"
     """StopLight Elements version to download from the CDN."""
@@ -261,13 +260,6 @@ def render_swagger_ui(self, request: Request) -> bytes:
         """
         schema = self.get_schema_from_request(request)
 
-        # Note: Fix for Swagger rejection OpenAPI >=3.1
-        if not self._dumped_modified_schema:
-            schema_copy = copy(schema)
-            schema_copy.openapi = "3.0.3"
-
-            self._dumped_modified_schema = encode_json(schema_copy.to_schema()).decode("utf-8")
-
         head = f"""
           <head>
             <title>{schema.info.title}</title>
@@ -286,7 +278,7 @@ def render_swagger_ui(self, request: Request) -> bytes:
             <div id='swagger-container'/>
             <script type="text/javascript">
             const ui = SwaggerUIBundle({{
-                spec: {self._dumped_modified_schema},
+                spec: {encode_json(schema.to_schema()).decode("utf-8")},
                 dom_id: '#swagger-container',
                 deepLinking: true,
                 showExtensions: true,


Test patch:
diff --git a/tests/openapi/test_controller.py b/tests/openapi/test_controller.py
--- a/tests/openapi/test_controller.py
+++ b/tests/openapi/test_controller.py
@@ -169,7 +169,7 @@ def test_openapi_swagger_caching_schema(
         client.get("/schema/redoc")  # Cache the schema
         response = client.get("/schema/swagger")  # Request swagger, should use a different cache
 
-        assert "3.0.3" in response.text  # Make sure the injected version is still there
+        assert "3.1.0" in response.text  # Make sure the injected version is still there
         assert response.status_code == HTTP_200_OK
         assert response.headers["content-type"].startswith(MediaType.HTML.value)
 
diff --git a/tests/openapi/test_request_body.py b/tests/openapi/test_request_body.py
--- a/tests/openapi/test_request_body.py
+++ b/tests/openapi/test_request_body.py
@@ -60,11 +60,10 @@ async def handle_file_list_upload(
     components = schema_dict["components"]
     assert paths["/file-upload"]["post"]["requestBody"]["content"]["multipart/form-data"]["schema"] == {
         "type": "string",
-        "format": "binary",
         "contentMediaType": "application/octet-stream",
     }
     assert paths["/file-list-upload"]["post"]["requestBody"]["content"]["multipart/form-data"]["schema"] == {
-        "items": {"type": "string", "format": "binary", "contentMediaType": "application/octet-stream"},
+        "items": {"type": "string", "contentMediaType": "application/octet-stream"},
         "type": "array",
     }
     assert components == {
@@ -73,12 +72,10 @@ async def handle_file_list_upload(
                 "properties": {
                     "cv": {
                         "type": "string",
-                        "format": "binary",
                         "contentMediaType": "application/octet-stream",
                     },
                     "image": {
                         "type": "string",
-                        "format": "binary",
                         "contentMediaType": "application/octet-stream",
                     },
                 },