-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
When multiple controllers reference the same schema (shared schemas), the generator incorrectly imports those DTOs from a single controller's DTO file instead of recognizing them as shared and organizing imports accordingly. This causes TypeScript compilation errors.
Expected Output:
// orders.controller.base.ts
import { OrderResponseDto, CreateOrderRequestDto } from './orders.dto';
import { ProductResponseDto, CategoryResponseDto } from '../shared/shared.dto';
Actual Output:
// orders.controller.base.ts
import { OrderResponseDto, CreateOrderRequestDto, ProductResponseDto, CategoryResponseDto } from './orders.dto';
// ❌ Error: ProductResponseDto and CategoryResponseDto are not defined in orders.dto.ts
This causes TypeScript compilation errors:
error TS2305: Module './orders.dto' has no exported member 'ProductResponseDto'.
error TS2305: Module './orders.dto' has no exported member 'CategoryResponseDto'.
Root Cause
The generator appears to:
- Process each OpenAPI spec/tag independently
- Collect all $ref schema references used by a controller
- Assume all referenced schemas will be in that controller's DTO file
- Generate a single import statement from the controller's DTO file
The generator does not:
- Track which schemas are referenced by multiple controllers
- Identify shared schemas that should be in a common location
- Generate separate DTO files for shared vs controller-specific schemas
- Resolve imports based on whether a schema is shared or controller-specific
Generating a Controller for shared schemas only
Another, issue I see that isn't a huge issue for us right now is that a controller automatically gets created for the shared spec when it only contains shared schemas. It would be nice to keep that from happening.
MrFiddle
Metadata
Metadata
Assignees
Labels
No labels