fix(profile): avoid duplicate meta key when meta is a factory param - #138
Merged
Merged
Conversation
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.
Collaborator
|
Thank you! |
sussdorff
added a commit
to cognovis/codegen
that referenced
this pull request
Apr 21, 2026
…de (codegen-zpq) All production-relevant fork-only code is merged upstream and ships in @atomic-ehr/codegen@0.0.13: - duplicate-meta-key fix (atomic-ehr#138) — landed upstream - KBV on-the-fly workarounds (ignorePackageIndex, preprocessPackage) — landed upstream - real-world regression test via examples/on-the-fly/kbv-r4/profile-patient.test.ts Polaris / mira-adapters consumes @atomic-ehr/codegen directly from npm (always did — the standing consumer-snapshot branch was speculative infrastructure). The fork is retained only as a doc anchor, PR staging area, and future baking ground for the scalar-slice-setters epic (codegen-4cw, blocked). Changes: - COGNOVIS.md: rewritten to document hibernate mode and reactivation criteria - test/api/write-generator/meta-regression.test.ts + fixture + snapshot: removed (redundant with upstream examples/on-the-fly/kbv-r4/profile-patient.test.ts; synthetic code-shape assertions were brittle against legitimate generator refactors) - cognovis/mira-adapters branch deleted, state preserved as tag archive/2026-04-mira-adapters for reactivation if needed
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.
Fixes #137.
Summary
When a profile exposes
metaas a required factory param (e.g. KBV ITA FOR/ERP profiles wheremeta.profileis pinned viamin: 1), the generatedcreateResourceemitted twometa:keys in the same object literal — firstmeta: args.meta,from the generic param loop, thenmeta: { profile: [canonicalUrl] },from the unconditional profile emission. This causedTS1117and silently dropped caller-suppliedmeta.tag/meta.source/ extra profile URLs.Before / After
Before (0.0.10, 0.0.11, 0.0.12 — all broken for profiles with
metain Raw type):After:
Profiles without
metain their Raw type continue to emit the existing single-line form — no behaviour change there.Implementation
src/api/writer-generator/typescript/profile.ts, both emission branches (Input-helper and standard):hasMetaParam = allFields.some((f) => f.name === "meta").metawhenhasMetais true.meta:line, ifhasMetaParam, spreadargs.metaand merge the profile URL intometa.profile; otherwise emit the current static form.Validation
bun test test/unit/— 174 pass / 4 pre-existing snapshot failures unrelated to this change (same onmain).bun test test/api/— 75 pass / 0 fail (no snapshot changes).bun run examples/typescript-r4/generate.ts— regenerates cleanly, zero diff in example output (none of the example profiles havemetain their Raw type, so no emission change).tsc --noEmiterror count from 9 → 0 for the duplicate-meta class.Notes
from()andapply()validation is unaffected because the merged emission still guarantees the profile'scanonicalUrlis inmeta.profile.meta.profilemin=1) if you'd like — wanted to ship the minimal fix first.