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/path_item.py b/litestar/_openapi/path_item.py
--- a/litestar/_openapi/path_item.py
+++ b/litestar/_openapi/path_item.py
@@ -88,7 +88,7 @@ def create_path_item(
     operation_ids: list[str] = []
 
     request_schema_creator = SchemaCreator(create_examples, plugins, schemas, prefer_alias=True)
-    response_schema_creator = SchemaCreator(create_examples, plugins, schemas, prefer_alias=False)
+    response_schema_creator = SchemaCreator(create_examples, plugins, schemas, prefer_alias=True)
     for http_method, handler_tuple in route.route_handler_map.items():
         route_handler, _ = handler_tuple
 
diff --git a/litestar/contrib/pydantic/pydantic_init_plugin.py b/litestar/contrib/pydantic/pydantic_init_plugin.py
--- a/litestar/contrib/pydantic/pydantic_init_plugin.py
+++ b/litestar/contrib/pydantic/pydantic_init_plugin.py
@@ -102,16 +102,20 @@ def _create_pydantic_v1_encoders() -> dict[Any, Callable[[Any], Any]]:  # pragma
 
     @staticmethod
     def _create_pydantic_v2_encoders() -> dict[Any, Callable[[Any], Any]]:
-        from pydantic_extra_types import color
-
-        return {
+        try:
+            from pydantic_extra_types import color
+        except ImportError:
+            color = None  # type: ignore[assignment]
+        encoders: dict[Any, Callable[[Any], Any]] = {
             pydantic.BaseModel: lambda model: model.model_dump(mode="json"),
-            color.Color: str,
             pydantic.types.SecretStr: lambda val: "**********" if val else "",
             pydantic.types.SecretBytes: lambda val: "**********" if val else "",
         }
+        if color:
+            encoders[color.Color] = str
+        return encoders
 
     def on_app_init(self, app_config: AppConfig) -> AppConfig:
-        app_config.type_encoders = {**(app_config.type_encoders or {}), **self.encoders()}
-        app_config.type_decoders = [*(app_config.type_decoders or []), *self.decoders()]
+        app_config.type_encoders = {**self.encoders(), **(app_config.type_encoders or {})}
+        app_config.type_decoders = [*self.decoders(), *(app_config.type_decoders or [])]
         return app_config


Test patch:
diff --git a/tests/unit/test_openapi/test_config.py b/tests/unit/test_openapi/test_config.py
--- a/tests/unit/test_openapi/test_config.py
+++ b/tests/unit/test_openapi/test_config.py
@@ -69,9 +69,9 @@ def handler(data: RequestWithAlias) -> ResponseWithAlias:
         "title": "RequestWithAlias",
     }
     assert schemas["ResponseWithAlias"] == {
-        "properties": {"first": {"type": "string"}},
+        "properties": {"second": {"type": "string"}},
         "type": "object",
-        "required": ["first"],
+        "required": ["second"],
         "title": "ResponseWithAlias",
     }