Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: "type" keyword doesn't behave the same as TypeAlias #3714

Closed
1 of 4 tasks
atom-andrew opened this issue Aug 31, 2024 · 2 comments · Fixed by #3715
Closed
1 of 4 tasks

Bug: "type" keyword doesn't behave the same as TypeAlias #3714

atom-andrew opened this issue Aug 31, 2024 · 2 comments · Fixed by #3715
Labels
Bug 🐛 This is something that is not working as expected

Comments

@atom-andrew
Copy link

atom-andrew commented Aug 31, 2024

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.
Fund with Polar
@atom-andrew atom-andrew added the Bug 🐛 This is something that is not working as expected label Aug 31, 2024
Copy link

github-actions bot commented Sep 3, 2024

This issue has been closed in #3715. The change will be included in the upcoming patch release.

Copy link

github-actions bot commented Jan 8, 2025

A fix for this issue has been released in v2.14.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 This is something that is not working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant