swagger

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

Allow user to enter un-encoded URL at FastAPI/Swagger page, preferably via GET

How to pass unencoded URL in FastAPI/Swagger UI via GET method? Question: I would like to write a FastAPI endpoint, with a Swagger page (or something similar) that will accept a non-encoded URL as input. It should preferably use GET, not POST method. Here’s an example of a GET endpoint that does require double-URL encoding. …

Total answers: 1

DRF Swagger – Endpoint parameter doesn't match the Serializer

DRF Swagger – Endpoint parameter doesn't match the Serializer Question: So I’m trying to create at REST API using DRF and Swagger for API Documentation, But I notice that Swagger UI Parameter doesn’t match the given Serializer. MailSerializer.py ` from main.BusinessLayer.Model.Mails import Mails from rest_framework import serializers class MailSerializer(serializers.Serializer): class Meta: model = Mails fields …

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 send a POST request to Swagger API on a localhost with Python?

How to send a POST request to a REST API on a localhost with Python? Question: I’m trying to send a post request to a SREST API, which is currently on the localhost and keep getting various errors. The error I’m getting at the moment is: requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0) …

Total answers: 1

Pulling Swagger API with python

Pulling Swagger API with python Question: Can someone explain how I can pull this API info with python or point me in the right direction? On the swagger documentation page for the API I am trying to access, I go to the header authentication section; paste in the API key, and am returned with a …

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