def openapi_schema(request: fastapi.Request):
            """Generate an OpenAPI schema from the Gradio app's API info."""
            info = api_info(request)
            schema = {
                "openapi": "3.0.2",
                "info": {
                    "title": getattr(app.get_blocks(), "title", "Gradio App"),
                    "description": getattr(app.get_blocks(), "description", ""),
                    "version": VERSION,
                },
                "paths": {},
                "components": {"schemas": {}},
            }

            for endpoint_path, endpoint_info in info.get("named_endpoints", {}).items():  # type: ignore
                if not endpoint_info.get("show_api", True):
                    continue
                path_item = {
                    "post": {
                        "summary": endpoint_info.get(
                            "description", f"Endpoint {endpoint_path}"
                        ),
                        "description": endpoint_info.get("description", ""),
                        "operationId": endpoint_path.strip("/").replace("/", "_"),
                        "requestBody": {
                            "required": True,
                            "content": {
                                "application/json": {
                                    "schema": {"type": "object", "properties": {}}
                                }
                            },
                        },
                        "responses": {
                            "200": {
                                "description": "Successful response",
                                "content": {
                                    "application/json": {
                                        "schema": {"type": "object", "properties": {}}
                                    }
                                },
                            }
                        },
                    }
                }

                request_properties = path_item["post"]["requestBody"]["content"][
                    "application/json"
                ]["schema"]["properties"]
                for param in endpoint_info.get("parameters", []):
                    param_name = param["parameter_name"]
                    param_type = param.get("type", {})

                    if "additional_description" in param_type:
                        param_type = dict(param_type)
                        param_type.pop("additional_description", None)

                    if "properties" in param_type and "type" not in param_type:
                        param_type = dict(param_type)
                        param_type["type"] = "object"

                    request_properties[param_name] = param_type

                    if "example_input" in param:
                        if (
                            "examples"
                            not in path_item["post"]["requestBody"]["content"][
                                "application/json"
                            ]
                        ):
                            path_item["post"]["requestBody"]["content"][
                                "application/json"
                            ]["examples"] = {"example1": {"value": {}}}
                        path_item["post"]["requestBody"]["content"]["application/json"][
                            "examples"
                        ]["example1"]["value"][param_name] = param["example_input"]

                response_properties = path_item["post"]["responses"]["200"]["content"][
                    "application/json"
                ]["schema"]["properties"]
                for i, ret in enumerate(endpoint_info.get("returns", [])):
                    ret_name = f"output_{i}" if i > 0 else "output"
                    ret_type = ret.get("type", {})

                    if "additional_description" in ret_type:
                        ret_type = dict(ret_type)
                        ret_type.pop("additional_description", None)

                    if "properties" in ret_type and "type" not in ret_type:
                        ret_type = dict(ret_type)
                        ret_type["type"] = "object"

                    response_properties[ret_name] = ret_type

                schema["paths"][f"/run{endpoint_path}"] = path_item

            return schema
Generate an OpenAPI schema from the Gradio app's API info.
gradio/routes.py