| 1 |
from ninja import Field, NinjaAPI, Schema |
| 2 |
|
| 3 |
|
| 4 |
class SchemaWithAlias(Schema): |
| 5 |
foo: str = Field("", alias="bar") |
| 6 |
|
| 7 |
|
| 8 |
api = NinjaAPI() |
| 9 |
|
| 10 |
|
| 11 |
@api.get("/path", response=SchemaWithAlias) |
| 12 |
def alias_operation(request): |
| 13 |
return {"bar": "value"} |
| 14 |
|
| 15 |
|
| 16 |
def test_alias(): |
| 17 |
schema = api.get_openapi_schema()["components"] |
| 18 |
print(schema) |
| 19 |
assert schema == { |
| 20 |
"schemas": { |
| 21 |
"SchemaWithAlias": { |
| 22 |
"type": "object", |
| 23 |
"properties": { |
| 24 |
"foo": {"type": "string", "default": "", "title": "Foo"} |
| 25 |
}, |
| 26 |
"title": "SchemaWithAlias", |
| 27 |
} |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|