-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Description
When using StrEnum types in query parameter structs, the generated routes.ts file references type names with Python module path prefixes (e.g., app_domain_insight_schemas__base_Granularity), but these types are not defined anywhere. The actual types in types.gen.ts (generated by hey-api) use simple names from the OpenAPI schema (e.g., Granularity).
This causes TypeScript compilation errors:
src/lib/generated/routes.ts:361:15 - error TS2304: Cannot find name 'app_domain_insight_schemas__base_GroupByField'.
src/lib/generated/routes.ts:409:19 - error TS2304: Cannot find name 'app_domain_insight_schemas__base_Granularity'.
src/lib/generated/routes.ts:467:15 - error TS2304: Cannot find name 'app_domain_insight_schemas__base_SortField'.
src/lib/generated/routes.ts:468:18 - error TS2304: Cannot find name 'app_domain_insight_schemas__base_SortOrder'.
Reproduction Steps
- ·Define enum types using Python
StrEnum:
# app/domain/insight/schemas/_base.py
from enum import StrEnum
class Granularity(StrEnum):
HOUR = "hour"
DAY = "day"
MONTH = "month"
class GroupByField(StrEnum):
CLIENT_ID = "client_id"
USER_ID = "user_id"- Use these enums in a query parameter struct:
# app/domain/insight/schemas/_query.py
from app.domain.insight.schemas._base import Granularity, GroupByField
from app.lib.schema import CamelizedBaseStruct
class TrendQueryParams(CamelizedBaseStruct):
granularity: Granularity = Granularity.DAY
class GroupQueryParams(CamelizedBaseStruct):
group_by: GroupByField- Run
litestar assets generate-types - Check the generated
routes.json- it contains module-prefixed type names:
{
"granularity": "app_domain_insight_schemas__base_Granularity | undefined",
"group_by": "app_domain_insight_schemas__base_GroupByField"
}- The generated
routes.tsuses these undefined types, causing TS compilation errors.
Expected Behavior
The generated routes.ts should either:
- Use simple type names that match the OpenAPI schema (
Granularity,GroupByField), OR - Define/import the types with the prefixed names, OR
- Inline the enum values directly (e.g.,
"hour" | "day" | "month")
Actual Behavior
openapi.jsoncorrectly defines enums with simple names (Granularity,GroupByField)types.gen.ts(hey-api) generates types with simple namesroutes.jsonandroutes.tsuse Python module path prefixed names that don't exist
Environment
- Python: 3.13.7
- Litestar: 2.19.0
- litestar-vite: 0.18.1
- OS: macOS
Workaround
Manually add type aliases to routes.ts after generation:
// Add after existing type aliases
type app_domain_insight_schemas__base_Granularity = "hour" | "day" | "month";
type app_domain_insight_schemas__base_GroupByField = "client_id" | "user_id";
type app_domain_insight_schemas__base_SortField =
| "request_timestamp"
| "total_tokens"
| "prompt_tokens"
| "completion_tokens"
| "created_at";
type app_domain_insight_schemas__base_SortOrder = "asc" | "desc";Suggested Fix
The issue appears to originate in the route metadata export logic. When serializing type information for query parameters, the code uses Python's fully qualified type name instead of the OpenAPI schema reference name.
Potential fixes:
- Map Python enum types to their OpenAPI schema names when generating
routes.json - Generate type aliases in
routes.tsfor any module-prefixed enum types - Inline enum literal types directly in the route type definitions
URL to code causing the issue
No response
MCVE
# Your MCVE code hereSteps to reproduce
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See errorScreenshots
"In the format of: "
Logs
Package Version
0.18.1
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)