Skip to content

Fix: $validate ignores |version in canonical profile URL - #5709

Open
Ketki Sheth (EXPEkesheth) with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-profile-resolution-issue
Open

Fix: $validate ignores |version in canonical profile URL#5709
Ketki Sheth (EXPEkesheth) with Copilot wants to merge 1 commit into
mainfrom
copilot/fix-profile-resolution-issue

Conversation

Copilot AI commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Description

User story link : https://microsofthealth.visualstudio.com/Health/_workitems/edit/199488

When calling POST [base]/{type}/$validate?profile=http://example.org/StructureDefinition/MyProfile|1.0.0, the server resolved whichever version of the profile happened to be last-loaded into the cache rather than the explicitly requested version.

Root cause — two cache key collisions in ServerProvideProfileValidation:

  • GetSummariesAsync: artifacts indexed by artifact.ResourceUri (unversioned URL). Two StructureDefinition resources with the same url but different version values produced identical keys, so the second silently overwrote the first. The Firely SDK's ResolveByCanonicalUri("url|version") correctly filters by version, but only one entry per canonical URL ever survived into _summaries.
  • LoadBySummary: _resourcesByUri cache keyed on the same unversioned ResourceUri, so both versions shared a single cache slot and the wrong resource could be returned.

Fix:

Both locations now use GetCanonicalUrl(artifact) — a helper that was already present and returns url|version when a version element exists — as the key, allowing all distinct versions to coexist independently.

// Before — last version wins, earlier versions lost
result[artifact.ResourceUri] = artifact;

// After — each version stored independently
result[GetCanonicalUrl(artifact)] = artifact;  // returns "url|version" when version present

Tests:

  • Updated existing R4 test GivenMultipleVersionsOfSameProfile_WhenGettingSupportedProfiles_ThenAllVersionsAreReturned — was asserting the buggy single-result behaviour; now asserts both |1.0.0 and |2.0.0 are present.
  • Added GivenMultipleVersionsOfSameProfile_WhenResolvingByVersionedCanonicalUri_ThenCorrectVersionIsReturned in both R4-specific and Shared (STU3/R4/R4B/R5) test projects, verifying that ResolveByCanonicalUriAsync("url|1.0.0") returns the resource with Version == "1.0.0" and not 2.0.0.

Related issues

Testing

Covered by unit tests in Microsoft.Health.Fhir.R4.Core.UnitTests and Microsoft.Health.Fhir.Shared.Core.UnitTests (shared project exercised across all FHIR version contexts).

FHIR Team Checklist

  • Update the title of the PR to be succinct and less than 65 characters
  • Add a milestone to the PR for the sprint that it is merged (i.e. add S47)
  • Tag the PR with the type of update: Bug, Build, Dependencies, Enhancement, New-Feature or Documentation
  • Tag the PR with Open source, Azure API for FHIR (CosmosDB or common code) or Azure Healthcare APIs (SQL or common code) to specify where this change is intended to be released.
  • Tag the PR with Schema Version backward compatible or Schema Version backward incompatible or Schema Version unchanged if this adds or updates Sql script which is/is not backward compatible with the code.
  • When changing or adding behavior, if your code modifies the system design or changes design assumptions, please create and include an ADR.
  • CI is green before merge Build Status
  • Review squash-merge requirements

Semver Change (docs)

Patch

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

Pull request overview

Fixes profile validation resolution for versioned canonical URLs (e.g. StructureDefinition/MyProfile|1.0.0) by eliminating cache key collisions in ServerProvideProfileValidation, ensuring that multiple versions of the same canonical URL can coexist and be resolved deterministically.

Changes:

  • Key _summaries entries by url|version (via existing GetCanonicalUrl) instead of unversioned ResourceUri.
  • Key _resourcesByUri cache entries by url|version to prevent cross-version overwrites during resource materialization.
  • Update/add unit tests (Shared + R4) to assert that multiple versions are returned and that versioned canonical resolution returns the correct version.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Microsoft.Health.Fhir.Shared.Core/Features/Validation/ServerProvideProfileValidation.cs Switch summary/resource caches to use versioned canonical keys (`url
src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.cs Add coverage for multiple-version supported profiles + versioned canonical resolution; extend test helper to set Version.
src/Microsoft.Health.Fhir.R4.Core.UnitTests/Features/Validation/ServerProvideProfileValidationTests.cs Update supported profiles assertion to expect both versions; add versioned canonical resolution test.

@LTA-Thinking

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@codecov-commenter

Codecov Comments Bot (codecov-commenter) commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.88%. Comparing base (ccd2246) to head (efbb032).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #5709      +/-   ##
==========================================
+ Coverage   77.74%   77.88%   +0.13%     
==========================================
  Files        1007     1007              
  Lines       37173    37254      +81     
  Branches     5651     5694      +43     
==========================================
+ Hits        28902    29017     +115     
+ Misses       6896     6862      -34     
  Partials     1375     1375              

see 25 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@LTA-Thinking
Robert Johnson (LTA-Thinking) marked this pull request as ready for review August 11, 2026 18:33
@LTA-Thinking
Robert Johnson (LTA-Thinking) requested a review from a team as a code owner August 11, 2026 18:33
@EXPEkesheth Ketki Sheth (EXPEkesheth) added Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs labels Aug 11, 2026
@EXPEkesheth Ketki Sheth (EXPEkesheth) added the Enhancement Enhancement on existing functionality. label Aug 11, 2026
@EXPEkesheth Ketki Sheth (EXPEkesheth) changed the title Fix: $validate ignores |version in versioned canonical profile URL Fix: $validate ignores |version in canonical profile URL Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Azure API for FHIR Label denotes that the issue or PR is relevant to the Azure API for FHIR Azure Healthcare APIs Label denotes that the issue or PR is relevant to the FHIR service in the Azure Healthcare APIs Enhancement Enhancement on existing functionality. No-ADR ADR not needed No-PaaS-breaking-change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants