swagger-ui

How to disable application/json in Swagger UI autodocs of a FastAPI application?

How to disable application/json in Swagger UI autodocs of a FastAPI application? Question: My API can return only a file: @router.get( "/partners/{partner_id}/rsr-requests/{rsr_request_id}/{document_path}", responses={200: {"content": {"application/octet-stream": {}}, "description": "Файл"}} ) async def download_rsr_document(…): pass But in Swagger UI, I can see that application/json still remains. How to disable it? Asked By: Альберт Александров || Source Answers: …

Total answers: 2

Set the media type of a custom Error Response via a pydantic model in FastAPI

Set the media type of a custom Error Response via a pydantic model in FastAPI Question: In my FastAPI application I want to return my errors as RFC Problem JSON: from pydantic import BaseModel class RFCProblemJSON(BaseModel): type: str title: str detail: str | None status: int | None I can set the response model in …

Total answers: 1

TypeError: Object of type 'type' is not JSON serializable

TypeError: Object of type 'type' is not JSON serializable Question: The code works fine in Postman and provides a valid response but fails to generate the OpenAPI/Swagger UI automatic docs. class Role(str, Enum): Internal = "internal" External = "external" class Info(BaseModel): id: int role: Role class AppInfo(Info): info: str @app.post("/api/v1/create", status_code=status.HTTP_200_OK) async def create(info: Info, …

Total answers: 2

Enable "Try it out" in OpenAPI so that no need to click

Enable "Try it out" in OpenAPI so that no need to click Question: I’m using FastAPI and OpenAPI/Swagger UI to see and test my endpoints. Each time I use an endpoint for the first time, in order to test it, I have to first click the Try it out button, which is getting tedious. Is …

Total answers: 1

Add a custom javascript to the FastAPI Swagger UI docs webpage in Python

Add a custom javascript to the FastAPI Swagger UI docs webpage in Python Question: I want to load my custom javascript file or code to the FastAPI Swagger UI webpage, to add some dynamic interaction when I create a FastAPI object. For example, in Swagger UI on docs webpage I would like to <script src="custom_script.js"></script> …

Total answers: 2

How to add drop down menu to Swagger UI autodocs based on BaseModel using FastAPI?

How to add drop down menu to Swagger UI autodocs based on BaseModel using FastAPI? Question: I have this following class: class Quiz(BaseModel): question: str subject: str choice: str = Query(choices=(‘eu’, ‘us’, ‘cn’, ‘ru’)) I can render the form bases on this class like this @api.post("/postdata") def post_data(form_data: Quiz = Depends()): return form_data How can …

Total answers: 1

How to authorize OpenAPI/Swagger UI page in FastAPI?

How to authorize OpenAPI/Swagger UI page in FastAPI? Question: I’m building a FastAPI application with OAuth2 and JWT authentication. I’ve got two endpoints that create the JWT token. The first is hidden from the OpenAPI page but is used by the page Authorize button. The second does the same functionality but is available to the …

Total answers: 1

How to add image to Swagger UI autodocs using FastAPI?

How to add image to Swagger UI autodocs using FastAPI? Question: I would like to add an image to the FastAPI automatic documentation (provided by Swagger UI), but I can’t figure out how to do this. This is the code: @api.get(path=’/carbon-credit/’, responses={ 200: {‘description’: ‘Ok’, "content": { "image/jpeg": { "example": ‘https://picsum.photos/seed/picsum/200/300’ } }}, 404: {"description": …

Total answers: 1

FastAPI: " ImportError: attempted relative import with no known parent package"

FastAPI: " ImportError: attempted relative import with no known parent package" Question: I am new to FastAPI and I’ve been having this problem with importing my other files. I get the error:‍‍‍‍ from . import schemas ImportError: attempted relative import with no known parent package For context, the file I am importing from is a …

Total answers: 2

FastAPI swagger don't use custom header

FastAPI swagger don't use custom header Question: I want to add "Authorization" header to the my FastAPI application. I did it by documentation, but when i try to execute request in the swagger – it doesn’t work(swagger don’t use custom header), i have "Missing Authorization Header" error Error in the swagger Asked By: Ilia || …

Total answers: 1