failed WRONG_FIX wrong_fix · 33 tool calls · 153 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 \"def __init__\" fastapi/applications.py"
} | {"status": "ok", "stdout": "64: def __init__(\n4568: def __init__(self, name: str):\n", "exit_code": 0}full{"status": "ok", "stdout": "64: def __init__(\n4568: def __init__(self, name: str):\n", "exit_code": 0} |
| 2 | read_file | {
"filepath": "fastapi/applications.py",
"start_line": 64,
"end_line": 120
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " def __init__(\n self: AppType,\n *,\n debug: Annotated[\n bool,\n Doc(\n \"\"\"\n Boolean ifull{"status": "ok", "filepath": "fastapi/applications.py", "content": " 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.tiangolo.com/tutorial/metadata/#metadata-for-api).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(title=\"ChimichangApp\")\n ```\n \"\"\"\n ),\n", "start_line": 64, "end_line": 120, "total_lines": 45 |
| 3 | read_file | {
"end_line": 160,
"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", "start_line": 121, "end_line": 160, "total_lines": 4588, "is_truncated": false} |
| 4 | read_file | {
"end_line": 200,
"filepath": "fastapi/applications.py",
"start_line": 161
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " description=\"\"\"\n ChimichangApp API helps you do awesome stuff. \ud83d\ude80\n\n ## Itemfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " 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: Annotated[\n str,\n Doc(\n \"\"\"\n The version of the API.\n\n **Note** This is the version of your application, not the version of\n the OpenAPI specification nor the version of FastAPI being used.\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(version=\"0.0.1\")\n", "start_line": 161, "end_line": 200, "total_lines": 4588, "is_truncated": false} |
| 5 | read_file | {
"end_line": 250,
"filepath": "fastapi/applications.py",
"start_line": 201
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " ```\n \"\"\"\n ),\n ] = \"0.1.0\",\n openapi_url: Annotated[\n Optional[str],\n Doc(\n \"\"full{"status": "ok", "filepath": "fastapi/applications.py", "content": " ```\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 tag.\n [CommonMark syntax](https://commonmark.org/) MAY be used for rich\n", "s |
| 6 | read_file | {
"end_line": 300,
"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 |
| 7 | read_file | {
"end_line": 350,
"filepath": "fastapi/applications.py",
"start_line": 301
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "\n Each item in the `list` is a `dict` containing:\n\n * `url`: A URL to the target host. Thfull{"status": "ok", "filepath": "fastapi/applications.py", "content": "\n Each item in the `list` is a `dict` containing:\n\n * `url`: A URL to the target host. This URL supports Server Variables\n and MAY be relative, to indicate that the host location is relative\n to the location where the OpenAPI document is being served. Variable\n substitutions will be made when a variable is named in `{`brackets`}`.\n * `description`: An optional string describing the host designated by\n the URL. [CommonMark syntax](https://commonmark.org/) MAY be used for\n rich text representation.\n * `variables`: A `dict` between a variable name and its value. The value\n is used for substitution in the server's URL template.\n\n Read more in the\n [FastAPI docs for Behind a Proxy](https://fastapi.tiangolo.com/advanced/behind-a-proxy/#additional-servers).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(\n servers=[\n {\"url\": \"https://stag.example.com\", \"description\": \"Staging environment\"},\n {\"url\": \"https://prod.example.com\", \"description\": \"Production environment\"},\n ]\n )\n ```\n \"\"\"\n ),\n ] = None,\n dependencies: Annotated[\n Optional[Sequence[Depends]],\n Doc(\n \"\"\"\n A list of global dependencies, they will be applied to each\n *path operation*, including in sub-routers.\n\n Read more about it in the\n [FastAPI docs for Global Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/global-dependencies/).\n\n **Example**\ |
| 8 | 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} |
| 9 | 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} |
| 10 | 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, " |
| 11 | 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} |
| 12 | 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} |
| 13 | 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 |
| 14 | read_file | {
"end_line": 700,
"filepath": "fastapi/applications.py",
"start_line": 651
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(root_path=\"/apfull{"status": "ok", "filepath": "fastapi/applications.py", "content": "\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(root_path=\"/api/v1\")\n ```\n \"\"\"\n ),\n ] = \"\",\n root_path_in_servers: Annotated[\n bool,\n Doc(\n \"\"\"\n To disable automatically generating the URLs in the `servers` field\n in the autogenerated OpenAPI using the `root_path`.\n\n Read more about it in the\n [FastAPI docs for Behind a Proxy](https://fastapi.tiangolo.com/advanced/behind-a-proxy/#disable-automatic-server-from-root_path).\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI(root_path_in_servers=False)\n ```\n \"\"\"\n ),\n ] = True,\n responses: Annotated[\n Optional[Dict[Union[int, str], Dict[str, Any]]],\n Doc(\n \"\"\"\n Additional responses to be shown in OpenAPI.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more about it in the\n [FastAPI docs for Additional Responses in OpenAPI](https://fastapi.tiangolo.com/advanced/additional-responses/).\n\n And in the\n [FastAPI docs for Bigger Applications](https://fastapi.tiangolo.com/tutorial/bigger-applications/#include-an-apirouter-with-a-custom-prefix-tags-responses-and-dependencies).\n \"\"\"\n ),\n ] = None,\n callbacks: Annotated[\n Optional[List[BaseRoute]],\n Doc(\n", "start_line": 651, "end_line": 700, "total_lines": 4588, "is_truncated": false} |
| 15 | read_file | {
"end_line": 750,
"filepath": "fastapi/applications.py",
"start_line": 701
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n OpenAPI callbacks that should apply to all *path operations*.\n\n It will be addedfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n OpenAPI callbacks that should apply to all *path operations*.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more about it in the\n [FastAPI docs for OpenAPI Callbacks](https://fastapi.tiangolo.com/advanced/openapi-callbacks/).\n \"\"\"\n ),\n ] = None,\n webhooks: Annotated[\n Optional[routing.APIRouter],\n Doc(\n \"\"\"\n Add OpenAPI webhooks. This is similar to `callbacks` but it doesn't\n depend on specific *path operations*.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n **Note**: This is available since OpenAPI 3.1.0, FastAPI 0.99.0.\n\n Read more about it in the\n [FastAPI docs for OpenAPI Webhooks](https://fastapi.tiangolo.com/advanced/openapi-webhooks/).\n \"\"\"\n ),\n ] = None,\n deprecated: Annotated[\n Optional[bool],\n Doc(\n \"\"\"\n Mark all *path operations* as deprecated. You probably don't need it,\n but it's available.\n\n It will be added to the generated OpenAPI (e.g. visible at `/docs`).\n\n Read more about it in the\n [FastAPI docs for Path Operation Configuration](https://fastapi.tiangolo.com/tutorial/path-operation-configuration/).\n \"\"\"\n ),\n ] = None,\n include_in_schema: Annotated[\n bool,\n Doc(\n \"\"\"\n To include (or not) all the *path operations* in the generated OpenAPI.\n You probably don't need it, but it's available.\n\n This affects the generated OpenAPI (e.g. visible at `/doc |
| 16 | read_file | {
"end_line": 800,
"filepath": "fastapi/applications.py",
"start_line": 751
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " [FastAPI docs for Query Parameters and String Validations](https://fastapi.tiangolo.com/tutfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " [FastAPI docs for Query Parameters and String Validations](https://fastapi.tiangolo.com/tutorial/query-params-str-validations/#exclude-parameters-from-openapi).\n \"\"\"\n ),\n ] = True,\n swagger_ui_parameters: Annotated[\n Optional[Dict[str, Any]],\n Doc(\n \"\"\"\n Parameters to configure Swagger UI, the autogenerated interactive API\n documentation (by default at `/docs`).\n\n Read more about it in the\n [FastAPI docs about how to Configure Swagger UI](https://fastapi.tiangolo.com/how-to/configure-swagger-ui/).\n \"\"\"\n ),\n ] = None,\n generate_unique_id_function: Annotated[\n Callable[[routing.APIRoute], str],\n Doc(\n \"\"\"\n Customize the function used to generate unique IDs for the *path\n operations* shown in the generated OpenAPI.\n\n This is particularly useful when automatically generating clients or\n SDKs for your API.\n\n Read more about it in the\n [FastAPI docs about how to Generate Clients](https://fastapi.tiangolo.com/advanced/generate-clients/#custom-generate-unique-id-function).\n \"\"\"\n ),\n ] = Default(generate_unique_id),\n separate_input_output_schemas: Annotated[\n bool,\n Doc(\n \"\"\"\n Whether to generate separate OpenAPI schemas for request body and\n response body when the results would be more precise.\n\n This is particularly useful when automatically generating clients.\n\n For example, if you have a model like:\n\n ```python\n from pydantic import BaseModel\n\n class |
| 17 | read_file | {
"end_line": 850,
"filepath": "fastapi/applications.py",
"start_line": 801
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " When `Item` is used for input, a request body, `tags` is not required,\n the client doesn'tfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " When `Item` is used for input, a request body, `tags` is not required,\n the client doesn't have to provide it.\n\n But when using `Item` for output, for a response body, `tags` is always\n available because it has a default value, even if it's just an empty\n list. So, the client should be able to always expect it.\n\n In this case, there would be two different schemas, one for input and\n another one for output.\n \"\"\"\n ),\n ] = True,\n **extra: Annotated[\n Any,\n Doc(\n \"\"\"\n Extra keyword arguments to be stored in the app, not used by FastAPI\n anywhere.\n \"\"\"\n ),\n ],\n ) -> None:\n self.debug = debug\n self.title = title\n self.summary = summary\n self.description = description\n self.version = version\n self.terms_of_service = terms_of_service\n self.contact = contact\n self.license_info = license_info\n self.openapi_url = openapi_url\n self.openapi_tags = openapi_tags\n self.root_path_in_servers = root_path_in_servers\n self.docs_url = docs_url\n self.redoc_url = redoc_url\n self.swagger_ui_oauth2_redirect_url = swagger_ui_oauth2_redirect_url\n self.swagger_ui_init_oauth = swagger_ui_init_oauth\n self.swagger_ui_parameters = swagger_ui_parameters\n self.servers = servers or []\n self.separate_input_output_schemas = separate_input_output_schemas\n self.extra = extra\n self.openapi_version: Annotated[\n str,\n Doc(\n \"\"\"\n The version string of OpenAPI.\n\n FastAPI will generate OpenAPI version 3.1.0, and will output that as\n |
| 18 | read_file | {
"end_line": 880,
"filepath": "fastapi/applications.py",
"start_line": 851
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": "\n So you could override this value to trick those tools into using\n the generated OpenAPI.full{"status": "ok", "filepath": "fastapi/applications.py", "content": "\n So you could override this value to trick those tools into using\n the generated OpenAPI. Have in mind that this is a hack. But if you\n avoid using features added in OpenAPI 3.1.0, it might work for your\n use case.\n\n This is not passed as a parameter to the `FastAPI` class to avoid\n giving the false idea that FastAPI would generate a different OpenAPI\n schema. It is only available as an attribute.\n\n **Example**\n\n ```python\n from fastapi import FastAPI\n\n app = FastAPI()\n\n app.openapi_version = \"3.0.2\"\n ```\n \"\"\"\n ),\n ] = \"3.1.0\"\n self.openapi_schema: Optional[Dict[str, Any]] = None\n if self.openapi_url:\n assert self.title, \"A title must be provided for OpenAPI, e.g.: 'My API'\"\n assert self.version, \"A version must be provided for OpenAPI, e.g.: '2.1.0'\"\n # TODO: remove when discarding the openapi_prefix parameter\n if openapi_prefix:\n logger.warning(\n '\"openapi_prefix\" has been deprecated in favor of \"root_path\", which '\n", "start_line": 851, "end_line": 880, "total_lines": 4588, "is_truncated": false} |
| 19 | 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 |
| 20 | read_file | {
"end_line": 120,
"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", "start_line": 101, "end_line": 120, "total_lines": 445, "is_truncated": false} |
| 21 | read_file | {
"end_line": 130,
"filepath": "fastapi/openapi/models.py",
"start_line": 115
} | {"status": "ok", "filepath": "fastapi/openapi/models.py", "content": " attribute: Optional[bool] = None\n wrapped: Optional[bool] = None\n\n\nclass ExternalDocufull{"status": "ok", "filepath": "fastapi/openapi/models.py", "content": " 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", "start_line": 115, "end_line": 130, "total_lines": 445, "is_truncated": false} |
| 22 | 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 |
| 23 | run_command | {
"command": "grep -rn \"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} |
| 24 | read_file | {
"end_line": 568,
"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 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,\n )\n for route in routes or []:\n if isinstance(route, routing.APIRoute):\n result = get_openapi_path(\n route=route,\n |
| 25 | read_file | {
"end_line": 130,
"filepath": "fastapi/openapi/models.py",
"start_line": 70
} | {"status": "ok", "filepath": "fastapi/openapi/models.py", "content": " url: Optional[AnyUrl] = None\n email: Optional[EmailStr] = None\n\n\nclass License(BaseMofull{"status": "ok", "filepath": "fastapi/openapi/models.py", "content": " url: Optional[AnyUrl] = None\n email: Optional[EmailStr] = None\n\n\nclass License(BaseModelWithConfig):\n name: str\n identifier: Optional[str] = None\n url: Optional[AnyUrl] = None\n\n\nclass Info(BaseModelWithConfig):\n title: str\n summary: Optional[str] = None\n description: Optional[str] = None\n termsOfService: Optional[str] = None\n contact: Optional[Contact] = None\n license: Optional[License] = None\n version: str\n\n\nclass ServerVariable(BaseModelWithConfig):\n enum: Annotated[Optional[List[str]], Field(min_length=1)] = None\n default: str\n description: Optional[str] = None\n\n\nclass Server(BaseModelWithConfig):\n url: Union[AnyUrl, str]\n description: Optional[str] = None\n variables: Optional[Dict[str, ServerVariable]] = None\n\n\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", "start_line": 70, "end_line": 130, "total_lines": 445, "is_truncated": false} |
| 26 | edit_file | {
"filepath": "fastapi/openapi/models.py",
"new_string": "class Info(BaseModelWithConfig):\n title: str\n summary: Optional[str] = None\n description: Optional[str] = None\n termsOfService: Optional[str] = None\n contact: Optional[Contact] = None\n license: Optional[License] = None\n externalDocs: Optional[ExternalDocumentation] = None\n version: str",
"old_string": "class Info(BaseModelWithConfig):\n title: str\n summary: Optional[str] = None\n description: Optional[str] = None\n termsOfService: Optional[str] = None\n contact: Optional[Contact] = None\n license: Optional[License] = None\n version: str"
} | {"status": "ok", "filepath": "fastapi/openapi/models.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/models.py\n+++ b/fastapi/openapifull{"status": "ok", "filepath": "fastapi/openapi/models.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/models.py\n+++ b/fastapi/openapi/models.py\n@@ -84,6 +84,7 @@\n termsOfService: Optional[str] = None\n contact: Optional[Contact] = None\n license: Optional[License] = None\n+ externalDocs: Optional[ExternalDocumentation] = None\n version: str\n \n \n", "is_truncated": false} |
| 27 | edit_file | {
"filepath": "fastapi/openapi/utils.py",
"new_string": " 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 external_docs: 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 if external_docs:\n info[\"externalDocs\"] = external_docs\n output: Dict[str, Any] = {\"openapi\": openapi_version, \"info\": info}",
"old_string": " 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}"
} | {"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/ufull{"status": "ok", "filepath": "fastapi/openapi/utils.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/openapi/utils.py\n+++ b/fastapi/openapi/utils.py\n@@ -487,6 +487,7 @@\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+ external_docs: 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@@ -500,6 +501,8 @@\n info[\"contact\"] = contact\n if license_info:\n info[\"license\"] = license_info\n+ if external_docs:\n+ info[\"externalDocs\"] = external_docs\n output: Dict[str, Any] = {\"openapi\": openapi_version, \"info\": info}\n if servers:\n output[\"servers\"] = servers\n", "is_truncated": false} |
| 28 | read_file | {
"end_line": 830,
"filepath": "fastapi/applications.py",
"start_line": 780
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " ),\n ] = Default(generate_unique_id),\n separate_input_output_schemas: Annotated[\n bool,\nfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " ),\n ] = Default(generate_unique_id),\n separate_input_output_schemas: Annotated[\n bool,\n Doc(\n \"\"\"\n Whether to generate separate OpenAPI schemas for request body and\n response body when the results would be more precise.\n\n This is particularly useful when automatically generating clients.\n\n For example, if you have a model like:\n\n ```python\n from pydantic import BaseModel\n\n class Item(BaseModel):\n name: str\n tags: list[str] = []\n ```\n\n When `Item` is used for input, a request body, `tags` is not required,\n the client doesn't have to provide it.\n\n But when using `Item` for output, for a response body, `tags` is always\n available because it has a default value, even if it's just an empty\n list. So, the client should be able to always expect it.\n\n In this case, there would be two different schemas, one for input and\n another one for output.\n \"\"\"\n ),\n ] = True,\n **extra: Annotated[\n Any,\n Doc(\n \"\"\"\n Extra keyword arguments to be stored in the app, not used by FastAPI\n anywhere.\n \"\"\"\n ),\n ],\n ) -> None:\n self.debug = debug\n self.title = title\n self.summary = summary\n self.description = description\n self.version = version\n self.terms_of_service = terms_of_service\n self.contact = contact\n self.license_info = license_info\n", "start_line": 780, "end_line": 830, "total_lines": 4588, "is_truncated": false} |
| 29 | edit_file | {
"filepath": "fastapi/applications.py",
"new_string": " separate_input_output_schemas: Annotated[\n bool,\n Doc(\n \"\"\"\n Whether to generate separate OpenAPI schemas for request body and\n response body when the results would be more precise.\n\n This is particularly useful when automatically generating clients.\n\n For example, if you have a model like:\n\n ```python\n from pydantic import BaseModel\n\n class Item(BaseModel):\n name: str\n tags: list[str] = []\n ```\n\n When `Item` is used for input, a request body, `tags` is not required,\n the client doesn't have to provide it.\n\n But when using `Item` for output, for a response body, `tags` is always\n available because it has a default value, even if it's just an empty\n list. So, the client should be able to always expect it.\n\n In this case, there would be two different schemas, one for input and\n another one for output.\n \"\"\"\n ),\n ] = True,\n external_docs: Annotated[\n Optional[Dict[str, Union[str, Any]]],\n Doc(\n \"\"\"\n A dictionary with the external documentation for the exposed API.\n\n It can contain several fields.\n\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 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 external_docs={\n \"description\": \"External documentation\",\n \"url\": \"https://fastapi.tiangolo.com/\",\n }\n )\n ```\n \"\"\"\n ),\n ] = None,\n **extra: Annotated[\n Any,\n Doc(\n \"\"\"\n Extra keyword arguments to be stored in the app, not used by FastAPI\n anywhere.\n \"\"\"\n ),\n ],\n ) -> None:\n self.debug = debug\n self.title = title\n self.summary = summary\n self.description = description\n self.version = version\n self.terms_of_service = terms_of_service\n self.contact = contact\n self.license_info = license_info\n self.external_docs = external_docs",
"old_string": " separate_input_output_schemas: Annotated[\n bool,\n Doc(\n \"\"\"\n Whether to generate separate OpenAPI schemas for request body and\n response body when the results would be more precise.\n\n This is particularly useful when automatically generating clients.\n\n For example, if you have a model like:\n\n ```python\n from pydantic import BaseModel\n\n class Item(BaseModel):\n name: str\n tags: list[str] = []\n ```\n\n When `Item` is used for input, a request body, `tags` is not required,\n the client doesn't have to provide it.\n\n But when using `Item` for output, for a response body, `tags` is always\n availa | {"status": "ok", "filepath": "fastapi/applications.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/applications.py\n+++ b/fastapi/applicationfull{"status": "ok", "filepath": "fastapi/applications.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/applications.py\n+++ b/fastapi/applications.py\n@@ -810,6 +810,38 @@\n \"\"\"\n ),\n ] = True,\n+ external_docs: Annotated[\n+ Optional[Dict[str, Union[str, Any]]],\n+ Doc(\n+ \"\"\"\n+ A dictionary with the external documentation for the exposed API.\n+\n+ It can contain several fields.\n+\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+ 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+ external_docs={\n+ \"description\": \"External documentation\",\n+ \"url\": \"https://fastapi.tiangolo.com/\",\n+ }\n+ )\n+ ```\n+ \"\"\"\n+ ),\n+ ] = None,\n **extra: Annotated[\n Any,\n Doc(\n@@ -828,6 +860,7 @@\n self.terms_of_service = terms_of_service\n self.contact = contact\n self.license_info = license_info\n+ self.external_docs = external_docs\n self.openapi_url = openapi_url\n self.openapi_tags = openapi_tags\n self.root_path_in_servers = root_path_in_servers\n", "is_truncated": false} |
| 30 | run_command | {
"command": "grep -rn \"def get_openapi_schema\" fastapi/applications.py"
} | {"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "", "exit_code": 1}}full{"status": "error", "error_type": "CommandError", "error_message": "Command failed with exit code 1", "details": {"stdout": "", "stderr": "", "exit_code": 1}} |
| 31 | run_command | {
"command": "grep -rn \"get_openapi\" fastapi/applications.py | head -20"
} | {"status": "ok", "stdout": "30:from fastapi.openapi.utils import get_openapi\n1014: self.openapi_schema = get_openapi(\n", "exit_code": 0}full{"status": "ok", "stdout": "30:from fastapi.openapi.utils import get_openapi\n1014: self.openapi_schema = get_openapi(\n", "exit_code": 0} |
| 32 | read_file | {
"end_line": 1030,
"filepath": "fastapi/applications.py",
"start_line": 1000
} | {"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\n Generate the OpenAPI schema of the application. This is called by FastAPI\n internfull{"status": "ok", "filepath": "fastapi/applications.py", "content": " \"\"\"\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", "start_line": 1000, "end_line": 1030, "total_lines": 4621, "is_truncated": false} |
| 33 | edit_file | {
"filepath": "fastapi/applications.py",
"new_string": " terms_of_service=self.terms_of_service,\n contact=self.contact,\n license_info=self.license_info,\n external_docs=self.external_docs,\n routes=self.routes,",
"old_string": " terms_of_service=self.terms_of_service,\n contact=self.contact,\n license_info=self.license_info,\n routes=self.routes,"
} | {"status": "ok", "filepath": "fastapi/applications.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/applications.py\n+++ b/fastapi/applicationfull{"status": "ok", "filepath": "fastapi/applications.py", "occurrences": 1, "strategy": "exact", "diff": "--- a/fastapi/applications.py\n+++ b/fastapi/applications.py\n@@ -1020,6 +1020,7 @@\n terms_of_service=self.terms_of_service,\n contact=self.contact,\n license_info=self.license_info,\n+ external_docs=self.external_docs,\n routes=self.routes,\n webhooks=self.webhooks.routes,\n tags=self.openapi_tags,\n", "is_truncated": false} |
| 34 | submit_patch | [] | {"status": "ok", "patch_size": 3577, "files_changed": 3}full{"status": "ok", "patch_size": 3577, "files_changed": 3} |
diff --git a/fastapi/applications.py b/fastapi/applications.py
index 05c7bd2b..4a9f5f4f 100644
--- a/fastapi/applications.py
+++ b/fastapi/applications.py
@@ -810,6 +810,38 @@ class FastAPI(Starlette):
"""
),
] = True,
+ external_docs: Annotated[
+ Optional[Dict[str, Union[str, Any]]],
+ Doc(
+ """
+ A dictionary with the external documentation for the exposed API.
+
+ It can contain several fields.
+
+ * `description`: A short description of the target documentation.
+ [CommonMark syntax](https://commonmark.org/) MAY be used for
+ rich text representation.
+ * `url`: The URL for the target documentation. Value MUST be in
+ the form of a URL.
+
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
+
+ Read more at the
+ [FastAPI docs for Metadata and Docs URLs](https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-api).
+
+ **Example**
+
+ ```python
+ app = FastAPI(
+ external_docs={
+ "description": "External documentation",
+ "url": "https://fastapi.tiangolo.com/",
+ }
+ )
+ ```
+ """
+ ),
+ ] = None,
**extra: Annotated[
Any,
Doc(
@@ -828,6 +860,7 @@ class FastAPI(Starlette):
self.terms_of_service = terms_of_service
self.contact = contact
self.license_info = license_info
+ self.external_docs = external_docs
self.openapi_url = openapi_url
self.openapi_tags = openapi_tags
self.root_path_in_servers = root_path_in_servers
@@ -987,6 +1020,7 @@ class FastAPI(Starlette):
terms_of_service=self.terms_of_service,
contact=self.contact,
license_info=self.license_info,
+ external_docs=self.external_docs,
routes=self.routes,
webhooks=self.webhooks.routes,
tags=self.openapi_tags,
diff --git a/fastapi/openapi/models.py b/fastapi/openapi/models.py
index ed07b40f..b5a165c5 100644
--- a/fastapi/openapi/models.py
+++ b/fastapi/openapi/models.py
@@ -84,6 +84,7 @@ class Info(BaseModelWithConfig):
termsOfService: Optional[str] = None
contact: Optional[Contact] = None
license: Optional[License] = None
+ externalDocs: Optional[ExternalDocumentation] = None
version: str
diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py
index eda64a99..b88f874b 100644
--- a/fastapi/openapi/utils.py
+++ b/fastapi/openapi/utils.py
@@ -487,6 +487,7 @@ def get_openapi(
terms_of_service: Optional[str] = None,
contact: Optional[Dict[str, Union[str, Any]]] = None,
license_info: Optional[Dict[str, Union[str, Any]]] = None,
+ external_docs: Optional[Dict[str, Union[str, Any]]] = None,
separate_input_output_schemas: bool = True,
) -> Dict[str, Any]:
info: Dict[str, Any] = {"title": title, "version": version}
@@ -500,6 +501,8 @@ def get_openapi(
info["contact"] = contact
if license_info:
info["license"] = license_info
+ if external_docs:
+ info["externalDocs"] = external_docs
output: Dict[str, Any] = {"openapi": openapi_version, "info": info}
if servers:
output["servers"] = servers
==================================== ERRORS ====================================
________________________ ERROR collecting tests/main.py ________________________
tests/main.py:4: in <module>
from fastapi import FastAPI, Path, Query
fastapi/__init__.py:7: in <module>
from .applications import FastAPI as FastAPI
fastapi/applications.py:16: in <module>
from fastapi import routing
fastapi/routing.py:25: in <module>
from fastapi import params
fastapi/params.py:5: in <module>
from fastapi.openapi.models import Example
fastapi/openapi/models.py:80: in <module>
class Info(BaseModelWithConfig):
fastapi/openapi/models.py:87: in Info
externalDocs: Optional[ExternalDocumentation] = None
^^^^^^^^^^^^^^^^^^^^^
E NameError: name 'ExternalDocumentation' is not defined
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!!
1 error in 0.34s