diff --git a/fastapi/openapi/models.py b/fastapi/openapi/models.py index d5eee02d4..e2abca215 100644 --- a/fastapi/openapi/models.py +++ b/fastapi/openapi/models.py @@ -14,7 +14,6 @@ from pydantic import AnyUrl, BaseModel, Field, validator from typing_extensions import Annotated, Literal, TypedDict from typing_extensions import deprecated as typing_deprecated - try: import email_validator @@ -444,7 +443,8 @@ class OpenAPI(BaseModelWithConfig): def check_tags(cls, tags): # type: ignore unique_names = set() assert not any( - t.name in unique_names or unique_names.add(t.name) for t in tags # type: ignore + t.name in unique_names or unique_names.add(t.name) + for t in tags # type: ignore ), "Tag names must be unique" return tags diff --git a/fastapi/openapi/utils.py b/fastapi/openapi/utils.py index e51cafb56..5f533b8c2 100644 --- a/fastapi/openapi/utils.py +++ b/fastapi/openapi/utils.py @@ -568,5 +568,7 @@ def get_openapi( # discard tags with non-unique names as it is against the OpenAPI spec # https://swagger.io/specification/#openapi-object names = set() - output["tags"] = [t for t in tags if t["name"] not in names and not names.add(t["name"])] # type: ignore + output["tags"] = [ + t for t in tags if t["name"] not in names and not names.add(t["name"]) + ] # type: ignore return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True) # type: ignore