Bug: "type" keyword doesn't behave the same as TypeAlias
atom-andrew opened this issue · 2 comments
atom-andrew commented
Description
The "type" keyword just generates an empty schema in openapi.
URL to code causing the issue
No response
MCVE
# Your MCVE code here
import json
from typing import TypeAlias, Literal
from litestar import Controller, Litestar, get
AliasArg: TypeAlias = Literal[456]
type TypeArg = Literal[123]
class Test(Controller):
@get(path="/test")
async def test(self, alias_arg: AliasArg, type_arg: TypeArg) -> None:
...
if __name__ == "__main__":
app = Litestar(
route_handlers=[Test],
)
print(json.dumps(app.openapi_schema.to_schema(), indent=4))
Output looks like:
{
"info": {
"title": "Litestar API",
"version": "1.0.0"
},
"openapi": "3.1.0",
"servers": [
{
"url": "/"
}
],
"paths": {
"/test": {
"get": {
"summary": "Test",
"operationId": "TestTest",
"parameters": [
{
"name": "alias_arg",
"in": "query",
"schema": {
"type": "integer",
"const": 456
},
"required": true,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
},
{
"name": "type_arg",
"in": "query",
"schema": {},
"required": true,
"deprecated": false,
"allowEmptyValue": false,
"allowReserved": false
}
],
"responses": {
"200": {
"description": "Request fulfilled, document follows",
"headers": {}
},
"400": {
"description": "Bad request syntax or unsupported method",
"content": {
"application/json": {
"schema": {
"properties": {
"status_code": {
"type": "integer"
},
"detail": {
"type": "string"
},
"extra": {
"additionalProperties": {},
"type": [
"null",
"object",
"array"
]
}
},
"type": "object",
"required": [
"detail",
"status_code"
],
"description": "Validation Exception",
"examples": [
{
"status_code": 400,
"detail": "Bad Request",
"extra": {}
}
]
}
}
}
}
},
"deprecated": false
}
}
},
"components": {
"schemas": {}
}
}
Steps to reproduce
1. Run example code
2. Inspect openapi output
Screenshots
"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"
Logs
No response
Litestar Version
2.10.0
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Note
While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.
Check out all issues funded or available for funding on our Polar.sh dashboard
- If you would like to see an issue prioritized, make a pledge towards it!
- We receive the pledge once the issue is completed & verified
- This, along with engagement in the community, helps us know which features are a priority to our users.
github-actions commented
This issue has been closed in #3715. The change will be included in the upcoming patch release.
github-actions commented
A fix for this issue has been released in v2.12.0