From c487e7eee507f18ccaa667f9adb982fa796d7289 Mon Sep 17 00:00:00 2001 From: Lasisi Ibrahim <113442282+ibrahimpelumi6142@users.noreply.github.com> Date: Tue, 9 Dec 2025 23:25:38 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20validation=20error=20examp?= =?UTF-8?q?le=20for=20Enum=20path=20parameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/tutorial/path-params.md | 34 ++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/docs/en/docs/tutorial/path-params.md b/docs/en/docs/tutorial/path-params.md index 457cc2713..c9e2c3973 100644 --- a/docs/en/docs/tutorial/path-params.md +++ b/docs/en/docs/tutorial/path-params.md @@ -166,6 +166,40 @@ Because the available values for the *path parameter* are predefined, the intera +### Common Validation Errors with Enums { #enum-validation-errors } + +When using an `Enum` for a path parameter, FastAPI will validate the value automatically. + +For example, if your `ModelName` enum only allows: + +- `"alexnet"` +- `"resnet"` +- `"lenet"` + +And the client sends an invalid value: + +``` +GET /models/vgg16 +``` + +FastAPI returns a clear validation error: + +``` +{ + "detail": [ + { + "type": "enum", + "loc": ["path", "model_name"], + "msg": "Input should be 'alexnet', 'resnet' or 'lenet'", + "input": "vgg16" + } + ] +} + +``` + +This helps catch invalid requests before they reach your logic and keeps your API behavior predictable. + ### Working with Python *enumerations* { #working-with-python-enumerations } The value of the *path parameter* will be an *enumeration member*.