fix(generator): codegen typing fixes for #292, #293, #294#297
Merged
Conversation
…e serialization JSON.stringify throws on bigint values and JSON.parse never produces bigint, making z.bigint() unworkable for standard API clients. int64 fields now map to number with an inline comment noting precision is limited to 2^53-1. Changes: - primitiveToTs(): int64 branch returns 'number /* int64, precision limited to 2^53-1 */' - primitiveToZod(): int64 branch returns 'z.number()' - primitiveTypeToZod(): remove dead 'if (base !== z.bigint())' guard so numeric constraints (min/max/multipleOf) now chain correctly onto int64 fields - Update int64 unit tests in types-unit.test.ts and zod-unit.test.ts - Regenerate committed example output (openai and generated-rq models.ts files) BREAKING CHANGE: int64 fields previously generated as bigint / z.bigint(). Consumers who relied on bigint types for int64 fields must update their code. User-owned schemas.ts files containing z.bigint() for int64 properties will get TS compile errors and must be manually updated to z.number(). Closes #292
…string, T>
inlineSchemaToTs() in client.ts previously returned 'Record<string, unknown>'
for any object type unconditionally. When an operation response schema has
additionalProperties set to a schema object, the generated return type now
recurses into the value schema and produces Record<string, T>.
The named-schema path in types.ts already handled this correctly via
schemaToTypeString. This fix brings the inline response path in line with it.
Examples:
- additionalProperties: {type: integer, format: int32} -> Record<string, number>
- additionalProperties: {type: string} -> Record<string, string>
- additionalProperties: true -> Record<string, unknown> (unchanged)
- no additionalProperties -> Record<string, unknown> (unchanged)
Closes #294
…or bodies
Adds optional error_body_type and error_body_type_import fields to Config.
When set, schema-less error responses in the generated client are cast to the
specified type instead of unknown.
Special value 'laravel' emits a built-in LaravelValidationError type
({ message: string; errors: Record<string, string[]> }) alongside ApiError
and casts the error body to it. No import is needed for this built-in.
Any other non-empty string is used as a type name directly. When
error_body_type_import is also set, the generator emits an import type
statement at the top of the generated client. Without an import path the type
is treated as ambient/global (a deliberate choice documented in the JSDoc).
Changes:
- Config interface: error_body_type and error_body_type_import optional fields
- parseConfig(): validates both fields as non-empty strings when present
- ClientOptions: errorBodyType and errorBodyTypeImport optional fields
- HelperFeatures: errorBodyType field threaded to emitErrorCheckAndReturn()
- emitErrorCheckAndReturn(): accepts optional errorBodyType, emits typed cast
- generateClient(): emits LaravelValidationError type after ApiError when
errorBodyType is 'laravel'; emits import type when custom type + import set
- generator.ts: passes config.error_body_type and error_body_type_import into
ClientOptions for both initial and schema-enhanced generation passes
Closes #293
…aToTs Extract validateErrorBodyConfig() from parseConfig() to hold the error_body_type/error_body_type_import validation branches, bringing parseConfig below the cyclomatic threshold. Extract inlineObjectSchemaToTs() from inlineSchemaToTs() to hold the additionalProperties object branch, bringing inlineSchemaToTs below the cyclomatic and cognitive thresholds. Pure extraction, no behavior change.
Contributor
Fallow audit reportFound 2 findings. Details
Generated by fallow. |
Contributor
Fallow audit report0 inline findings selected for GitHub review. |
…ies changes petstore-3.0 getInventory() return type updated from Record<string, unknown> to Record<string, number> in both examples/generated and examples/generated-rq, fixing the Showcase CI drift check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Three schema-to-TypeScript mapping fixes in
packages/openapi-zod-ts, surfaced by the cross-language Laravel e2e demo.Changes
bigintbreak at runtime: JSON.stringify throws, JSON.parse loses precision #292 (BREAKING) mapint64tonumber /* int64, precision limited to 2^53-1 */andz.number()instead ofbigint/z.bigint().JSON.stringifythrows on bigint andJSON.parsenever yields bigint, so the old combo was broken in both directions. Removed the now-dead z.bigint() constraint guard. Regenerated 7 committed examplemodels.tsoutputs.Record<string, unknown>instead of the value type #294 type inlineadditionalPropertiesresponses asRecord<string, T>instead ofRecord<string, unknown>.unknown; offer a typed error fallback #293 add optionalerror_body_type(+error_body_type_import) config to type schema-less error response bodies; ships a built-inLaravelValidationErrortype forerror_body_type: 'laravel'.refactorcommit extracts helpers to keepparseConfig/inlineSchemaToTsunder the fallow complexity gate.Verification
pnpm -r run buildcleanpnpm -r run testall packages passpnpm fallow:auditgate passes (exit 0)Note
#292 is a breaking change — Release Please will propose a MAJOR version bump. Per repo policy this needs maintainer sign-off before merging the release PR.
Closes #292
Closes #293
Closes #294