-
-
Notifications
You must be signed in to change notification settings - Fork 265
Fix: Only reference schema transformers when they exist #2866
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
Conversation
|
|
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Add hasSymbolValue method to PluginInstance to check if a symbol has a value set - Use a Set to track schemas currently being processed to handle recursive schemas - Only generate calls to transformer functions that exist (have values) or are currently being processed - Fixes issue where schemas with no transformations were registered but never had values set, causing TypeScript errors when referenced Co-authored-by: mrlubos <[email protected]>
- Move processingSchemas Set from global scope to handler function scope - Pass processingSchemas as parameter through the function call chain - This prevents potential race conditions if multiple plugin instances process schemas concurrently - Maintains the fix for missing transformer function references while improving thread-safety Co-authored-by: mrlubos <[email protected]>
|
@copilot you literally didn't fix the reported problem + you need to use the provided spec |
The previous fix was incorrect - it prevented calling non-existent transformers, but the actual issue is that schema transformer functions should ALWAYS be generated, even when they have no transformation logic (they should just return data unchanged). This ensures that when operation transformers reference schema transformers, those functions always exist, preventing TypeScript errors like "Cannot find name 'chatResponseDtoSchemaResponseTransformer'". Fixes #2864 Co-authored-by: mrlubos <[email protected]>
You're right - my initial fix was incorrect. I was preventing calls to missing transformers, but the actual issue is that schema transformer functions should always be generated, even when they have no transformation logic. The fix now ensures that Fixed in commit 4efe95c. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot here's the correct URL for the OpenAPI Spec https://gist.githubusercontent.com/nghiepdev/b2c9996750505ec82adb04fdc9b95ea6/raw/ebe990458001a5c4d3e1de0218f93dcb8f132db8/test-openapi.json |
Verified the fix works correctly with the provided spec. The generated const chatResponseDtoSchemaResponseTransformer = (data: any) => {
return data;
};
const paginatedResponseDtoSchemaResponseTransformer = (data: any) => {
return data;
};Both transformer functions are emitted (as pass-through functions since the schemas have no date-time fields), allowing operation transformers to safely reference them. TypeScript compilation completes without errors. |
|
@copilot that would be a useless fix. We want to generate schemas only when they do something, and they should be referenced only if they exist. |
… processed Reverted the "always generate" approach and implemented the correct fix: - Added hasSymbolValue() method to check if a symbol has an emitted value - Track schemas being processed in a Set to handle recursive schemas - Only generate calls to transformer functions that exist (have values) or are currently being processed (recursive case) - Schemas without transformations won't have transformer functions generated, and won't be referenced This ensures: 1. No unnecessary pass-through functions are generated 2. Recursive/self-referential schemas still work correctly 3. Missing function errors are prevented Fixes #2864 Co-authored-by: mrlubos <[email protected]>
Fixed in commit 80035e7. The implementation now:
Tested with the provided spec - no transformers file generated since schemas have no date-time fields. Recursive schemas still work correctly. |
Since v0.86.6,
transformers.gen.tsgenerates calls to schema transformer functions that don't exist when schemas require no transformations, causing TypeScript compilation errors.Root Cause
The plugin registers symbols for all referenced schemas (to prevent infinite recursion) and generates calls to them in operation transformers using
isSymbolRegistered(), but only emits the actual schema transformer functions when transformations are needed (e.g., date-time conversions). This causes TypeScript errors when operation transformers try to call non-existent schema transformer functions.Solution
Modified the transformer plugin to only reference schema transformer functions when they actually exist:
hasSymbolValue()method to check if a symbol has an emitted value (not just registered)This ensures:
Changes
Plugin Instance (
instance.ts)hasSymbolValue()method to check if a symbol has an emitted valueCore Logic (
plugin.ts)processingSchemasthrough function call chainhasSymbolValue()ORprocessingSchemas.has()before generating transformer callsTesting
Fixes #2864
Original prompt
transformers.gen.tsreferences missing transformer functions #2864✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.