Skip to content

fix(formats): match an anyOf of formats on the source schema - #4832

Merged
kddejong merged 2 commits into
aws-cloudformation:mainfrom
kddejong:fix/comparer-source-anyof
Oct 22, 2026
Merged

kddejong merged 2 commits into
aws-cloudformation:mainfrom
kddejong:fix/comparer-source-anyof

Conversation

@kddejong

Copy link
Copy Markdown
Contributor

What

RefFormat (E1041) and GetAttFormat (E1040) compare the property schema (the source) against the Ref/GetAtt return schema (the destination) in _schema_comparer.compare_schemas. An anyOf of formats was only honored on the destination: on the source, the entry point reads a single source.get("format") and returns None (no check) when it is absent. So a property that declares an anyOf of acceptable formats was not validated at all — a reference returning a matching format passed, but so did one returning a completely unrelated format.

Fix

When the source schema has no plain format but has an anyOf of formats, treat the property as compatible when the reference matches any listed format, and report when it matches none — mirroring the behavior the destination side already has via _any_of.

Why

This is needed for properties that legitimately accept more than one referenced type. The motivating case is Route53 AliasTarget.HostedZoneId, which accepts either a service's canonical hosted-zone id (AWS::Route53::AliasTarget.HostedZoneId) or a Ref to a hosted zone you own (AWS::Route53::HostedZone.Id) for a same-zone alias. The schema side is a companion change in resource-provider-enhanced-schemas (emits the anyOf); this PR is the engine support it depends on.

Tests

  • test_schema_comparer: a source anyOf now matches when any format is compatible and errors when none are (replacing the previous case that asserted a non-matching source anyOf was silently valid), plus the Route53 positive/negative pair.
  • Full test/unit/rules/formats, test_ref_format, test_getatt_format: 106 pass.
  • No new E1040/E1041 findings across the entire test/fixtures/templates/good corpus (yaml + json), so no currently-clean template regresses.
  • ruff / ruff format / isort / mypy / bandit clean.

RefFormat/GetAttFormat compare the property schema (source) against the
Ref/GetAtt return schema (destination). anyOf of formats was only honored
on the destination; a property declaring an anyOf of formats was skipped
entirely, so a wrong reference went unreported. Match when any source
format is compatible with the destination, and report when none are.
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.67%. Comparing base (f0b0e23) to head (d1075f5).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4832   +/-   ##
=======================================
  Coverage   94.67%   94.67%           
=======================================
  Files         439      439           
  Lines       15985    15995   +10     
  Branches     3100     3104    +4     
=======================================
+ Hits        15134    15144   +10     
  Misses        468      468           
  Partials      383      383           
Flag Coverage Δ
unittests 94.67% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Add cases for an anyOf source with no format keywords (unchecked) and an
anyOf source against a destination with no format, covering the new
branches in compare_schemas.
@kddejong
kddejong merged commit 2a10fb4 into aws-cloudformation:main Oct 22, 2026
24 checks passed
@kddejong
kddejong deleted the fix/comparer-source-anyof branch October 22, 2026 19:33
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.

1 participant