Skip to content

Feature implementation from commits 89b41b5..494583f #4

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

Open
wants to merge 15 commits into
base: feature-base-branch-2
Choose a base branch
from

Conversation

codeOwlAI
Copy link
Owner

@codeOwlAI codeOwlAI commented Jun 29, 2025

PR Summary

Schema Refinement Feature and Schema Handling Improvements

Overview

This PR adds schema refinement capabilities, improves schema name handling for duplicates, and fixes issues with falsy default values and string trimming.

Change Types

Type Description
Enhancement Added schema refinement feature to modify schemas before Zod conversion
Bug Fix Fixed handling of falsy default values in schema processing
Bug Fix Improved string processing using trim() instead of newline replacement
Enhancement Added support for handling multiple schemas mapped to the same result string
Refactor Formatting improvements for better code readability

Affected Modules

Module / File Change Description
src/openApiToZod.ts Added schema refinement capability and fixed falsy default value handling
src/template-context.ts Added schemaRefiner option type and schema name normalization
src/getZodiosEndpointDefinitionList.ts Improved string processing and schema name lookup behavior
tests/* Added/updated tests for new functionality and fixes

Notes for Reviewers

  • The schema refinement feature allows modifying schemas before they're converted to Zod
  • Pay attention to the fix for falsy default values which now uses explicit undefined checks
  • Schema name normalization now handles dot notation by splitting and using the first part

@@ -65,6 +65,10 @@ export const getZodiosEndpointDefinitionList = (doc: OpenAPIObject, options?: Te
.otherwise((fn) => fn);

const ctx: ConversionTypeContext = { resolver, zodSchemaByName: {}, schemaByName: {} };
if (options?.exportAllNamedSchemas) {
ctx.schemasByName = {};
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Property name mismatch with type definition.

The code initializes ctx.schemasByName but the type definition uses schemaByName (without 's'), which will cause runtime errors when accessing this property.

Current Code (Diff):

-        ctx.schemasByName = {};
+        ctx.schemaByName = {};
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
ctx.schemasByName = {};
ctx.schemaByName = {};

🔄 Dependencies Affected

lib/src/template-context.ts

Function: any function using getZodiosEndpointDefinitionList result

Issue: Code expecting schemaByName property but receiving schemasByName

Suggestion: Update any code using ctx.schemasByName to use ctx.schemaByName instead


dependencies.add(schemaName);
// Sometimes the schema includes a chain that should be removed from the dependency
const [normalizedSchemaName] = schemaName.split(".");
dependencies.add(normalizedSchemaName!);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐛 Correctness Issue

Non-null Assertion on Potentially Undefined Value.

The non-null assertion operator on normalizedSchemaName could cause runtime errors if the split pattern produces unexpected results.

Current Code (Diff):

-                 dependencies.add(normalizedSchemaName!);
+                 dependencies.add(normalizedSchemaName || schemaName);
📝 Committable suggestion

‼️ IMPORTANT
Trust, but verify! 🕵️ Please review this suggestion with the care of a code archaeologist - check that it perfectly replaces the highlighted code, preserves all lines, maintains proper indentation, and won't break anything in production. Your future self will thank you! 🚀

Suggested change
dependencies.add(normalizedSchemaName!);
dependencies.add(normalizedSchemaName || schemaName);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants