Skip to content

Instantly share code, notes, and snippets.

View eylwithjv's full-sized avatar

Vignesh Jeevanandam eylwithjv

View GitHub Profile
@eylwithjv
eylwithjv / app.py
Last active October 8, 2024 04:37
Adding multiple request body examples to swagger docs in fastAPI
"""
FastAPI uses pydantic models to validate the API request body and also generate the swagger documentation. Since the schema
generated by pydantic only comply to JSON schema specification and not to openAPI specification, swagger documentation
generated from pydantic models do not support adding multiple examples for a request body.
Ref: https://fastapi.tiangolo.com/tutorial/schema-extra-example/#technical-details
In the following code, I have extended fastAPI openAPI schema to include multiple request body examples.
"""
import json