swagger-api / swagger-api/swagger-ui
having problems with dict used in get requests
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 29k
- Forks
- 9.3k
- Avg merge
- 2d 23h
- Merged PRs (30d)
- 25
Description
Q&A (please complete the following information)
- OS: Windows 11
- Browser: Chrome
- Version: 134.0.6998.179
- Method of installation: pip with fastapi
- Swagger-UI version: 3.10.0
- Swagger/OpenAPI version: OAS 3.1
Describe the bug you're encountering
having problems with dicts used in get requests
To reproduce...
Steps to reproduce the behavior:
write pydantic + fastapi code
import json
from typing import Optional, List
from fastapi import FastAPI, APIRouter, Query, Request, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel, Field
from pydantic import ConfigDict, field_validator
app = FastAPI()
class AdBase(BaseModel):
id: str
title: str
owner: Optional[str] = None
doc_id: Optional[List[str]] = None
class AdGetRequest(AdBase):
page: int = Field(0, gt=-1)
filters: Optional[dict] = Field(
default=None,
example={"location": ["Ankara", "İstanbul"], "position_title": "Yazılım"}
)
owner: Optional[str] = Field(None)
doc_id: Optional[List[str]] = Field(None)
model_config = ConfigDict(extra="ignore")
@field_validator("filters", mode="before")
def parse_filters(cls, value):
if value is None:
return value
if isinstance(value, str):
try:
return json.loads(value)
except json.JSONDecodeError:
raise ValueError("filters must be a valid JSON string representing a dictionary")
return value
@app.get("/management")
async def get_ads(request: Request, ad: AdGetRequest = Query(...)):
print(f"Received Filters: {ad.filters}")
return JSONResponse(content={"message": "Filters received","filters": ad.filters})
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
Expected behavior
url should be:
localhost:8002/DB/ad/management?page=0&filters={"location": ["Ankara", "İstanbul"], "position_title": "Yazılım"}
not:
localhost:8002/DB/ad/management?page=0&location=["Ankara","İstanbul"]&position_title=Yazılım
filters missing.
Screenshots
The request is wrong, it's not usable.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided FastAPI and Pydantic example in Chrome with Swagger UI 3.10.0, then compare the generated GET query with the expected filters parameter. Done would require a confirmed Swagger UI reproduction using a minimal OpenAPI document and a specific affected entry point or test; the report identifies neither.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, frontend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 15/100