fix: generate tsc-safe TypeScript for parameters and payloads presets#374
Open
ALagoni97 wants to merge 1 commit into
Open
fix: generate tsc-safe TypeScript for parameters and payloads presets#374ALagoni97 wants to merge 1 commit into
ALagoni97 wants to merge 1 commit into
Conversation
Generation reported zero errors but the emitted .ts failed `tsc`, breaking downstream `npm run build` in publish pipelines. Four template defects across two presets are fixed. parameters preset (#372): - Serialize/deserialize now access the constrained camelCase field (this.skip) instead of the raw spec name (this.Skip), while the wire key (params.append('Skip'), path placeholders, extractPathParameters cases) keeps the original casing. Threaded a ParameterConfig carrying both names. - Always emit deserializeUrl (a no-op with no query params) so path-only classes, whose fromUrl() calls it unconditionally, compile. payloads/headers presets (#373): - New createMarshallingFixPreset corrects Modelina's class marshal/unmarshal output (Modelina is an external package with no patch tooling). Derived from the model so each replacement targets only the affected property: - drop the `== null ? null : new Date(...)` fallback for required, non-nullable date-time fields (was Date | null, declared Date). - null-guard nullable arrays before iterating them in marshal(). Verified by regenerating both minimal repros and the full safepay-v2 client through tsc --strict (clean), plus regression tests for all four defects. Refs: #372, #373 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
✅ Deploy Preview for the-codegen-project canceled.
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Problem
Generation reports zero errors, but the generated
.tsdoes not compile. A downstream publish pipeline runsnpm i && npm run build && npm publish; thetscbuild step exits non-zero and nothing publishes. These are silent-at-generation, fatal-at-build defects.Fixes four independent template defects across two presets, tracked upstream as #372 (parameters) and #373 (payloads).
Defects & fixes
parameterspreset — #372 (src/codegen/inputs/openapi/generators/parameters.ts)skip) but the code emittedthis.Skip→TS2551 Property 'Skip' does not exist. Introduced aParameterConfigcarrying bothname(original wire key) andpropertyName(constrained accessor), plus abuildConstrainedNameMap()helper. Everythis.*accessor now uses the constrained name; every wire key (params.append('Skip'),params.has(...), URL placeholders,extractPathParametersswitch cases) keeps the original casing. The path serializer already behaved correctly; this makes serialize, deserialize,fromUrl, andextractPathParametersconsistent.deserializeUrlwas only generated when the class had query params, butfromUrl()always calls it. A path-only parameters class failed withTS2551 Property 'deserializeUrl' does not exist.deserializeUrlis now always emitted (a harmless no-op when there are no query params).payloads/headerspresets — #373 (newsrc/codegen/modelina/presets/marshalling.ts)These defects originate in Modelina's
TS_COMMON_PRESETmarshalling. Modelina is an external published package with no patch tooling in this repo, so the fix is a small post-processing preset (createMarshallingFixPreset) that runs immediately afterTS_COMMON_PRESET. Each replacement is derived from the model, so it targets exactly the affected property line and leaves everything else untouched.date-timeinunmarshal().instance.created = obj["created"] == null ? null : new Date(...)yieldsDate | nullwhere the field is declaredDate→TS2322. The null branch is dropped for required, non-nullable date fields.!== undefinedinmarshal(), then iterated.nullslips past the guard intofor (const item of this.signers)→TS2531 Object is possibly 'null'. An explicit!== nullguard is added.Wired into both
payloads.tsandheaders.ts, which share the same marshalling setup.Verification
tsc --strict— clean.tsc(ignoringajv/ajv-formatsresolution noise that resolves afternpm i).parameters.spec.ts([Bug]: TypeScript parameters preset emits non-compiling code (query-param casing + missing deserializeUrl for path-only params) #372) andpayload.spec.ts([Bug]: TypeScript payloads preset emits non-compiling code (non-nullable date-time null fallback + nullable-array marshal) #373), asserting the exact fixed output from inline specs.deserializeUrlno-op added to path-only classes; no payload snapshots changed.lintandtypecheck:testclean.Closes #372
Closes #373
🤖 Generated with Claude Code