Skip to content

Fix inverted pattern containment check & Expand validator test coverage#325

Merged
luisfabib merged 1 commit intomainfrom
fix-pattern-validators
Mar 24, 2026
Merged

Fix inverted pattern containment check & Expand validator test coverage#325
luisfabib merged 1 commit intomainfrom
fix-pattern-validators

Conversation

@luisfabib
Copy link
Copy Markdown
Owner

This PR fixes a false-positive bug in validate_FHIR_element_pattern() (issue #317) where elements with list fields holding values that contradict the pattern were incorrectly accepted. It replaces the broken merge_dicts-based containment check with a new is_dict_subset() utility, and adds full unit test coverage for all previously untested validator functions along with regression tests that directly reproduce the reported bug.

Added

  • is_dict_subset(subset, superset) utility function in utils.py to recursively check that all keys and values in subset are present and matching in superset, with correct handling of nested dicts and lists of primitives.

Changed

Removed

  • Removed the now unused merge_dicts() utility function.

Testing

  • Added comprehensive unit tests for all previously untested validator functions:
  • _validate_FHIR_element_constraint
  • validate_FHIR_element_pattern
  • validate_FHIR_model_pattern
  • validate_FHIR_element_fixed_value
  • validate_FHIR_model_fixed_value
  • validate_type_choice_element
  • validate_slicing_cardinalities
  • get_type_choice_value_by_base.

Replace merge_dicts-based pattern check in validate_FHIR_element_pattern()
with a correct is_dict_subset() check. The old approach produced false positives
when an element's list field held different primitive values from the pattern,
because merge_lists() always kept values from the first (element) dict.

- Add is_dict_subset() to utils.py; remove merge_dicts()
- Update validate_FHIR_element_pattern() to use is_dict_subset(pattern, element)
- Unify FHIRBaseModel/dict/scalar handling into a single branch
- Add full unit test coverage for all validator functions
- Add regression tests covering the false-positive and false-negative cases from #317
@luisfabib luisfabib merged commit 8ae248d into main Mar 24, 2026
3 checks passed
@luisfabib luisfabib deleted the fix-pattern-validators branch March 24, 2026 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validate_FHIR_element_pattern() containment check is inverted

1 participant