# Buggy code
def get_flat_models_from_routes(
    routes: Sequence[Type[BaseRoute]],
) -> Set[Type[BaseModel]]:
    body_fields_from_routes: List[Field] = []
    responses_from_routes: List[Field] = []
    for route in routes:
        if getattr(route, "include_in_schema", None) and isinstance(
            route, routing.APIRoute
        ):
            if route.body_field:
                assert isinstance(route.body_field, Field), (
                    "A request body must be a Pydantic Field"
                )
                body_fields_from_routes.append(route.body_field)
            if route.response_field:
                responses_from_routes.append(route.response_field)
            if route.response_fields:
                responses_from_routes.extend(route.response_fields.values())
    flat_models = get_flat_models_from_fields(
        body_fields_from_routes + responses_from_routes
    )
    return flat_models


# Traceback (TypeError)
INFO: ('127.0.0.1', 55246) - "GET /openapi.json HTTP/1.1" 500
ERROR: Exception in ASGI application
Traceback (most recent call last):
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 369, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\applications.py", line 133, in __call__
await self.error_middleware(scope, receive, send)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\middleware\errors.py", line 122, in __call__
raise exc from None
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\middleware\errors.py", line 100, in __call__
await self.app(scope, receive, _send)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\exceptions.py", line 73, in __call__
raise exc from None
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\exceptions.py", line 62, in __call__
await self.app(scope, receive, sender)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\routing.py", line 585, in __call__
await route(scope, receive, send)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\routing.py", line 207, in __call__
await self.app(scope, receive, send)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\starlette\routing.py", line 40, in app
response = await func(request)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\fastapi\applications.py", line 87, in openapi
return JSONResponse(self.openapi())
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\fastapi\applications.py", line 79, in openapi
openapi_prefix=self.openapi_prefix,
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\fastapi\openapi\utils.py", line 241, in get_openapi
flat_models = get_flat_models_from_routes(routes)
File "c:\users\user\.virtualenvs\server-xl-s7lqx\lib\site-packages\fastapi\utils.py", line 31, in get_flat_models_from_routes
body_fields_from_routes + responses_from_routes
TypeError: get_flat_models_from_fields() missing 1 required positional argument: 'known_models'

# Fixed code
def get_flat_models_from_routes(
    routes: Sequence[Type[BaseRoute]],
) -> Set[Type[BaseModel]]:
    body_fields_from_routes: List[Field] = []
    responses_from_routes: List[Field] = []
    for route in routes:
        if getattr(route, "include_in_schema", None) and isinstance(
            route, routing.APIRoute
        ):
            if route.body_field:
                assert isinstance(route.body_field, Field), (
                    "A request body must be a Pydantic Field"
                )
                body_fields_from_routes.append(route.body_field)
            if route.response_field:
                responses_from_routes.append(route.response_field)
            if route.response_fields:
                responses_from_routes.extend(route.response_fields.values())
    flat_models = get_flat_models_from_fields(
        body_fields_from_routes + responses_from_routes, known_models=set()
    )
    return flat_models