Skip to content

Instantly share code, notes, and snippets.

View linknum23's full-sized avatar

Lincoln Lorenz linknum23

  • MicroNova
  • United States
View GitHub Profile
@linknum23
linknum23 / app.py
Last active May 21, 2021 19:28 — forked from vigneshjs/app.py
Adding multiple request and response 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