Skip to content

fix(generator): codegen typing fixes for #292, #293, #294#297

Merged
benjamineckstein merged 5 commits into
mainfrom
fix/codegen-typing-294-293-292
Jun 14, 2026
Merged

fix(generator): codegen typing fixes for #292, #293, #294#297
benjamineckstein merged 5 commits into
mainfrom
fix/codegen-typing-294-293-292

Conversation

@benjamineckstein

Copy link
Copy Markdown
Contributor

Three schema-to-TypeScript mapping fixes in packages/openapi-zod-ts, surfaced by the cross-language Laravel e2e demo.

Changes

Verification

  • pnpm -r run build clean
  • pnpm -r run test all packages pass
  • pnpm fallow:audit gate 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

…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.
@github-actions

Copy link
Copy Markdown
Contributor

Fallow audit report

Found 2 findings.

Details
Severity Rule Location Description
minor fallow/unused-dev-dependency examples/package.json:15 Package '@tanstack/react-query' is in devDependencies but never imported; imported in other workspaces: packages/integration
minor fallow/unused-dev-dependency examples/package.json:17 Package 'react' is in devDependencies but never imported; imported in other workspaces: packages/integration

Generated by fallow.

@github-actions

Copy link
Copy Markdown
Contributor

Fallow audit report

0 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.
@benjamineckstein benjamineckstein merged commit 6ac859b into main Jun 14, 2026
7 checks passed
@benjamineckstein benjamineckstein deleted the fix/codegen-typing-294-293-292 branch June 14, 2026 16:58
@github-actions github-actions Bot mentioned this pull request Jun 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant