]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
✅ Add test to support Enums with their own re-usable schema (#1461)
authorSebastián Ramírez <tiangolo@gmail.com>
Sat, 23 May 2020 14:04:25 +0000 (16:04 +0200)
committerGitHub <noreply@github.com>
Sat, 23 May 2020 14:04:25 +0000 (16:04 +0200)
tests/test_tutorial/test_path_params/test_tutorial005.py

index bdf0a9e5977eecebc75613c98d2adadfb86d6057..b0e0535e8a627099de5f396fd180570350756168 100644 (file)
@@ -76,10 +76,78 @@ openapi_schema = {
 }
 
 
+openapi_schema2 = {
+    "openapi": "3.0.2",
+    "info": {"title": "FastAPI", "version": "0.1.0"},
+    "paths": {
+        "/model/{model_name}": {
+            "get": {
+                "summary": "Get Model",
+                "operationId": "get_model_model__model_name__get",
+                "parameters": [
+                    {
+                        "required": True,
+                        "schema": {"$ref": "#/definitions/ModelName"},
+                        "name": "model_name",
+                        "in": "path",
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "Successful Response",
+                        "content": {"application/json": {"schema": {}}},
+                    },
+                    "422": {
+                        "description": "Validation Error",
+                        "content": {
+                            "application/json": {
+                                "schema": {
+                                    "$ref": "#/components/schemas/HTTPValidationError"
+                                }
+                            }
+                        },
+                    },
+                },
+            }
+        }
+    },
+    "components": {
+        "schemas": {
+            "HTTPValidationError": {
+                "title": "HTTPValidationError",
+                "type": "object",
+                "properties": {
+                    "detail": {
+                        "title": "Detail",
+                        "type": "array",
+                        "items": {"$ref": "#/components/schemas/ValidationError"},
+                    }
+                },
+            },
+            "ValidationError": {
+                "title": "ValidationError",
+                "required": ["loc", "msg", "type"],
+                "type": "object",
+                "properties": {
+                    "loc": {
+                        "title": "Location",
+                        "type": "array",
+                        "items": {"type": "string"},
+                    },
+                    "msg": {"title": "Message", "type": "string"},
+                    "type": {"title": "Error Type", "type": "string"},
+                },
+            },
+        }
+    },
+}
+
+
 def test_openapi():
     response = client.get("/openapi.json")
     assert response.status_code == 200, response.text
-    assert response.json() == openapi_schema
+    data = response.json()
+    assert data == openapi_schema or data == openapi_schema2
 
 
 @pytest.mark.parametrize(