Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Strange unstable behavior #13720

Answered by sachinh35
shurshilov asked this question in Questions
May 15, 2025 · 1 comments · 1 reply
Discussion options

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

#I have 2 similar routes
#1
@router.get("/api/users/", response_model=list[UserListResponse])
async def get_users(req: Request, include_me: IntBool = IntBool.FALSE):
    """
    Get user list
    """
    ...
#2
@router.get("/api/client_list/", response_model=list[BypassesResponse])
async def get_client_list(req: Request):
    """
    Returns clients list
    """
#custom annotation
MAX_UINT_32: Final[int] = 2**32 - 1
Id = Annotated[int, Field(..., ge=1, le=MAX_UINT_32)]

#two model
#1
class UserListResponse(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    id: Id = Field(description="id user")
#2
class BypassesResponse(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )

    id: Id = Field(..., description="id client")

Description

I have 2 similar routes
1

@router.get("/api/users/", response_model=list[UserListResponse])
async def get_users(req: Request, include_me: IntBool = IntBool.FALSE):
    """
    Get user list
    """
    ...

2

@router.get("/api/client_list/", response_model=list[BypassesResponse])
async def get_client_list(req: Request):
    """
    Returns clients list
    """
I have custom type id that imported

MAX_UINT_32: Final[int] = 2**32 - 1
Id = Annotated[int, Field(..., ge=1, le=MAX_UINT_32)]

And 2 response models
1

class UserListResponse(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    id: Id = Field(description="id user")

2

class BypassesResponse(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )

    id: Id = Field(..., description="id client")

But in Swagger first ID required and Second ID not required
image
image

Operating System

Windows

Operating System Details

No response

FastAPI Version

115.8

Pydantic Version

2.10.6

Python Version

3.11

Additional Context

No response

You must be logged in to vote

Hello, I wasn't able to fully replicate the issue on my end. I don't have a windows machine though. Here's what I used.

Details about python packages

(venv) ➜  FastApi-13720 pip3 freeze
annotated-types==0.7.0
anyio==4.9.0
click==8.2.0
fastapi==0.115.8
h11==0.16.0
idna==3.10
pydantic==2.10.6
pydantic_core==2.27.2
sniffio==1.3.1
starlette==0.45.3
typing-inspection==0.4.0
typing_extensions==4.13.2
uvicorn==0.34.2
(venv) ➜  FastApi-13720

Details about fastapi app

from typing import Final, Annotated, List

from fastapi import FastAPI, APIRouter, Request
from pydantic import BaseModel, Field, ConfigDict
from enum import IntEnum

# Custom annotation
MAX_UINT_32: Final[int] = 2 ** 32 - 1
Id = An…

Replies: 1 comment · 1 reply

Comment options

Hello, I wasn't able to fully replicate the issue on my end. I don't have a windows machine though. Here's what I used.

Details about python packages

(venv) ➜  FastApi-13720 pip3 freeze
annotated-types==0.7.0
anyio==4.9.0
click==8.2.0
fastapi==0.115.8
h11==0.16.0
idna==3.10
pydantic==2.10.6
pydantic_core==2.27.2
sniffio==1.3.1
starlette==0.45.3
typing-inspection==0.4.0
typing_extensions==4.13.2
uvicorn==0.34.2
(venv) ➜  FastApi-13720

Details about fastapi app

from typing import Final, Annotated, List

from fastapi import FastAPI, APIRouter, Request
from pydantic import BaseModel, Field, ConfigDict
from enum import IntEnum

# Custom annotation
MAX_UINT_32: Final[int] = 2 ** 32 - 1
Id = Annotated[int, Field(..., ge=1, le=MAX_UINT_32)]


# Custom Enum
class IntBool(IntEnum):
    FALSE = 0
    TRUE = 1


# Two Pydantic models
class UserListResponse(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    id: Id = Field(description="id user")


class BypassesResponse(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    id: Id = Field(..., description="id client")


# APIRouter instance
router = APIRouter()


@router.get("/api/users/", response_model=List[UserListResponse])
async def get_users(req: Request, include_me: IntBool = IntBool.FALSE):
    """
    Get user list
    """
    # In a real application, you would fetch users from a database or other source.
    # For this example, we'll return a static list.
    users = [
        {"id": 1},
        {"id": 2},
        {"id": 3},
    ]
    return users


@router.get("/api/client_list/", response_model=List[BypassesResponse])
async def get_client_list(req: Request):
    """
    Returns clients list
    """
    # In a real application, you would fetch clients from a database or other source.
    # For this example, we'll return a static list.
    clients = [
        {"id": 101},
        {"id": 102},
    ]
    return clients


# FastAPI application instance
app = FastAPI()

# Include the router in the app
app.include_router(router)
  1. I saved the file with main.py and ran the code using uvicorn main:app --reload.
  2. After that, I opened swagger docs on http://127.0.0.1:8000/docs. It produced the correct swagger documentation. Screenshot below.
Screenshot 2025-05-15 at 7 10 58 PM

Can you please share how you are running your app and how are you accessing the swagger docs URL? If you share your entire code then that'd be of huge help too.

You must be logged in to vote
1 reply
@shurshilov
Comment options

Hi, thank you, I tested all day and in pydantyc 2.9.2 it work after not for example 2.10.6
Now will check your version too

Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.