Repository navigation
Conversation
… locals Records today's import blocks and validate() output for five causes: - the ten-name validate bundle imported when one validator or none is called - a complex extension resolving to a flat-input profile still imports its sub-extension value type (CodeableConcept) - an extension slice without a url imports Extension and ensurePath unused - a generic extension imports its profile class unused - a profile with nothing to validate emits the profileName/res locals
- collectValidateBody collects the validate() expressions and the validate* helpers they call; the profile-helpers import takes its validate* names from that set, and validate() declares profileName/res only when it has an expression - every other helper is imported under the condition its emitter uses: ensureSliceDefaults, setArraySlice/getArraySlice, isExtension, getExtensionValue, pushExtension, ensurePath and extractComplexExtension; isRawExtensionInput and ensureProfile no longer depend on the canonical url - collectExtensionMethodInfos is the one list of url'd extensions the extension methods and the imports both read, so an extension without a url imports nothing - a complex extension resolving to a flat-input profile no longer imports its sub-extension value types; a generic extension no longer imports its profile class
Flips the pin to the intended import blocks and the local-free empty validate(), and updates the snapshots whose profile modules lose unused helper and type imports.
… its params generateType renders any schema named Reference, Coding or CodeableConcept with the hardcoded `<T extends string>` and drops its IR generic params, but generateDependenciesImports still imported the constraint type only those params named. The CDA Reference imported `Base` (r5) without using it.
Every example tsconfig extends the root one, so an unused import in generated output now fails the example typecheck. Drops the unused test fixtures it flags (_dateTimeType, _periodType, _rangeType, _basePackageInfo) and writes the vflat member check in _flatContractTypes as an expression.
- examples/typescript-r4-us-core/fhir-types: 17 profile modules - examples/typescript-custom-packages/__snapshots__: profile-complex-extension-flat, profile-typed-bundle - examples/on-the-fly/norge-r4/__snapshots__: kjernejournal-profiles - examples/on-the-fly/ccda/__snapshots__: uv-extensions-r4
- RelatedPerson.patient widened to Patient and Person - Provenance.target narrowed from Resource to Patient and Device - Extension.valueReference restated with targets on an unconstrained base - MedicationRequest.reportedReference with an extra Device - Encounter.participant.individual with an extra Patient - a grandchild of the widened profile restating Person only - local Patient and Person profiles as targets alongside Patient - an in-memory generate() over a widened RelatedPerson reports no warnings
- fold each constraint level's reference targets base-to-leaf over the nearest specialization's targets - admit a target when its base resource lies within a permitted one, so Resource and DomainResource admit their descendants - keep the previous targets when a level admits none - warn with #nonMonotonicReference naming the profile, the path and the dropped targets - emit resource and profiles from the surviving targets
- copy the deduplicated #nonMonotonicReference and #nonMonotonicChoice messages of the ts logger into report.warnings after the IR stage
- widened top-level, choice-variant and nested targets are dropped with a warning - a grandchild that allows none of its parent's targets keeps them with a distinct warning - profiles of a dropped resource leave profiles too - generate() reports the warning and prettyReport prints it
- WidenedRelatedPerson (R5) restates RelatedPerson.patient with Patient and Person, added as a tree-shake root - demo builds a valid related person for a Patient - a Person reference fails tsc in createResource and setPatient, and validate() rejects one read from the wire - snapshot of the generated profile module
…ings - a Condition profile restating subject as Resource and Patient keeps Patient and Group and warns about Resource - the CDA fixture's prohibited choice variants reach report.warnings
Palid
marked this pull request as draft
October 1, 2026 02:11
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.
Stacked on #256 — review that first; this PR's diff against it is the last 8 commits. A profile that listed reference targets its base element does not allow got that list verbatim, so its input type was wider than the base field
createResourceassigns it to, and nothing reported it. Reference targets are now narrowed base-to-leaf the way #200 narrows choice variants, and the dropped targets are reported as generation warnings.Closes #255
TypeSchema
resolvePermittedRefersinfield-builder.tsfolds each constraint level's reference targets base-to-leaf over the nearest specialization's targetsResourceandDomainResourceadmit their descendantsResourceonCondition.subjectkeepsPatient,Group)resourceandprofilesare both built from the surviving targets, so a profile of a dropped resource leavesprofilestoo#nonMonotonicReferencetag insrc/utils/log.ts; the warning names the profile, the element and the dropped targets, and points atcanonicalManager.patchesvalidateReferencelist, and Python's annotations,validate_referencelist and accessor comment all follow from the IRA dropped target, and a level whose targets are all outside its ancestor's:
gd-RelatedPersonwithout the norge-r4 patch failedtscwith TS2322; its input type now matches the baseReference<"Patient">, and the runtime check agrees with it:export type GdRelatedPersonProfileRaw = { - patient: Reference<"Person" /* http://ehelse.no/fhir/StructureDefinition/gd-Person, http://hl7.no/fhir/StructureDefinition/no-basis-Person */ | "Patient" /* http://hl7.no/fhir/StructureDefinition/no-basis-Patient */>; + patient: Reference<"Patient" /* http://hl7.no/fhir/StructureDefinition/no-basis-Patient */>; }Generation report
APIBuilder.generate()copies the deduplicated#nonMonotonicReferenceand#nonMonotonicChoicemessages of the ts logger intoreport.warnings, soprettyReportprints aWarnings:linesuppressTagsare left outsuccessand.throwException()are unchanged: the narrowed output compiles, so the run succeedsThe norge-r4 example used to report a plain success; its
Warnings:line now includes:Examples and tests
test/unit/typeschema/transformer/reference.test.ts: the first commit pins the widened targets, a later one asserts the narrowed ones and the warningstest/unit/api/generation-report-warnings.test.ts:report.warnings, theprettyReportline, and a suppressed tagtest/api/write-generator/typescript.test.tsasserts theProtectiveFactorchoice warning inresult.warningsexamples/typescript-custom-packages:widened-related-person.structuredefinition.json(R5,PatientandPersononRelatedPerson.patient), added as one tree-shake rootprofile-reference-widening.test.ts: a demo building a valid related person,@ts-expect-erroron aPersonreference passed tocreateResourceandsetPatient,validate()rejecting one read from the wire, and a snapshot of the generated moduleReach
examples/python-r4-us-core/fhir_types/README.md: one line in its skipped-canonicals list, because that example loads the custom-packagesstructure-definitions/foldergd-RelatedPersonpatch stays; loader-level fixes remain the documented waysfm-MedicationDispenseandsfm-MedicationStatementare left unpatched: they now warn, and theirvalidateReferencelists loseMedicationStatementOpen question: should
report.warningshonoursuppressTags(it does here), or stay independent of the console filter?