Conversation
This refactoring addresses the monolithic structure of the codebase by: ## Changes Made ### 1. Created shared utilities module - **src/utils/schema-utils.ts**: Extracted duplicated functions - `CONTENT_TYPE_MAP`: Content type priority mapping - `findContentType()`: Finds appropriate content type from options - `resolveParameter()`: Resolves parameter references - Eliminated code duplication between `zenko.ts` and `collect-referenced-schemas.ts` - Added comprehensive test coverage (17 tests) ### 2. Extracted schema generation logic - **src/core/schema-generator.ts**: Isolated all Zod schema building - `generateZodSchema()`: Generates complete Zod schema exports - `getZodTypeFromSchema()`: Converts OpenAPI to Zod types - `buildZodObject()`: Builds object schemas - `buildString()`, `buildNumber()`, `buildInteger()`: Primitive types - `applyStrictArrayBounds()`: Array constraints - `applyNumericBounds()`: Numeric bounds - `applyOptionalModifier()`: Optional/nullable/nullish modifiers - `isPrimitiveLike()`: Primitive type checking - Reduced main file from 1,537 to 1,212 lines (325 lines extracted) - Added comprehensive test coverage (63 tests) ## Impact - **Better separation of concerns**: Each module has a single responsibility - **Improved testability**: Individual functions can be tested in isolation - **Reduced code duplication**: Shared utilities prevent maintenance issues - **Maintained compatibility**: All 264 existing tests pass - **Enhanced composability**: Functions are now more reusable ## Future Refactoring Opportunities The following areas can be further improved: - Extract operation parsing logic (parseOperations, collectParameters, etc.) - Separate response type resolution (getResponseTypes, selectSuccessResponse) - Isolate error handling logic (buildErrorGroups) - Create dedicated generator modules for paths, headers, and operations - Refactor the main orchestration logic into a cleaner pipeline This is the first phase of a larger maintainability improvement initiative.
WalkthroughThe PR refactors schema generation and content-type utilities from monolithic Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (6)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2025-10-16T00:11:55.898ZApplied to files:
📚 Learning: 2025-10-31T22:24:57.504ZApplied to files:
🧬 Code graph analysis (3)packages/zenko/src/utils/__tests__/schema-utils.test.ts (2)
packages/zenko/src/core/__tests__/schema-generator.test.ts (1)
packages/zenko/src/core/schema-generator.ts (2)
🔇 Additional comments (6)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.