r/FastAPI • • Apr 24 '21

Question GET requests show Request Body in Swagger UI

  • Python: 3.6.8

  • FastAPI: 0.63.0

  • Pydantic: 1.8.1

  • Starlette: 0.13.6

I have gone through the documentation and built a multi-file app. All of my requests work fine via curl, requests, etc., but when I view them in the Swagger UI, all of the GETs have a Request Body included, which defaults to:

[
    "string"
]

In order to successfully send any requests via the Swagger UI, you need to first clear the Request Body text box before clicking Execute.

Is there a way to remove the Request Body from GET requests in the Swagger UI?

EDIT: This was caused by a bad type hint (see here).

1 Upvotes

2 comments sorted by

1

u/Akmantainman Apr 27 '21

Can you post your route code? I don't think this is expected behavior.

1

u/terminalmage Apr 27 '21

Thanks for your response. I went back and looked, and noticed that one of my modules was not exhibiting this behavior. It turns out that, in most of my modules, all of the functions had a queryarg defined with a bad type hint. Instead of Union[None, str] = None I had Union[None, list] = None. Once I corrected this, the request body went away.

So, this was just lazy copy/paste.