]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:memo: Update enum examples to use str, and improve Swagger UI in examples (#351)
authorSebastián Ramírez <tiangolo@gmail.com>
Fri, 28 Jun 2019 19:27:27 +0000 (21:27 +0200)
committerGitHub <noreply@github.com>
Fri, 28 Jun 2019 19:27:27 +0000 (21:27 +0200)
docs/src/path_params/tutorial005.py
docs/tutorial/path-params.md
tests/test_tutorial/test_path_params/test_tutorial005.py

index d4f24bce70dede9f918aca6389f80d522ace6ec5..e58b22c618e4c8ea89f79cd26f4ade7130ad82a0 100644 (file)
@@ -3,7 +3,7 @@ from enum import Enum
 from fastapi import FastAPI
 
 
-class ModelName(Enum):
+class ModelName(str, Enum):
     alexnet = "alexnet"
     resnet = "resnet"
     lenet = "lenet"
index 96e29366e1455c4e74f4f525ce53771687ec8747..d0c592d687e43ccda855b9a96eb88e004ece75f3 100644 (file)
@@ -119,7 +119,9 @@ If you have a *path operation* that receives a *path parameter*, but you want th
 
 ### Create an `Enum` class
 
-Import `Enum` and create a sub-class that inherits from it.
+Import `Enum` and create a sub-class that inherits from `str` and from `Enum`.
+
+By inheriting from `str` the API docs will be able to know that the values must be of type `string` and will be able to render correctly.
 
 And create class attributes with fixed values, those fixed values will be the available valid values:
 
index 3245cdcebe2f66d98f2e5b500f4a94a255d06831..89f5863c557c5e4c2696478b3e17fe667fe0771c 100644 (file)
@@ -35,6 +35,7 @@ openapi_schema = {
                         "schema": {
                             "title": "Model_Name",
                             "enum": ["alexnet", "resnet", "lenet"],
+                            "type": "string",
                         },
                         "name": "model_name",
                         "in": "path",