I'm reading the tutorial on Path Parameter Validation.
I want to allow the strings "a" "b" and "c" as possible parameter values. I want these values to show up in the OpenAPI documentation (i.e., FastAPI's automatic docs), so that the API user does not have to guess them. How can I make these values show up in the documentation?
Here is my implementation:
from fastapi import FastAPI, HTTPException
app = FastAPI()
parameters = ["a", "b", "c"]
@app.get("/endpoint/{parameter}")
def endpoint(parameter: str):
if parameter not in parameters:
raise HTTPException(status_code=400, detail="parameter must be a, b, or c")
return {"parameter": parameter}