Skip to content

Skip meta.profile entries without a string value when picking profiles - #712

Merged
andrzejskowronski merged 1 commit into
developfrom
claude/fix-710-meta-profile-without-value
Oct 20, 2026
Merged

andrzejskowronski merged 1 commit into
developfrom
claude/fix-710-meta-profile-without-value

Conversation

@alexzautke

Copy link
Copy Markdown
Member

Description

ResourceSchema.GetMetaProfileSchemas built a Canonical from every meta.profile value with (string)pn.GetValue()!. This method runs for every resource, so validation threw instead of returning an outcome when:

  • an entry has no value. This is valid FHIR when the entry only carries an extension, e.g. "_profile": [{"extension": [...]}]. It threw ArgumentNullException in every parse mode, including Strict.
  • a lenient parse (SyntaxOnly, Recoverable) kept a non-string JSON value, e.g. "profile": [5]. It threw InvalidCastException.

Neither case names a profile, so only string values are taken now (.OfType<string>()). Nothing changes for valid profile URLs.

Not covered here:

  • With this fix, "profile": [5] still throws, but later, in CanonicalValidator. Its Canonical.Value getter throws on a non-string raw value. That is the wrong-typed-value problem from Investigate and fix our fatal errors. #559/Investigate and fix errors in the model that lead to fatals on the validator #561, which also makes the primitive-bad test case expect a -1 crash.
  • Found while testing: on STU3, ExtensionContextValidator accepts a DATATYPE context only when it is "Any" (ExtensionContextValidator.cs:107), not "*". So STU3 extensions with context datatype *, such as data-absent-reason, are reported as "used outside of appropriate contexts" wherever they appear. The new shared test uses iso21090-nullFlavor on STU3 to work around this.

Related issues

Closes #710

Testing

  • New ResourceSchemaTests.MetaProfileWithoutStringValueIsSkipped: an entry with only an extension, and a number value, parsed in SyntaxOnly mode. Only the string profile is returned.
  • New ResourceSchemaValidationTests.ValidatesMetaProfileWithoutValue (shared, so it runs on STU3/R4/R4B/R5): a Patient whose only meta.profile entry carries an extension validates without issues.
  • Both fail without the fix (with ArgumentNullException / InvalidCastException) and pass with it.
  • dotnet build Firely.Validator.API.slnx -c Release and all test projects pass: Firely.Fhir.Validation.Tests 335, Compilation R4 505, R4B 136, R5 331, STU3 177 (3 skipped per Compilation project, as on develop). No schema snapshot changes.
  • A separate review pass on the diff found nothing blocking. Its one nit, a comment that overstated what the element validators report, is applied.

Generated by Claude Code

GetMetaProfileSchemas cast every meta.profile value to a string and built a
Canonical from it. An entry without a value (valid FHIR when it only carries
an extension) threw ArgumentNullException in every parse mode, and a
non-string JSON value kept by a lenient parse threw InvalidCastException.
Neither names a profile, so both are now skipped.

Fixes #710

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PMryuSqWt3gpT2vJdDfXh8
@alexzautke
alexzautke marked this pull request as ready for review October 19, 2026 19:16
Copilot AI balanced review requested due to automatic review settings October 19, 2026 19:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The narrow filtering change preserves valid profile behavior and has targeted regression coverage, with no unresolved findings.

No open issues 🎉

What changed in this PR

Fixes profile selection to ignore meta.profile entries without string values while preserving valid profile URLs.

Changes:

  • Filters out null and non-string values before constructing canonicals.
  • Adds regression tests for profile selection and extension-only entries across FHIR versions.
File Description
test/​Firely.Fhir.Validation.Tests/​Impl/​ResourceSchemaTests.cs Tests skipping null and numeric profile values.
test/​Firely.Fhir.Validation.Compilation.Tests.Shared/​ResourceSchemaValidationTests.cs Tests validation of extension-only profile entries.
src/​Firely.Fhir.Validation/​Impl/​ResourceSchema.cs Limits profile selection to string values.

Review effort: Balanced

@andrzejskowronski
andrzejskowronski merged commit fbda480 into develop Oct 20, 2026
4 checks passed
@andrzejskowronski
andrzejskowronski deleted the claude/fix-710-meta-profile-without-value branch October 20, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation throws when a meta.profile entry has no string value

4 participants