Skip to content

Component name regression in OpenAPI spec for v0.119.0 #14247

@tiangolo

Description

@tiangolo

Adding the issue here for completeness, although most of the conversation is in the GitHub Discussion.

Discussed in #14177

Originally posted by walsha2 October 12, 2025

First Check

  • I added a very descriptive title here.
  • I used the GitHub search to find a similar question and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from enum import StrEnum

from fastapi import FastAPI
from pydantic import BaseModel, Field


class MessageEventType(StrEnum):
    alpha = "alpha"
    beta = "beta"


class MessageEvent(BaseModel):
    event_type: MessageEventType = Field(default=MessageEventType.alpha)
    output: str


class MessageOutput(BaseModel):
    body: str = ""
    events: list[MessageEvent]


class Message(BaseModel):
    id: str
    input: str
    output: MessageOutput


app = FastAPI(title="Minimal FastAPI App", version="1.0.0")


@app.post("/messages", response_model=Message)
async def create_message(input_message: str) -> Message:
    return Message(
        input=input_message,
        output=MessageOutput(body=f"Processed: {input_message}"),
    )


if __name__ == "__main__":
    openapi_spec = app.openapi()
    for c in list(openapi_spec.get("components", {}).get("schemas", {}).keys()):
        print(c)

Description

Issue Summary

Take the minimal example provided above, run with fastapi==0.118.3 and it will produce:

HTTPValidationError
Message
MessageEvent
MessageEventType
MessageOutput
ValidationError

Now run the same code with fastapi==0.119.0 and it will produce:

HTTPValidationError
Message
MessageEvent
MessageEventType
MessageOutput-Input
MessageOutput-Output
ValidationError

Note how MessageOutput is now suffixed unnecessarily as: MessageOutput-Input and MessageOutput-Output. This seems unexpected considering the changes made between v0.118.3 and v0.119.0

Minor Tweak

One minor tweak to the example and this issue goes away. Remove the enum from MessageEvent:

class MessageEvent(BaseModel):
    output: str

Run again and the issue is no longer there.

HTTPValidationError
Message
MessageEvent
MessageOutput
ValidationError

TLDR

Why does the presence of an enum value on MessageEvent create a bifurcated OpenAPI schema definition for MessageOutput and why does this issue only start happening in fastapi==0.119.0?

Operating System

macOS

Operating System Details

15.6.1 (24G90)

FastAPI Version

0.119.0

Pydantic Version

2.12.0

Python Version

Python 3.13.1

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions