Skip to content

Commit 3e7b772

Browse files
committed
fix(profile): avoid duplicate meta key when meta is a factory param
When a profile exposes `meta` as a required factory param (e.g. KBV FOR/ERP profiles where `meta.profile` is pinned via min=1), the TypeScript profile writer emitted two `meta:` keys in the same `createResource` object literal — the first from the generic param loop and the second from the unconditional `meta: { profile: [...] }` emission. This produced TypeScript TS1117 errors and silently dropped any caller-supplied `meta.tag` / `meta.source` / extra profile URLs, because the second key overwrote the first. Fix: when `meta` is already in `allFields`, suppress the generic emission and merge the caller-supplied meta with the profile's canonical URL: meta: { ...args.meta, profile: [...(args.meta?.profile ?? []), canonicalUrl] } Profiles without `meta` in params are unchanged: meta: { profile: [canonicalUrl] } Applies to both the Input-helper branch (with extension slices) and the standard branch. Typecheck on consuming project (mira-adapters, 10+ KBV profiles) goes from 9 TS1117 errors to 0 after regeneration.
1 parent 373dc66 commit 3e7b772

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

src/api/writer-generator/typescript/profile.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,14 +488,22 @@ const generateFactoryMethods = (
488488
}
489489
w.line();
490490
const extensionVar = extSliceField ? "extensionWithDefaults" : "resolvedExtensions";
491+
const hasMetaParam = allFields.some((f) => f.name === "meta");
491492
w.curlyBlock([`const resource: ${tsBaseResourceName} =`], () => {
492493
for (const f of allFields) {
493494
if (f.name === "extension") continue;
495+
if (f.name === "meta" && hasMeta) continue;
494496
w.line(`${f.name}: ${f.value},`);
495497
}
496498
w.line(`extension: ${extensionVar},`);
497499
if (hasMeta) {
498-
w.line(`meta: { profile: [${profileClassName}.canonicalUrl] },`);
500+
if (hasMetaParam) {
501+
w.line(
502+
`meta: { ...args.meta, profile: [...(args.meta?.profile ?? []), ${profileClassName}.canonicalUrl] },`,
503+
);
504+
} else {
505+
w.line(`meta: { profile: [${profileClassName}.canonicalUrl] },`);
506+
}
499507
}
500508
});
501509

@@ -530,12 +538,20 @@ const generateFactoryMethods = (
530538
if (isPrimitiveIdentifier(flatProfile.base)) {
531539
w.lineSM(`const resource = undefined as unknown as ${tsBaseResourceName}`);
532540
} else {
541+
const hasMetaParam = allFields.some((f) => f.name === "meta");
533542
w.curlyBlock([`const resource: ${tsBaseResourceName} =`], () => {
534543
for (const f of allFields) {
544+
if (f.name === "meta" && hasMeta) continue;
535545
w.line(`${f.name}: ${f.value},`);
536546
}
537547
if (hasMeta) {
538-
w.line(`meta: { profile: [${profileClassName}.canonicalUrl] },`);
548+
if (hasMetaParam) {
549+
w.line(
550+
`meta: { ...args.meta, profile: [...(args.meta?.profile ?? []), ${profileClassName}.canonicalUrl] },`,
551+
);
552+
} else {
553+
w.line(`meta: { profile: [${profileClassName}.canonicalUrl] },`);
554+
}
539555
}
540556
});
541557
}

0 commit comments

Comments
 (0)