failed CONTEXT NO_PATCH UNSUBMITTED agent_error · 24 tool calls · 126 s · fastapi/fastapi
✨ Add OpenAPI `external_docs` parameter to `FastAPI` This PR adds an external_docs parameter to the __init__ method of the FastAPI class. Currently, the external_docs parameter is not being passed when generating the OpenAPI documentation, which I believe is an oversight. By including this parameter in the FastAPI class constructor, the external_docs field will be correctly included in the root of the generated OpenAPI JSON or YAML file. Reasoning: The external_docs field provides valuable external documentation links and should be part of the OpenAPI metadata. Including it at the root level of the OpenAPI spec enhances the usability and completeness of the generated documentation, especially for providing references to external resources.
| # | Tool | Arguments | Result |
|---|---|---|---|
| 1 | run_command | {
"command": "grep -rn \"class FastAPI\" ."
} | {"status": "ok", "stdout": "./fastapi/applications.py:48:class FastAPI(Starlette):\n./fastapi/exceptions.py:143:class FastAPIError(RuntimeError):\n", "exit_codefull{"status": "ok", "stdout": "./fastapi/applications.py:48:class FastAPI(Starlette):\n./fastapi/exceptions.py:143:class FastAPIError(RuntimeError):\n", "exit_code": 0} |
| 2 | read_file | {
"end_line": 120,
"filepath": "fastapi/applications.py",
"start_line": 48
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "class FastAPI(Starlette):\n \"\"\"\n `FastAPI` app class, the main entrypoint to use FastAPIfull{"status": "ok", "filepath": "fastapi/applications.py", "content": "class FastAPI(Starlette):\n \"\"\"\n `FastAPI` app class, the main entrypoint to use FastAPI.\n\n Read more in the\n [FastAPI docs for First Steps](https://fastapi.tiangolo.com/tutorial/first-steps/).\n\n ## Example\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI()\n ```\n \"\"\"\n\n def __init__(\n self: AppType,\n *,\n debug: Annotated[\n bool,\n Doc(\n \"\"\"\n Boolean indicating if debug tracebacks should be returned on server\n errors.\n\n Read more in the\n [Starlette docs for Applications](https://www.starlette.io/applications/#instantiating-the-application).\n \"\"\"\n ),\n ] = False,\n routes: Annotated[\n Optional[List[BaseRoute]],\n Doc(\n \"\"\"\n **Note**: you probably shouldn't use this parameter, it is inherited\n from Starlette and supported for compatibility.\n\n ---\n\n A list of routes to serve incoming HTTP and WebSocket requests.\n \"\"\"\n ),\n deprecated(\n \"\"\"\n You normally wouldn't use this parameter with FastAPI, it is inherited\n from Starlette and supported for compatibility.\n\n In FastAPI, you normally would use the *path operation methods*,\n like `app.get()`, `app.post()`, etc.\n \"\"\"\n ),\n ] = None,\n title: Annotated[\n str,\n Doc(\n \"\"\"\n The title of the API.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tia |
| 3 | read_file | {
"end_line": 200,
"filepath": "fastapi/applications.py",
"start_line": 121
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " ] = \"FastAPI\",\n summary: Annotated[\n Optional[str],\n Doc(\n \"\"\"\n A short summary ofull{"status": "ok", "filepath": "fastapi/applications.py", "content": " ] = \"FastAPI\",\n summary: Annotated[\n Optional[str],\n Doc(\n \"\"\"\n A short summary of the API.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-api).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(summary=\"Deadpond's favorite app. Nuff said.\")\n ```\n \"\"\"\n ),\n ] = None,\n description: Annotated[\n str,\n Doc(\n '''\n A description of the API. Supports Markdown (using\n [CommonMark syntax](https://commonmark.org/)).\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-api).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(\n description=\"\"\"\n ChimichangApp API helps you do awesome stuff. \ud83d\ude80\n\n ## Items\n\n You can **read items**.\n\n ## Users\n\n You will be able to:\n\n * **Create users** (_not implemented_).\n * **Read users** (_not implemented_).\n\n \"\"\"\n )\n ```\n '''\n ),\n ] = \"\",\n version |
| 4 | run_command | {
"command": "grep -n \"def openapi\" fastapi/applications.py"
} | {"status": "ok", "stdout": "966: def openapi(self) -> Dict[str, Any]:\n1003: async def openapi(req: Request) -> JSONResponse:\n", "exit_code": 0}full{"status": "ok", "stdout": "966: def openapi(self) -> Dict[str, Any]:\n1003: async def openapi(req: Request) -> JSONResponse:\n", "exit_code": 0} |
| 5 | read_file | {
"end_line": 1000,
"filepath": "fastapi/applications.py",
"start_line": 966
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " def openapi(self) -> Dict[str, Any]:\n \"\"\"\n Generate the OpenAPI schema of the applicatfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " def openapi(self) -> Dict[str, Any]:\n \"\"\"\n Generate the OpenAPI schema of the application. This is called by FastAPI\n internally.\n\n The first time it is called it stores the result in the attribute\n `app.openapi_schema`, and next times it is called, it just returns that same\n result. To avoid the cost of generating the schema every time.\n\n If you need to modify the generated OpenAPI schema, you could modify it.\n\n Read more in the\n [FastAPI docs for OpenAPI](https://fastapi.tiangolo.com/how-to/extending-openapi/).\n \"\"\"\n if not self.openapi_schema:\n self.openapi_schema = get_openapi(\n title=self.title,\n version=self.version,\n openapi_version=self.openapi_version,\n summary=self.summary,\n description=self.description,\n terms_of_service=self.terms_of_service,\n contact=self.contact,\n license_info=self.license_info,\n routes=self.routes,\n webhooks=self.webhooks.routes,\n tags=self.openapi_tags,\n servers=self.servers,\n separate_input_output_schemas=self.separate_input_output_schemas,\n )\n return self.openapi_schema\n\n def setup(self) -> None:\n if self.openapi_url:\n urls = (server_data.get(\"url\") for server_data in self.servers)\n", "start_line": 966, "end_line": 1000, "total_lines": 4588, "is_truncated": false} |
| 6 | read_file | {
"end_line": 200,
"filepath": "fastapi/applications.py",
"start_line": 48
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "class FastAPI(Starlette):\n \"\"\"\n `FastAPI` app class, the main entrypoint to use FastAPIfull{"status": "ok", "filepath": "fastapi/applications.py", "content": "class FastAPI(Starlette):\n \"\"\"\n `FastAPI` app class, the main entrypoint to use FastAPI.\n\n Read more in the\n [FastAPI docs for First Steps](https://fastapi.tiangolo.com/tutorial/first-steps/).\n\n ## Example\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI()\n ```\n \"\"\"\n\n def __init__(\n self: AppType,\n *,\n debug: Annotated[\n bool,\n Doc(\n \"\"\"\n Boolean indicating if debug tracebacks should be returned on server\n errors.\n\n Read more in the\n [Starlette docs for Applications](https://www.starlette.io/applications/#instantiating-the-application).\n \"\"\"\n ),\n ] = False,\n routes: Annotated[\n Optional[List[BaseRoute]],\n Doc(\n \"\"\"\n **Note**: you probably shouldn't use this parameter, it is inherited\n from Starlette and supported for compatibility.\n\n ---\n\n A list of routes to serve incoming HTTP and WebSocket requests.\n \"\"\"\n ),\n deprecated(\n \"\"\"\n You normally wouldn't use this parameter with FastAPI, it is inherited\n from Starlette and supported for compatibility.\n\n In FastAPI, you normally would use the *path operation methods*,\n like `app.get()`, `app.post()`, etc.\n \"\"\"\n ),\n ] = None,\n title: Annotated[\n str,\n Doc(\n \"\"\"\n The title of the API.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tia |
| 7 | read_file | {
"end_line": 250,
"filepath": "fastapi/applications.py",
"start_line": 198
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " from fastapi import FastAPI\n\n app = FastAPI(version=\"0.0.1\")\n ```\n \"\"\"\n ),\n ] = full{"status": "ok", "filepath": "fastapi/applications.py", "content": " from fastapi import FastAPI\n\n app = FastAPI(version=\"0.0.1\")\n ```\n \"\"\"\n ),\n ] = \"0.1.0\",\n openapi_url: Annotated[\n Optional[str],\n Doc(\n \"\"\"\n The URL where the OpenAPI schema will be served from.\n\n If you set it to `None`, no OpenAPI schema will be served publicly, and\n the default automatic endpoints `/docs` and `/redoc` will also be\n disabled.\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#openapi-url).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(openapi_url=\"/api/v1/openapi.json\")\n ```\n \"\"\"\n ),\n ] = \"/openapi.json\",\n openapi_tags: Annotated[\n Optional[List[Dict[str, Any]]],\n Doc(\n \"\"\"\n A list of tags used by OpenAPI, these are the same `tags` you can set\n in the *path operations*, like:\n\n * `@app.get(\"/users/\", tags=[\"users\"])`\n * `@app.get(\"/items/\", tags=[\"items\"])`\n\n The order of the tags can be used to specify the order shown in\n tools like Swagger UI, used in the automatic path `/docs`.\n\n It's not required to specify all the tags used.\n\n The tags that are not declared MAY be organized randomly or based\n on the tools' logic. Each tag name in the list MUST be unique.\n\n The value of each item is a `dict` containing:\n\n * `name`: The name of the tag.\n * `description`: A short description of the t |
| 8 | read_file | {
"end_line": 350,
"filepath": "fastapi/applications.py",
"start_line": 251
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " text representation.\n * `externalDocs`: Additional external documentation for this tag. Iffull{"status": "ok", "filepath": "fastapi/applications.py", "content": " text representation.\n * `externalDocs`: Additional external documentation for this tag. If\n provided, it would contain a `dict` with:\n * `description`: A short description of the target documentation.\n [CommonMark syntax](https://commonmark.org/) MAY be used for\n rich text representation.\n * `url`: The URL for the target documentation. Value MUST be in\n the form of a URL.\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-tags).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n tags_metadata = [\n {\n \"name\": \"users\",\n \"description\": \"Operations with users. The **login** logic is also here.\",\n },\n {\n \"name\": \"items\",\n \"description\": \"Manage items. So _fancy_ they have their own docs.\",\n \"externalDocs\": {\n \"description\": \"Items external docs\",\n \"url\": \"https://fastapi.tiangolo.com/\",\n },\n },\n ]\n\n app = FastAPI(openapi_tags=tags_metadata)\n ```\n \"\"\"\n ),\n ] = None,\n servers: Annotated[\n Optional[List[Dict[str, Union[str, Any]]]],\n Doc(\n \"\"\"\n A `list` of `dict`s with connectivity information to a target server.\n\n You would use it, for example, if your application is served from\n di |
| 9 | read_file | {
"end_line": 400,
"filepath": "fastapi/applications.py",
"start_line": 351
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n ),\n ] = None,\n default_response_class: Annotated[\n Type[Response],\n Doc(\n \"\full{"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n ),\n ] = None,\n default_response_class: Annotated[\n Type[Response],\n Doc(\n \"\"\"\n The default response class to be used.\n\n Read more in the\n [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/#default-response-class).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n from fastapi.responses import ORJSONResponse\n\n app = FastAPI(default_response_class=ORJSONResponse)\n ```\n \"\"\"\n ),\n ] = Default(JSONResponse),\n redirect_slashes: Annotated[\n bool,\n Doc(\n \"\"\"\n Whether to detect and redirect slashes in URLs when the client doesn't\n use the same format.\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(redirect_slashes=True) # the default\n\n @app.get(\"/items/\")\n async def read_items():\n return [{\"item_id\": \"Foo\"}]\n ```\n\n With this app, if a client goes to `/items` (without a trailing slash),\n they will be automatically redirected with an HTTP status code of 307\n to `/items/`.\n \"\"\"\n ),\n ] = True,\n docs_url: Annotated[\n Optional[str],\n", "start_line": 351, "end_line": 400, "total_lines": 4588, "is_truncated": false} |
| 10 | read_file | {
"end_line": 450,
"filepath": "fastapi/applications.py",
"start_line": 401
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " Doc(\n \"\"\"\n The path to the automatic interactive API documentation.\n It is handled infull{"status": "ok", "filepath": "fastapi/applications.py", "content": " Doc(\n \"\"\"\n The path to the automatic interactive API documentation.\n It is handled in the browser by Swagger UI.\n\n The default URL is `/docs`. You can disable it by setting it to `None`.\n\n If `openapi_url` is set to `None`, this will be automatically disabled.\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#docs-urls).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(docs_url=\"/documentation\", redoc_url=None)\n ```\n \"\"\"\n ),\n ] = \"/docs\",\n redoc_url: Annotated[\n Optional[str],\n Doc(\n \"\"\"\n The path to the alternative automatic interactive API documentation\n provided by ReDoc.\n\n The default URL is `/redoc`. You can disable it by setting it to `None`.\n\n If `openapi_url` is set to `None`, this will be automatically disabled.\n\n Read more in the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#docs-urls).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(docs_url=\"/documentation\", redoc_url=\"redocumentation\")\n ```\n \"\"\"\n ),\n ] = \"/redoc\",\n swagger_ui_oauth2_redirect_url: Annotated[\n Optional[str],\n Doc(\n \"\"\"\n", "start_line": 401, "end_line": 450, "total_lines": 4588, "is_truncated": false} |
| 11 | read_file | {
"end_line": 500,
"filepath": "fastapi/applications.py",
"start_line": 451
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " The OAuth2 redirect endpoint for the Swagger UI.\n\n By default it is `/docs/oauth2-redirecfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " The OAuth2 redirect endpoint for the Swagger UI.\n\n By default it is `/docs/oauth2-redirect`.\n\n This is only used if you use OAuth2 (with the \"Authorize\" button)\n with Swagger UI.\n \"\"\"\n ),\n ] = \"/docs/oauth2-redirect\",\n swagger_ui_init_oauth: Annotated[\n Optional[Dict[str, Any]],\n Doc(\n \"\"\"\n OAuth2 configuration for the Swagger UI, by default shown at `/docs`.\n\n Read more about the available configuration options in the\n [Swagger UI docs](https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/).\n \"\"\"\n ),\n ] = None,\n middleware: Annotated[\n Optional[Sequence[Middleware]],\n Doc(\n \"\"\"\n List of middleware to be added when creating the application.\n\n In FastAPI you would normally do this with `app.add_middleware()`\n instead.\n\n Read more in the\n [FastAPI docs for Middleware](https://fastapi.tiangolo.com/tutorial/middleware/).\n \"\"\"\n ),\n ] = None,\n exception_handlers: Annotated[\n Optional[\n Dict[\n Union[int, Type[Exception]],\n Callable[[Request, Any], Coroutine[Any, Any, Response]],\n ]\n ],\n Doc(\n \"\"\"\n A dictionary with handlers for exceptions.\n\n In FastAPI, you would normally use the decorator\n `@app.exception_handler()`.\n\n Read more in the\n [FastAPI docs for Handling Errors](https://fastapi.tiangolo.com/tutorial/handling-errors/).\n", "start_line": 451, "end_line": 500, " |
| 12 | read_file | {
"end_line": 550,
"filepath": "fastapi/applications.py",
"start_line": 501
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n ),\n ] = None,\n on_startup: Annotated[\n Optional[Sequence[Callable[[], Any]]],\nfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n ),\n ] = None,\n on_startup: Annotated[\n Optional[Sequence[Callable[[], Any]]],\n Doc(\n \"\"\"\n A list of startup event handler functions.\n\n You should instead use the `lifespan` handlers.\n\n Read more in the [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/).\n \"\"\"\n ),\n ] = None,\n on_shutdown: Annotated[\n Optional[Sequence[Callable[[], Any]]],\n Doc(\n \"\"\"\n A list of shutdown event handler functions.\n\n You should instead use the `lifespan` handlers.\n\n Read more in the\n [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/).\n \"\"\"\n ),\n ] = None,\n lifespan: Annotated[\n Optional[Lifespan[AppType]],\n Doc(\n \"\"\"\n A `Lifespan` context manager handler. This replaces `startup` and\n `shutdown` functions with a single context manager.\n\n Read more in the\n [FastAPI docs for `lifespan`](https://fastapi.tiangolo.com/advanced/events/).\n \"\"\"\n ),\n ] = None,\n terms_of_service: Annotated[\n Optional[str],\n Doc(\n \"\"\"\n A URL to the Terms of Service for your API.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more at the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-api).\n", "start_line": 501, "end_line": 550, "total_lines": 4588, "is_truncated": false} |
| 13 | read_file | {
"end_line": 600,
"filepath": "fastapi/applications.py",
"start_line": 551
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "\n **Example**\n\n ```python\n app = FastAPI(terms_of_service=\"http://example.com/terms/\")full{"status": "ok", "filepath": "fastapi/applications.py", "content": "\n **Example**\n\n ```python\n app = FastAPI(terms_of_service=\"http://example.com/terms/\")\n ```\n \"\"\"\n ),\n ] = None,\n contact: Annotated[\n Optional[Dict[str, Union[str, Any]]],\n Doc(\n \"\"\"\n A dictionary with the contact information for the exposed API.\n\n It can contain several fields.\n\n * `name`: (`str`) The name of the contact person/organization.\n * `url`: (`str`) A URL pointing to the contact information. MUST be in\n the format of a URL.\n * `email`: (`str`) The email address of the contact person/organization.\n MUST be in the format of an email address.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more at the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-api).\n\n **Example**\n\n ```python\n app = FastAPI(\n contact={\n \"name\": \"Deadpoolio the Amazing\",\n \"url\": \"http://x-force.example.com/contact/\",\n \"email\": \"dp@x-force.example.com\",\n }\n )\n ```\n \"\"\"\n ),\n ] = None,\n license_info: Annotated[\n Optional[Dict[str, Union[str, Any]]],\n Doc(\n \"\"\"\n A dictionary with the license information for the exposed API.\n\n It can contain several fields.\n\n", "start_line": 551, "end_line": 600, "total_lines": 4588, "is_truncated": false} |
| 14 | read_file | {
"end_line": 650,
"filepath": "fastapi/applications.py",
"start_line": 601
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " * `name`: (`str`) **REQUIRED** (if a `license_info` is set). The\n license name used for thfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " * `name`: (`str`) **REQUIRED** (if a `license_info` is set). The\n license name used for the API.\n * `identifier`: (`str`) An [SPDX](https://spdx.dev/) license expression\n for the API. The `identifier` field is mutually exclusive of the `url`\n field. Available since OpenAPI 3.1.0, FastAPI 0.99.0.\n * `url`: (`str`) A URL to the license used for the API. This MUST be\n the format of a URL.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more at the\n [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-api).\n\n **Example**\n\n ```python\n app = FastAPI(\n license_info={\n \"name\": \"Apache 2.0\",\n \"url\": \"https://www.apache.org/licenses/LICENSE-2.0.html\",\n }\n )\n ```\n \"\"\"\n ),\n ] = None,\n openapi_prefix: Annotated[\n str,\n Doc(\n \"\"\"\n A URL prefix for the OpenAPI URL.\n \"\"\"\n ),\n deprecated(\n \"\"\"\n \"openapi_prefix\" has been deprecated in favor of \"root_path\", which\n follows more closely the ASGI standard, is simpler, and more\n automatic.\n \"\"\"\n ),\n ] = \"\",\n root_path: Annotated[\n str,\n Doc(\n \"\"\"\n A path prefix handled by a proxy that is not seen by the application\n but is seen by external clients, which affects things like Swagger UI.\n\n Re |
| 15 | read_file | {
"end_line": 1000,
"filepath": "fastapi/applications.py",
"start_line": 960
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " self.user_middleware: List[Middleware] = (\n [] if middleware is None else list(middleware)full{"status": "ok", "filepath": "fastapi/applications.py", "content": " self.user_middleware: List[Middleware] = (\n [] if middleware is None else list(middleware)\n )\n self.middleware_stack: Union[ASGIApp, None] = None\n self.setup()\n\n def openapi(self) -> Dict[str, Any]:\n \"\"\"\n Generate the OpenAPI schema of the application. This is called by FastAPI\n internally.\n\n The first time it is called it stores the result in the attribute\n `app.openapi_schema`, and next times it is called, it just returns that same\n result. To avoid the cost of generating the schema every time.\n\n If you need to modify the generated OpenAPI schema, you could modify it.\n\n Read more in the\n [FastAPI docs for OpenAPI](https://fastapi.tiangolo.com/how-to/extending-openapi/).\n \"\"\"\n if not self.openapi_schema:\n self.openapi_schema = get_openapi(\n title=self.title,\n version=self.version,\n openapi_version=self.openapi_version,\n summary=self.summary,\n description=self.description,\n terms_of_service=self.terms_of_service,\n contact=self.contact,\n license_info=self.license_info,\n routes=self.routes,\n webhooks=self.webhooks.routes,\n tags=self.openapi_tags,\n servers=self.servers,\n separate_input_output_schemas=self.separate_input_output_schemas,\n )\n return self.openapi_schema\n\n def setup(self) -> None:\n if self.openapi_url:\n urls = (server_data.get(\"url\") for server_data in self.servers)\n", "start_line": 960, "end_line": 1000, "total_lines": 4588, "is_truncated": false} |
| 16 | read_file | {
"end_line": 100,
"filepath": "fastapi/openapi/utils.py",
"start_line": 1
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "import http.client\nimport inspect\nimport warnings\nfrom typing import Any, Dict, List, Opfull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "import http.client\nimport inspect\nimport warnings\nfrom typing import Any, Dict, List, Optional, Sequence, Set, Tuple, Type, Union, cast\n\nfrom fastapi import routing\nfrom fastapi._compat import (\n GenerateJsonSchema,\n JsonSchemaValue,\n ModelField,\n Undefined,\n get_compat_model_name_map,\n get_definitions,\n get_schema_from_model_field,\n lenient_issubclass,\n)\nfrom fastapi.datastructures import DefaultPlaceholder\nfrom fastapi.dependencies.models import Dependant\nfrom fastapi.dependencies.utils import (\n _get_flat_fields_from_params,\n get_flat_dependant,\n get_flat_params,\n)\nfrom fastapi.encoders import jsonable_encoder\nfrom fastapi.openapi.constants import METHODS_WITH_BODY, REF_PREFIX, REF_TEMPLATE\nfrom fastapi.openapi.models import OpenAPI\nfrom fastapi.params import Body, ParamTypes\nfrom fastapi.responses import Response\nfrom fastapi.types import ModelNameMap\nfrom fastapi.utils import (\n deep_dict_update,\n generate_operation_id_for_path,\n is_body_allowed_for_status_code,\n)\nfrom pydantic import BaseModel\nfrom starlette.responses import JSONResponse\nfrom starlette.routing import BaseRoute\nfrom typing_extensions import Literal\n\nvalidation_error_definition = {\n \"title\": \"ValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"loc\": {\n \"title\": \"Location\",\n \"type\": \"array\",\n \"items\": {\"anyOf\": [{\"type\": \"string\"}, {\"type\": \"integer\"}]},\n },\n \"msg\": {\"title\": \"Message\", \"type\": \"string\"},\n \"type\": {\"title\": \"Error Type\", \"type\": \"string\"},\n },\n \"required\": [\"loc\", \"msg\", \"type\"],\n}\n\nvalidation_error_response_definition = {\n \"title\": \"HTTPValidationError\",\n \"type\": \"object\",\n \"properties\": {\n \"detail\": {\n \"title\": \"Detail\",\n |
| 17 | run_command | {
"command": "grep -n \"def get_openapi\" fastapi/openapi/utils.py"
} | {"status": "ok", "stdout": "77:def get_openapi_security_definitions(\n169:def get_openapi_operation_request_body(\n227:def get_openapi_operation_metadata(\n253:full{"status": "ok", "stdout": "77:def get_openapi_security_definitions(\n169:def get_openapi_operation_request_body(\n227:def get_openapi_operation_metadata(\n253:def get_openapi_path(\n476:def get_openapi(\n", "exit_code": 0} |
| 18 | read_file | {
"end_line": 500,
"filepath": "fastapi/openapi/utils.py",
"start_line": 476
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "def get_openapi(\n *,\n title: str,\n version: str,\n openapi_version: str = \"3.1.0\",\n sfull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": "def get_openapi(\n *,\n title: str,\n version: str,\n openapi_version: str = \"3.1.0\",\n summary: Optional[str] = None,\n description: Optional[str] = None,\n routes: Sequence[BaseRoute],\n webhooks: Optional[Sequence[BaseRoute]] = None,\n tags: Optional[List[Dict[str, Any]]] = None,\n servers: Optional[List[Dict[str, Union[str, Any]]]] = None,\n terms_of_service: Optional[str] = None,\n contact: Optional[Dict[str, Union[str, Any]]] = None,\n license_info: Optional[Dict[str, Union[str, Any]]] = None,\n separate_input_output_schemas: bool = True,\n) -> Dict[str, Any]:\n info: Dict[str, Any] = {\"title\": title, \"version\": version}\n if summary:\n info[\"summary\"] = summary\n if description:\n info[\"description\"] = description\n if terms_of_service:\n info[\"termsOfService\"] = terms_of_service\n if contact:\n info[\"contact\"] = contact\n", "start_line": 476, "end_line": 500, "total_lines": 568, "is_truncated": false} |
| 19 | read_file | {
"end_line": 568,
"filepath": "fastapi/openapi/utils.py",
"start_line": 470
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": " flat_models = callback_flat_models + list(\n body_fields_from_routes + responses_from_routfull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "content": " flat_models = callback_flat_models + list(\n body_fields_from_routes + responses_from_routes + request_fields_from_routes\n )\n return flat_models\n\n\ndef get_openapi(\n *,\n title: str,\n version: str,\n openapi_version: str = \"3.1.0\",\n summary: Optional[str] = None,\n description: Optional[str] = None,\n routes: Sequence[BaseRoute],\n webhooks: Optional[Sequence[BaseRoute]] = None,\n tags: Optional[List[Dict[str, Any]]] = None,\n servers: Optional[List[Dict[str, Union[str, Any]]]] = None,\n terms_of_service: Optional[str] = None,\n contact: Optional[Dict[str, Union[str, Any]]] = None,\n license_info: Optional[Dict[str, Union[str, Any]]] = None,\n separate_input_output_schemas: bool = True,\n) -> Dict[str, Any]:\n info: Dict[str, Any] = {\"title\": title, \"version\": version}\n if summary:\n info[\"summary\"] = summary\n if description:\n info[\"description\"] = description\n if terms_of_service:\n info[\"termsOfService\"] = terms_of_service\n if contact:\n info[\"contact\"] = contact\n if license_info:\n info[\"license\"] = license_info\n output: Dict[str, Any] = {\"openapi\": openapi_version, \"info\": info}\n if servers:\n output[\"servers\"] = servers\n components: Dict[str, Dict[str, Any]] = {}\n paths: Dict[str, Dict[str, Any]] = {}\n webhook_paths: Dict[str, Dict[str, Any]] = {}\n operation_ids: Set[str] = set()\n all_fields = get_fields_from_routes(list(routes or []) + list(webhooks or []))\n model_name_map = get_compat_model_name_map(all_fields)\n schema_generator = GenerateJsonSchema(ref_template=REF_TEMPLATE)\n field_mapping, definitions = get_definitions(\n fields=all_fields,\n schema_generator=schema_generator,\n model_name_map=model_name_map,\n separate_input_output_schemas=separate_input_output_schemas,\ |
| 20 | read_file | {
"end_line": 100,
"filepath": "fastapi/openapi/models.py",
"start_line": 1
} | {"status": "ok", "filepath": "fastapi/openapi/models.py", "content": "from enum import Enum\nfrom typing import Any, Callable, Dict, Iterable, List, Optional, Sfull{"status": "ok", "filepath": "fastapi/openapi/models.py", "content": "from enum import Enum\nfrom typing import Any, Callable, Dict, Iterable, List, Optional, Set, Type, Union\n\nfrom fastapi._compat import (\n PYDANTIC_V2,\n CoreSchema,\n GetJsonSchemaHandler,\n JsonSchemaValue,\n _model_rebuild,\n with_info_plain_validator_function,\n)\nfrom fastapi.logger import logger\nfrom pydantic import AnyUrl, BaseModel, Field\nfrom typing_extensions import Annotated, Literal, TypedDict\nfrom typing_extensions import deprecated as typing_deprecated\n\ntry:\n import email_validator\n\n assert email_validator # make autoflake ignore the unused import\n from pydantic import EmailStr\nexcept ImportError: # pragma: no cover\n\n class EmailStr(str): # type: ignore\n @classmethod\n def __get_validators__(cls) -> Iterable[Callable[..., Any]]:\n yield cls.validate\n\n @classmethod\n def validate(cls, v: Any) -> str:\n logger.warning(\n \"email-validator not installed, email fields will be treated as str.\\n\"\n \"To install, run: pip install email-validator\"\n )\n return str(v)\n\n @classmethod\n def _validate(cls, __input_value: Any, _: Any) -> str:\n logger.warning(\n \"email-validator not installed, email fields will be treated as str.\\n\"\n \"To install, run: pip install email-validator\"\n )\n return str(__input_value)\n\n @classmethod\n def __get_pydantic_json_schema__(\n cls, core_schema: CoreSchema, handler: GetJsonSchemaHandler\n ) -> JsonSchemaValue:\n return {\"type\": \"string\", \"format\": \"email\"}\n\n @classmethod\n def __get_pydantic_core_schema__(\n cls, source: Type[Any], handler: Callable[[Any], CoreSchema]\n ) -> CoreSchema:\n return with_info_plain_validator_function |
| 21 | read_file | {
"end_line": 150,
"filepath": "fastapi/openapi/models.py",
"start_line": 101
} | {"status": "ok", "filepath": "fastapi/openapi/models.py", "content": "\nclass Reference(BaseModel):\n ref: str = Field(alias=\"$ref\")\n\n\nclass Discriminator(full{"status": "ok", "filepath": "fastapi/openapi/models.py", "content": "\nclass Reference(BaseModel):\n ref: str = Field(alias=\"$ref\")\n\n\nclass Discriminator(BaseModel):\n propertyName: str\n mapping: Optional[Dict[str, str]] = None\n\n\nclass XML(BaseModelWithConfig):\n name: Optional[str] = None\n namespace: Optional[str] = None\n prefix: Optional[str] = None\n attribute: Optional[bool] = None\n wrapped: Optional[bool] = None\n\n\nclass ExternalDocumentation(BaseModelWithConfig):\n description: Optional[str] = None\n url: AnyUrl\n\n\nclass Schema(BaseModelWithConfig):\n # Ref: JSON Schema 2020-12: https://json-schema.org/draft/2020-12/json-schema-core.html#name-the-json-schema-core-vocabu\n # Core Vocabulary\n schema_: Optional[str] = Field(default=None, alias=\"$schema\")\n vocabulary: Optional[str] = Field(default=None, alias=\"$vocabulary\")\n id: Optional[str] = Field(default=None, alias=\"$id\")\n anchor: Optional[str] = Field(default=None, alias=\"$anchor\")\n dynamicAnchor: Optional[str] = Field(default=None, alias=\"$dynamicAnchor\")\n ref: Optional[str] = Field(default=None, alias=\"$ref\")\n dynamicRef: Optional[str] = Field(default=None, alias=\"$dynamicRef\")\n defs: Optional[Dict[str, \"SchemaOrBool\"]] = Field(default=None, alias=\"$defs\")\n comment: Optional[str] = Field(default=None, alias=\"$comment\")\n # Ref: JSON Schema 2020-12: https://json-schema.org/draft/2020-12/json-schema-core.html#name-a-vocabulary-for-applying-s\n # A Vocabulary for Applying Subschemas\n allOf: Optional[List[\"SchemaOrBool\"]] = None\n anyOf: Optional[List[\"SchemaOrBool\"]] = None\n oneOf: Optional[List[\"SchemaOrBool\"]] = None\n not_: Optional[\"SchemaOrBool\"] = Field(default=None, alias=\"not\")\n if_: Optional[\"SchemaOrBool\"] = Field(default=None, alias=\"if\")\n then: Optional[\"SchemaOrBool\"] = None\n else_: Optional[\"SchemaOrBool\"] = Field(default=None, alias=\"els |
| 22 | read_file | {
"end_line": 445,
"filepath": "fastapi/openapi/models.py",
"start_line": 400
} | {"status": "ok", "filepath": "fastapi/openapi/models.py", "content": " type_: SecuritySchemeType = Field(\n default=SecuritySchemeType.openIdConnect, alias=\"tyfull{"status": "ok", "filepath": "fastapi/openapi/models.py", "content": " type_: SecuritySchemeType = Field(\n default=SecuritySchemeType.openIdConnect, alias=\"type\"\n )\n openIdConnectUrl: str\n\n\nSecurityScheme = Union[APIKey, HTTPBase, OAuth2, OpenIdConnect, HTTPBearer]\n\n\nclass Components(BaseModelWithConfig):\n schemas: Optional[Dict[str, Union[Schema, Reference]]] = None\n responses: Optional[Dict[str, Union[Response, Reference]]] = None\n parameters: Optional[Dict[str, Union[Parameter, Reference]]] = None\n examples: Optional[Dict[str, Union[Example, Reference]]] = None\n requestBodies: Optional[Dict[str, Union[RequestBody, Reference]]] = None\n headers: Optional[Dict[str, Union[Header, Reference]]] = None\n securitySchemes: Optional[Dict[str, Union[SecurityScheme, Reference]]] = None\n links: Optional[Dict[str, Union[Link, Reference]]] = None\n # Using Any for Specification Extensions\n callbacks: Optional[Dict[str, Union[Dict[str, PathItem], Reference, Any]]] = None\n pathItems: Optional[Dict[str, Union[PathItem, Reference]]] = None\n\n\nclass Tag(BaseModelWithConfig):\n name: str\n description: Optional[str] = None\n externalDocs: Optional[ExternalDocumentation] = None\n\n\nclass OpenAPI(BaseModelWithConfig):\n openapi: str\n info: Info\n jsonSchemaDialect: Optional[str] = None\n servers: Optional[List[Server]] = None\n # Using Any for Specification Extensions\n paths: Optional[Dict[str, Union[PathItem, Any]]] = None\n webhooks: Optional[Dict[str, Union[PathItem, Reference]]] = None\n components: Optional[Components] = None\n security: Optional[List[Dict[str, List[str]]]] = None\n tags: Optional[List[Tag]] = None\n externalDocs: Optional[ExternalDocumentation] = None\n\n\n_model_rebuild(Schema)\n_model_rebuild(Operation)\n_model_rebuild(Encoding)\n", "start_line": 400, "end_line": 445, "total_lines": 445, "is_truncated": false} |
| 23 | read_file | {
"end_line": 640,
"filepath": "fastapi/applications.py",
"start_line": 630
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n A URL prefix for the OpenAPI URL.\n \"\"\"\n ),\n deprecated(\n \"\"\"\n \"openapifull{"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n A URL prefix for the OpenAPI URL.\n \"\"\"\n ),\n deprecated(\n \"\"\"\n \"openapi_prefix\" has been deprecated in favor of \"root_path\", which\n follows more closely the ASGI standard, is simpler, and more\n automatic.\n \"\"\"\n ),\n", "start_line": 630, "end_line": 640, "total_lines": 4588, "is_truncated": false} |
| 24 | read_file | {
"end_line": 635,
"filepath": "fastapi/applications.py",
"start_line": 625
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " ),\n ] = None,\n openapi_prefix: Annotated[\n str,\n Doc(\n \"\"\"\n A URL prefix for the Ofull{"status": "ok", "filepath": "fastapi/applications.py", "content": " ),\n ] = None,\n openapi_prefix: Annotated[\n str,\n Doc(\n \"\"\"\n A URL prefix for the OpenAPI URL.\n \"\"\"\n ),\n deprecated(\n \"\"\"\n", "start_line": 625, "end_line": 635, "total_lines": 4588, "is_truncated": false} |