prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Bug: CLI Schema Export fails
  ### Description
  
  Exporting the Litestar schema via CLI fails presumably because the `json.dumps` can't serialize certain field types such as `UUID` or `datetime`.
  
  > [!IMPORTANT]  
  > This is only when `create_examples` is `True`
  
  ### URL to code causing the issue
  
  _No response_
  
  ### MCVE
  
  ```python
  from datetime import datetime
  from litestar import Litestar, get
  from litestar.openapi import OpenAPIConfig
  
  @get()
  async def something(date: datetime) -> None:
      return None
  
  app = Litestar([something], openapi_config=OpenAPIConfig('example', '0.0.1', True))
  ```
  
  or
  
  ```python
  from __future__ import annotations
  from datetime import datetime
  from uuid import UUID
  from litestar import Litestar, get
  from litestar.openapi import OpenAPIConfig
  from pydantic import BaseModel, Field
  
  class FileSchema(BaseModel):
      id: UUID
      updated: datetime
  
  @get()
  async def something() -> FileSchema | None:
      return None
  
  app = Litestar([something], openapi_config=OpenAPIConfig("example", "0.0.1", True))
  ```
  
  
  ### Steps to reproduce
  
  ```bash
  1. Create mcve.py
  2. `litestar schema openapi --output schema.json`
  3. See error
  ```
  
  
  ### Screenshots
  
  _No response_
  
  ### Logs
  
  _No response_
  
  ### Litestar Version
  
  2.x
  
  ### Platform
  
  - [ ] Linux
  - [ ] Mac
  - [ ] Windows
  - [X] Other (Please specify in the description above)
  
  <!-- POLAR PLEDGE BADGE START -->
  ---
  > [!NOTE]  
  > While we are open for sponsoring on [GitHub Sponsors](https://github.com/sponsors/litestar-org/) and 
  > [OpenCollective](https://opencollective.com/litestar), we also utilize [Polar.sh](https://polar.sh/) to engage in pledge-based sponsorship.
  >
  > Check out all issues funded or available for funding [on our Polar.sh Litestar dashboard](https://polar.sh/litestar-org)
  > * If you would like to see an issue prioritized, make a pledge towards it!
  > * We receive the pledge once the issue is completed & verified
  > * This, along with engagement in the community, helps us know which features are a priority to our users.
  
  <a href="https://polar.sh/litestar-org/litestar/issues/2575">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://polar.sh/api/github/litestar-org/litestar/issues/2575/pledge.svg?darkmode=1">
    <img alt="Fund with Polar" src="https://polar.sh/api/github/litestar-org/litestar/issues/2575/pledge.svg">
  </picture>
  </a>
  <!-- POLAR PLEDGE BADGE END -->
  
  
  </issue>
  <code>
  [start of litestar/cli/commands/schema.py]
  1 from json import dumps
  2 from pathlib import Path
  3 from typing import TYPE_CHECKING
  4 
  5 from yaml import dump as dump_yaml
  6 
  7 from litestar import Litestar
  8 from litestar._openapi.typescript_converter.converter import (
  9     convert_openapi_to_typescript,
  10 )
  11 from litestar.cli._utils import JSBEAUTIFIER_INSTALLED, RICH_CLICK_INSTALLED, LitestarCLIException, LitestarGroup
  12 
  13 if TYPE_CHECKING or not RICH_CLICK_INSTALLED:  # pragma: no cover
  14     from click import Path as ClickPath
  15     from click import group, option
  16 else:
  17     from rich_click import Path as ClickPath
  18     from rich_click import group, option
  19 
  20 if JSBEAUTIFIER_INSTALLED:  # pragma: no cover
  21     from jsbeautifier import Beautifier
  22 
  23     beautifier = Beautifier()
  24 
  25 
  26 __all__ = ("generate_openapi_schema", "generate_typescript_specs", "schema_group")
  27 
  28 
  29 @group(cls=LitestarGroup, name="schema")
  30 def schema_group() -> None:
  31     """Manage server-side OpenAPI schemas."""
  32 
  33 
  34 @schema_group.command("openapi")  # type: ignore
  35 @option(
  36     "--output",
  37     help="output file path",
  38     type=ClickPath(dir_okay=False, path_type=Path),
  39     default=Path("openapi_schema.json"),
  40     show_default=True,
  41 )
  42 def generate_openapi_schema(app: Litestar, output: Path) -> None:
  43     """Generate an OpenAPI Schema."""
  44     if output.suffix in (".yml", ".yaml"):
  45         content = dump_yaml(app.openapi_schema.to_schema(), default_flow_style=False)
  46     else:
  47         content = dumps(app.openapi_schema.to_schema(), indent=4)
  48 
  49     try:
  50         output.write_text(content)
  51     except OSError as e:  # pragma: no cover
  52         raise LitestarCLIException(f"failed to write schema to path {output}") from e
  53 
  54 
  55 @schema_group.command("typescript")  # type: ignore
  56 @option(
  57     "--output",
  58     help="output file path",
  59     type=ClickPath(dir_okay=False, path_type=Path),
  60     default=Path("api-specs.ts"),
  61     show_default=True,
  62 )
  63 @option("--namespace", help="namespace to use for the typescript specs", type=str, default="API")
  64 def generate_typescript_specs(app: Litestar, output: Path, namespace: str) -> None:
  65     """Generate TypeScript specs from the OpenAPI schema."""
  66     try:
  67         specs = convert_openapi_to_typescript(app.openapi_schema, namespace)
  68         # beautifier will be defined if JSBEAUTIFIER_INSTALLED is True
  69         specs_output = (
  70             beautifier.beautify(specs.write()) if JSBEAUTIFIER_INSTALLED else specs.write()  # pyright: ignore
  71         )
  72         output.write_text(specs_output)
  73     except OSError as e:  # pragma: no cover
  74         raise LitestarCLIException(f"failed to write schema to path {output}") from e
  75
  [end of litestar/cli/commands/schema.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/litestar/cli/commands/schema.py b/litestar/cli/commands/schema.py
  --- a/litestar/cli/commands/schema.py
  +++ b/litestar/cli/commands/schema.py
  @@ -1,7 +1,7 @@
  -from json import dumps
   from pathlib import Path
   from typing import TYPE_CHECKING
   
  +import msgspec
   from yaml import dump as dump_yaml
   
   from litestar import Litestar
  @@ -9,6 +9,7 @@
       convert_openapi_to_typescript,
   )
   from litestar.cli._utils import JSBEAUTIFIER_INSTALLED, RICH_CLICK_INSTALLED, LitestarCLIException, LitestarGroup
  +from litestar.serialization import encode_json, get_serializer
   
   if TYPE_CHECKING or not RICH_CLICK_INSTALLED:  # pragma: no cover
       from click import Path as ClickPath
  @@ -31,6 +32,27 @@
       """Manage server-side OpenAPI schemas."""
   
   
  +def _generate_openapi_schema(app: Litestar, output: Path) -> None:
  +    """Generate an OpenAPI Schema."""
  +    serializer = get_serializer(app.type_encoders)
  +    if output.suffix in (".yml", ".yaml"):
  +        content = dump_yaml(
  +            msgspec.to_builtins(app.openapi_schema.to_schema(), enc_hook=serializer),
  +            default_flow_style=False,
  +            encoding="utf-8",
  +        )
  +    else:
  +        content = msgspec.json.format(
  +            encode_json(app.openapi_schema.to_schema(), serializer=serializer),
  +            indent=4,
  +        )
  +
  +    try:
  +        output.write_bytes(content)
  +    except OSError as e:  # pragma: no cover
  +        raise LitestarCLIException(f"failed to write schema to path {output}") from e
  +
  +
   @schema_group.command("openapi")  # type: ignore
   @option(
       "--output",
  @@ -41,15 +63,7 @@
   )
   def generate_openapi_schema(app: Litestar, output: Path) -> None:
       """Generate an OpenAPI Schema."""
  -    if output.suffix in (".yml", ".yaml"):
  -        content = dump_yaml(app.openapi_schema.to_schema(), default_flow_style=False)
  -    else:
  -        content = dumps(app.openapi_schema.to_schema(), indent=4)
  -
  -    try:
  -        output.write_text(content)
  -    except OSError as e:  # pragma: no cover
  -        raise LitestarCLIException(f"failed to write schema to path {output}") from e
  +    _generate_openapi_schema(app, output)
   
   
   @schema_group.command("typescript")  # type: ignore
  
verification_info: {"golden_diff": "diff --git a/litestar/cli/commands/schema.py b/litestar/cli/commands/schema.py\n--- a/litestar/cli/commands/schema.py\n+++ b/litestar/cli/commands/schema.py\n@@ -1,7 +1,7 @@\n-from json import dumps\n from pathlib import Path\n from typing import TYPE_CHECKING\n \n+import msgspec\n from yaml import dump as dump_yaml\n \n from litestar import Litestar\n@@ -9,6 +9,7 @@\n     convert_openapi_to_typescript,\n )\n from litestar.cli._utils import JSBEAUTIFIER_INSTALLED, RICH_CLICK_INSTALLED, LitestarCLIException, LitestarGroup\n+from litestar.serialization import encode_json, get_serializer\n \n if TYPE_CHECKING or not RICH_CLICK_INSTALLED:  # pragma: no cover\n     from click import Path as ClickPath\n@@ -31,6 +32,27 @@\n     \"\"\"Manage server-side OpenAPI schemas.\"\"\"\n \n \n+def _generate_openapi_schema(app: Litestar, output: Path) -> None:\n+    \"\"\"Generate an OpenAPI Schema.\"\"\"\n+    serializer = get_serializer(app.type_encoders)\n+    if output.suffix in (\".yml\", \".yaml\"):\n+        content = dump_yaml(\n+            msgspec.to_builtins(app.openapi_schema.to_schema(), enc_hook=serializer),\n+            default_flow_style=False,\n+            encoding=\"utf-8\",\n+        )\n+    else:\n+        content = msgspec.json.format(\n+            encode_json(app.openapi_schema.to_schema(), serializer=serializer),\n+            indent=4,\n+        )\n+\n+    try:\n+        output.write_bytes(content)\n+    except OSError as e:  # pragma: no cover\n+        raise LitestarCLIException(f\"failed to write schema to path {output}\") from e\n+\n+\n @schema_group.command(\"openapi\")  # type: ignore\n @option(\n     \"--output\",\n@@ -41,15 +63,7 @@\n )\n def generate_openapi_schema(app: Litestar, output: Path) -> None:\n     \"\"\"Generate an OpenAPI Schema.\"\"\"\n-    if output.suffix in (\".yml\", \".yaml\"):\n-        content = dump_yaml(app.openapi_schema.to_schema(), default_flow_style=False)\n-    else:\n-        content = dumps(app.openapi_schema.to_schema(), indent=4)\n-\n-    try:\n-        output.write_text(content)\n-    except OSError as e:  # pragma: no cover\n-        raise LitestarCLIException(f\"failed to write schema to path {output}\") from e\n+    _generate_openapi_schema(app, output)\n \n \n @schema_group.command(\"typescript\")  # type: ignore\n", "issue": "Bug: CLI Schema Export fails\n### Description\r\n\r\nExporting the Litestar schema via CLI fails presumably because the `json.dumps` can't serialize certain field types such as `UUID` or `datetime`.\r\n\r\n> [!IMPORTANT]  \r\n> This is only when `create_examples` is `True`\r\n\r\n### URL to code causing the issue\r\n\r\n_No response_\r\n\r\n### MCVE\r\n\r\n```python\r\nfrom datetime import datetime\r\nfrom litestar import Litestar, get\r\nfrom litestar.openapi import OpenAPIConfig\r\n\r\n@get()\r\nasync def something(date: datetime) -> None:\r\n    return None\r\n\r\napp = Litestar([something], openapi_config=OpenAPIConfig('example', '0.0.1', True))\r\n```\r\n\r\nor\r\n\r\n```python\r\nfrom __future__ import annotations\r\nfrom datetime import datetime\r\nfrom uuid import UUID\r\nfrom litestar import Litestar, get\r\nfrom litestar.openapi import OpenAPIConfig\r\nfrom pydantic import BaseModel, Field\r\n\r\nclass FileSchema(BaseModel):\r\n    id: UUID\r\n    updated: datetime\r\n\r\n@get()\r\nasync def something() -> FileSchema | None:\r\n    return None\r\n\r\napp = Litestar([something], openapi_config=OpenAPIConfig(\"example\", \"0.0.1\", True))\r\n```\r\n\r\n\r\n### Steps to reproduce\r\n\r\n```bash\r\n1. Create mcve.py\r\n2. `litestar schema openapi --output schema.json`\r\n3. See error\r\n```\r\n\r\n\r\n### Screenshots\r\n\r\n_No response_\r\n\r\n### Logs\r\n\r\n_No response_\r\n\r\n### Litestar Version\r\n\r\n2.x\r\n\r\n### Platform\r\n\r\n- [ ] Linux\r\n- [ ] Mac\r\n- [ ] Windows\r\n- [X] Other (Please specify in the description above)\r\n\r\n<!-- POLAR PLEDGE BADGE START -->\r\n---\r\n> [!NOTE]  \r\n> While we are open for sponsoring on [GitHub Sponsors](https://github.com/sponsors/litestar-org/) and \r\n> [OpenCollective](https://opencollective.com/litestar), we also utilize [Polar.sh](https://polar.sh/) to engage in pledge-based sponsorship.\r\n>\r\n> Check out all issues funded or available for funding [on our Polar.sh Litestar dashboard](https://polar.sh/litestar-org)\r\n> * If you would like to see an issue prioritized, make a pledge towards it!\r\n> * We receive the pledge once the issue is completed & verified\r\n> * This, along with engagement in the community, helps us know which features are a priority to our users.\r\n\r\n<a href=\"https://polar.sh/litestar-org/litestar/issues/2575\">\r\n<picture>\r\n  <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://polar.sh/api/github/litestar-org/litestar/issues/2575/pledge.svg?darkmode=1\">\r\n  <img alt=\"Fund with Polar\" src=\"https://polar.sh/api/github/litestar-org/litestar/issues/2575/pledge.svg\">\r\n</picture>\r\n</a>\r\n<!-- POLAR PLEDGE BADGE END -->\r\n\n", "before_files": [{"content": "from json import dumps\nfrom pathlib import Path\nfrom typing import TYPE_CHECKING\n\nfrom yaml import dump as dump_yaml\n\nfrom litestar import Litestar\nfrom litestar._openapi.typescript_converter.converter import (\n    convert_openapi_to_typescript,\n)\nfrom litestar.cli._utils import JSBEAUTIFIER_INSTALLED, RICH_CLICK_INSTALLED, LitestarCLIException, LitestarGroup\n\nif TYPE_CHECKING or not RICH_CLICK_INSTALLED:  # pragma: no cover\n    from click import Path as ClickPath\n    from click import group, option\nelse:\n    from rich_click import Path as ClickPath\n    from rich_click import group, option\n\nif JSBEAUTIFIER_INSTALLED:  # pragma: no cover\n    from jsbeautifier import Beautifier\n\n    beautifier = Beautifier()\n\n\n__all__ = (\"generate_openapi_schema\", \"generate_typescript_specs\", \"schema_group\")\n\n\n@group(cls=LitestarGroup, name=\"schema\")\ndef schema_group() -> None:\n    \"\"\"Manage server-side OpenAPI schemas.\"\"\"\n\n\n@schema_group.command(\"openapi\")  # type: ignore\n@option(\n    \"--output\",\n    help=\"output file path\",\n    type=ClickPath(dir_okay=False, path_type=Path),\n    default=Path(\"openapi_schema.json\"),\n    show_default=True,\n)\ndef generate_openapi_schema(app: Litestar, output: Path) -> None:\n    \"\"\"Generate an OpenAPI Schema.\"\"\"\n    if output.suffix in (\".yml\", \".yaml\"):\n        content = dump_yaml(app.openapi_schema.to_schema(), default_flow_style=False)\n    else:\n        content = dumps(app.openapi_schema.to_schema(), indent=4)\n\n    try:\n        output.write_text(content)\n    except OSError as e:  # pragma: no cover\n        raise LitestarCLIException(f\"failed to write schema to path {output}\") from e\n\n\n@schema_group.command(\"typescript\")  # type: ignore\n@option(\n    \"--output\",\n    help=\"output file path\",\n    type=ClickPath(dir_okay=False, path_type=Path),\n    default=Path(\"api-specs.ts\"),\n    show_default=True,\n)\n@option(\"--namespace\", help=\"namespace to use for the typescript specs\", type=str, default=\"API\")\ndef generate_typescript_specs(app: Litestar, output: Path, namespace: str) -> None:\n    \"\"\"Generate TypeScript specs from the OpenAPI schema.\"\"\"\n    try:\n        specs = convert_openapi_to_typescript(app.openapi_schema, namespace)\n        # beautifier will be defined if JSBEAUTIFIER_INSTALLED is True\n        specs_output = (\n            beautifier.beautify(specs.write()) if JSBEAUTIFIER_INSTALLED else specs.write()  # pyright: ignore\n        )\n        output.write_text(specs_output)\n    except OSError as e:  # pragma: no cover\n        raise LitestarCLIException(f\"failed to write schema to path {output}\") from e\n", "path": "litestar/cli/commands/schema.py"}]}