This release focuses on supporting the KBV Base IG (kbv.basis@1.9.0) — a real-world multi-package German IG — with an emphasis on profile support. Generating its profiles surfaced a series of problems in choice type handling, reference target resolution, tree shaking, and introspection; fixing them properly improved profile generation across the board (US Core included), and the Python writer was brought up to parity along the way.
Choice type (value[x]) support in profiles
KBV profiles use open type-sliced choice elements (e.g. Condition.onset[x]), which exposed gaps in how choice constraints were computed and validated:
- Profiles that narrow a choice element now prohibit all undeclared variants, not just the ones restated as fields.
validate()emits the full prohibited list via the newvalidateChoiceProhibited(TS) /validate_choice_prohibited(PY) helpers — a profile narrowingExtension.value[x]tovalueAddressno longer silently accepts resources carrying any other variant (#199, #204) - Choice constraints are resolved monotonically across the profile hierarchy: a child profile can never reintroduce a variant an ancestor prohibited; reintroduction attempts are reported with the new
#nonMonotonicChoicewarning (#200) - Open-sliced choice roots that restate nothing (KBV
onset[x]/abatement[x]) correctly keep all base variants permitted and emit no checks (#200)
Profile reference targets
KBV profiles reference other profiles (e.g. Condition.subject → KBV_PR_Base_Patient), which used to leak profile names into generated types and validators:
- Reference targets pointing at profiles are resolved to their base resource type at transform time, so generated
Reference<...>unions andvalidateReferencechecks always use realresourceTypevalues (Patient/id, neverKBV_PR_Base_Patient/id) — and no longer depend on the referenced profile surviving tree shaking (#201) - Generated TS reference types keep the replaced profile canonical URL as a comment for traceability:
Reference<"Patient" /* ...us-core-patient */>(#205) - New
followReferencestree-shake option (per rule, or for all roots viatreeShakeDefaults) pulls reference targets into the generated set with one flag instead of enumerating every target by hand; following is non-transitive, so it cannot drag in the whole package (#202)
Multi-package introspection fixes
Tree-shaking a single profile out of kbv.basis (which pulls 11 packages) exposed introspection dumping far too much, with wrong attribution:
introspection({ fhirSchemas, structureDefinitions })now dumps only schemas in the tree-shaken index (previously the entire register — 5535 files → 499 for the single-profile KBV example), and StructureDefinitions are attributed to the package that actually declares them (#197)- New
profileSnapshotsflag onintrospection.typeSchemasadditionally exports flattened profile snapshots for debugging profile resolution (#199)
Python writer parity
- Ports prohibited-choice-variant validation, slice required-field validation (
validate_slice_fields), and inherited base-required field checks from the TypeScript writer (#204) Referencebecomes generic: fields are annotated with their targets asReference[Literal["Patient", ...]], with profile targets resolved to base resources (#204)- Tightened
profile_helpers.pytyping: arbitrary-input parameters goAny→object, adding a mypy guardrail against un-narrowed access (#194)
TypeSchema format changes
Generated TS/Python output is unaffected, but consumers of the serialized TypeSchema format should note:
- Slicing is stored separately from fields: field-level
slicingmoved to a schema-levelslicing: Record<fieldName, FieldSlicing>map (#203) - Field reference targets changed from a flat identifier array to a
FieldReferenceobject withresource(base resource types) andprofiles(conformance expectations fromtargetProfile) (#201)
Other
- New on-the-fly example and in-memory snapshot tests for the KBV Condition Diagnosis pipeline (
kbv.basis@1.9.0from the Simplifier registry), pinning every stage from FHIR schema to generated TS (#200, #206) - CI: bump
actions/checkoutto v6; update LICENSE year (#195)
All pull requests
- PY: reduce
Anyin profile_helpers.py by @ryukzak in #194 - CI: bump actions/checkout to v6; update LICENSE year by @ryukzak in #195
- API/TypeSchema: respect tree shaking and fix package attribution in introspection output by @ryukzak in #197
- TypeSchema/API/TS: prohibit undeclared choice variants, validate them, export profile snapshots by @ryukzak in #199
- TypeSchema: resolve choice variants monotonically across the profile hierarchy by @ryukzak in #200
- TypeSchema/TS/PY: resolve reference targets to base resources, keep profile expectations separately by @ryukzak in #201
- TypeSchema: followReferences tree-shake option to generate referenced types by @ryukzak in #202
- TS: comment reference types with replaced profile target URLs by @ryukzak in #205
- PY: port profile validation features and parametrized Reference types from the TypeScript writer by @ryukzak in #204
- API: snapshot tests for the KBV Condition Diagnosis pipeline by @ryukzak in #206
- TypeSchema: store slicing separately from fields by @ryukzak in #203
Full Changelog: v0.0.17...v0.0.18