|
| 1 | +from ellar.common import Controller, get, serialize_object |
| 2 | +from ellar.openapi import OpenAPIDocumentBuilder |
| 3 | +from ellar.testing import Test |
| 4 | + |
| 5 | + |
| 6 | +@Controller |
| 7 | +class Cat1Controller: |
| 8 | + @get("/create") |
| 9 | + async def create_cat(self): |
| 10 | + return {"message": "created"} |
| 11 | + |
| 12 | + |
| 13 | +@Controller |
| 14 | +class Cat2Controller: |
| 15 | + @get("/create") |
| 16 | + async def create_cat(self): |
| 17 | + return {"message": "created"} |
| 18 | + |
| 19 | + |
| 20 | +Cat2Controller.add_router(Cat1Controller) |
| 21 | + |
| 22 | + |
| 23 | +tm = Test.create_test_module(controllers=[Cat2Controller]) |
| 24 | + |
| 25 | + |
| 26 | +def test_nested_route_openapi_schema(): |
| 27 | + app = tm.create_application() |
| 28 | + document = serialize_object(OpenAPIDocumentBuilder().build_document(app)) |
| 29 | + assert document == NESTED_SCHEMA |
| 30 | + |
| 31 | + |
| 32 | +NESTED_SCHEMA = { |
| 33 | + "openapi": "3.1.0", |
| 34 | + "info": {"title": "Ellar API Docs", "version": "1.0.0"}, |
| 35 | + "paths": { |
| 36 | + "/cat2/cat1/create": { |
| 37 | + "get": { |
| 38 | + "tags": ["cat1"], |
| 39 | + "operationId": "create_cat_create_get__cat1", |
| 40 | + "responses": { |
| 41 | + "200": { |
| 42 | + "description": "Successful Response", |
| 43 | + "content": { |
| 44 | + "application/json": { |
| 45 | + "schema": {"type": "object", "title": "Response Model"} |
| 46 | + } |
| 47 | + }, |
| 48 | + } |
| 49 | + }, |
| 50 | + } |
| 51 | + }, |
| 52 | + "/cat2/create": { |
| 53 | + "get": { |
| 54 | + "tags": ["cat2"], |
| 55 | + "operationId": "create_cat_create_get__cat2", |
| 56 | + "responses": { |
| 57 | + "200": { |
| 58 | + "description": "Successful Response", |
| 59 | + "content": { |
| 60 | + "application/json": { |
| 61 | + "schema": {"type": "object", "title": "Response Model"} |
| 62 | + } |
| 63 | + }, |
| 64 | + } |
| 65 | + }, |
| 66 | + } |
| 67 | + }, |
| 68 | + }, |
| 69 | + "components": { |
| 70 | + "schemas": { |
| 71 | + "HTTPValidationError": { |
| 72 | + "properties": { |
| 73 | + "detail": { |
| 74 | + "items": {"$ref": "#/components/schemas/ValidationError"}, |
| 75 | + "type": "array", |
| 76 | + "title": "Details", |
| 77 | + } |
| 78 | + }, |
| 79 | + "type": "object", |
| 80 | + "required": ["detail"], |
| 81 | + "title": "HTTPValidationError", |
| 82 | + }, |
| 83 | + "ValidationError": { |
| 84 | + "properties": { |
| 85 | + "loc": { |
| 86 | + "items": {"type": "string"}, |
| 87 | + "type": "array", |
| 88 | + "title": "Location", |
| 89 | + }, |
| 90 | + "msg": {"type": "string", "title": "Message"}, |
| 91 | + "type": {"type": "string", "title": "Error Type"}, |
| 92 | + }, |
| 93 | + "type": "object", |
| 94 | + "required": ["loc", "msg", "type"], |
| 95 | + "title": "ValidationError", |
| 96 | + }, |
| 97 | + } |
| 98 | + }, |
| 99 | + "tags": [{"name": "cat1"}, {"name": "cat2"}], |
| 100 | +} |
0 commit comments