text: import typing
  
  from starlette.testclient import TestClient
  from typing_extensions import Annotated
  
  from xpresso import App, File, FromFile, Path, UploadFile
  
  
  def test_bytes():
      async def endpoint(file: FromFile[bytes]) -> None:
          ...
  
      app = App([Path("/", post=endpoint)])
  
      expected_openapi: typing.Dict[str, typing.Any] = {
          "openapi": "3.0.3",
          "info": {"title": "API", "version": "0.1.0"},
          "paths": {
              "/": {
                  "post": {
                      "responses": {
                          "200": {"description": "Successful Response"},
                          "422": {
                              "description": "Validation Error",
                              "content": {
                                  "application/json": {
                                      "schema": {
                                          "$ref": "#/components/schemas/HTTPValidationError"
                                      }
                                  }
                              },
                          },
                      },
                      "requestBody": {
                          "content": {
                              "*/*": {"schema": {"type": "string", "format": "binary"}}
                          },
                          "required": True,
                      },
                  }
              }
          },
          "components": {
              "schemas": {
                  "ValidationError": {
                      "title": "ValidationError",
                      "required": ["loc", "msg", "type"],
                      "type": "object",
                      "properties": {
                          "loc": {
                              "title": "Location",
                              "type": "array",
                              "items": {
                                  "oneOf": [{"type": "string"}, {"type": "integer"}]
                              },
                          },
                          "msg": {"title": "Message", "type": "string"},
                          "type": {"title": "Error Type", "type": "string"},
                      },
                  },
                  "HTTPValidationError": {
                      "title": "HTTPValidationError",
                      "type": "object",
                      "properties": {
                          "detail": {
                              "title": "Detail",
                              "type": "array",
                              "items": {"$ref": "#/components/schemas/ValidationError"},
                          }
                      },
                  },
              }
          },
      }
  
      with TestClient(app) as client:
          resp = client.get("/openapi.json")
      assert resp.status_code == 200, resp.text
      assert resp.json() == expected_openapi
  
  
  def test_uploadfile():
      async def endpoint(file: FromFile[UploadFile]) -> None:
          ...
  
      app = App([Path("/", post=endpoint)])
  
      expected_openapi: typing.Dict[str, typing.Any] = {
          "openapi": "3.0.3",
          "info": {"title": "API", "version": "0.1.0"},
          "paths": {
              "/": {
                  "post": {
                      "responses": {
                          "200": {"description": "Successful Response"},
                          "422": {
                              "description": "Validation Error",
                              "content": {
                                  "application/json": {
                                      "schema": {
                                          "$ref": "#/components/schemas/HTTPValidationError"
                                      }
                                  }
                              },
                          },
                      },
                      "requestBody": {
                          "content": {
                              "*/*": {
                                  "schema": {
                                      "type": "string",
                                      "format": "binary",
                                  }
                              }
                          },
                          "required": True,
                      },
                  }
              }
          },
          "components": {
              "schemas": {
                  "ValidationError": {
                      "title": "ValidationError",
                      "required": ["loc", "msg", "type"],
                      "type": "object",
                      "properties": {
                          "loc": {
                              "title": "Location",
                              "type": "array",
                              "items": {
                                  "oneOf": [{"type": "string"}, {"type": "integer"}]
                              },
                          },
                          "msg": {"title": "Message", "type": "string"},
                          "type": {"title": "Error Type", "type": "string"},
                      },
                  },
                  "HTTPValidationError": {
                      "title": "HTTPValidationError",
                      "type": "object",
                      "properties": {
                          "detail": {
                              "title": "Detail",
                              "type": "array",
                              "items": {"$ref": "#/components/schemas/ValidationError"},
                          }
                      },
                  },
              }
          },
      }
  
      with TestClient(app) as client:
          resp = client.get("/openapi.json")
      assert resp.status_code == 200, resp.text
      assert resp.json() == expected_openapi
  
  
  def test_uploadfile_custom_format():
      async def endpoint(file: Annotated[UploadFile, File(format="base64")]) -> None:
          ...
  
      app = App([Path("/", post=endpoint)])
  
      expected_openapi: typing.Dict[str, typing.Any] = {
          "openapi": "3.0.3",
          "info": {"title": "API", "version": "0.1.0"},
          "paths": {
              "/": {
                  "post": {
                      "responses": {
                          "200": {"description": "Successful Response"},
                          "422": {
                              "description": "Validation Error",
                              "content": {
                                  "application/json": {
                                      "schema": {
                                          "$ref": "#/components/schemas/HTTPValidationError"
                                      }
                                  }
                              },
                          },
                      },
                      "requestBody": {
                          "content": {
                              "*/*": {
                                  "schema": {
                                      "type": "string",
                                      "format": "base64",
                                  }
                              }
                          },
                          "required": True,
                      },
                  }
              }
          },
          "components": {
              "schemas": {
                  "ValidationError": {
                      "title": "ValidationError",
                      "required": ["loc", "msg", "type"],
                      "type": "object",
                      "properties": {
                          "loc": {
                              "title": "Location",
                              "type": "array",
                              "items": {
                                  "oneOf": [{"type": "string"}, {"type": "integer"}]
                              },
                          },
                          "msg": {"title": "Message", "type": "string"},
                          "type": {"title": "Error Type", "type": "string"},
                      },
                  },
                  "HTTPValidationError": {
                      "title": "HTTPValidationError",
                      "type": "object",
                      "properties": {
                          "detail": {
                              "title": "Detail",
                              "type": "array",
                              "items": {"$ref": "#/components/schemas/ValidationError"},
                          }
                      },
                  },
              }
          },
      }
  
      with TestClient(app) as client:
          resp = client.get("/openapi.json")
      assert resp.status_code == 200, resp.text
      assert resp.json() == expected_openapi
  
  
  def test_custom_media_type():
      async def endpoint(file: Annotated[bytes, File(media_type="image/png")]) -> None:
          ...
  
      app = App([Path("/", post=endpoint)])
  
      expected_openapi: typing.Dict[str, typing.Any] = {
          "openapi": "3.0.3",
          "info": {"title": "API", "version": "0.1.0"},
          "paths": {
              "/": {
                  "post": {
                      "responses": {
                          "200": {"description": "Successful Response"},
                          "422": {
                              "description": "Validation Error",
                              "content": {
                                  "application/json": {
                                      "schema": {
                                          "$ref": "#/components/schemas/HTTPValidationError"
                                      }
                                  }
                              },
                          },
                      },
                      "requestBody": {
                          "content": {
                              "image/png": {
                                  "schema": {
                                      "type": "string",
                                      "format": "binary",
                                  }
                              }
                          },
                          "required": True,
                      },
                  }
              }
          },
          "components": {
              "schemas": {
                  "ValidationError": {
                      "title": "ValidationError",
                      "required": ["loc", "msg", "type"],
                      "type": "object",
                      "properties": {
                          "loc": {
                              "title": "Location",
                              "type": "array",
                              "items": {
                                  "oneOf": [{"type": "string"}, {"type": "integer"}]
                              },
                          },
                          "msg": {"title": "Message", "type": "string"},
                          "type": {"title": "Error Type", "type": "string"},
                      },
                  },
                  "HTTPValidationError": {
                      "title": "HTTPValidationError",
                      "type": "object",
                      "properties": {
                          "detail": {
                              "title": "Detail",
                              "type": "array",
                              "items": {"$ref": "#/components/schemas/ValidationError"},
                          }
                      },
                  },
              }
          },
      }
  
      with TestClient(app) as client:
          resp = client.get("/openapi.json")
      assert resp.status_code == 200, resp.text
      assert resp.json() == expected_openapi
  
  
  def test_include_in_schema() -> None:
      async def test(body: Annotated[str, File(include_in_schema=False)]) -> None:
          ...
  
      app = App([Path("/", post=test)])
  
      expected_openapi: typing.Dict[str, typing.Any] = {
          "openapi": "3.0.3",
          "info": {"title": "API", "version": "0.1.0"},
          "paths": {
              "/": {
                  "post": {
                      "responses": {
                          "200": {"description": "Successful Response"},
                          "422": {
                              "description": "Validation Error",
                              "content": {
                                  "application/json": {
                                      "schema": {
                                          "$ref": "#/components/schemas/HTTPValidationError"
                                      }
                                  }
                              },
                          },
                      },
                      "requestBody": {"content": {}},
                  }
              }
          },
          "components": {
              "schemas": {
                  "ValidationError": {
                      "title": "ValidationError",
                      "required": ["loc", "msg", "type"],
                      "type": "object",
                      "properties": {
                          "loc": {
                              "title": "Location",
                              "type": "array",
                              "items": {
                                  "oneOf": [{"type": "string"}, {"type": "integer"}]
                              },
                          },
                          "msg": {"title": "Message", "type": "string"},
                          "type": {"title": "Error Type", "type": "string"},
                      },
                  },
                  "HTTPValidationError": {
                      "title": "HTTPValidationError",
                      "type": "object",
                      "properties": {
                          "detail": {
                              "title": "Detail",
                              "type": "array",
                              "items": {"$ref": "#/components/schemas/ValidationError"},
                          }
                      },
                  },
              }
          },
      }
  
      with TestClient(app) as client:
          resp = client.get("/openapi.json")
      assert resp.status_code == 200, resp.text
      assert resp.json() == expected_openapi
  