Skip to content

fix: narrow ARM metadata filter to only strip exclusively read-only properties#3931

Merged
JialinHuang803 merged 5 commits intomainfrom
copilot/fix-arm-metadata-filter
Apr 23, 2026
Merged

fix: narrow ARM metadata filter to only strip exclusively read-only properties#3931
JialinHuang803 merged 5 commits intomainfrom
copilot/fix-arm-metadata-filter

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

In ARM mode, the metadata property filter in buildModelInterface was stripping @path properties from any model where the property's visibility set contained Visibility.Read — including plain parameter bag models with no ARM base class. Since @path properties carry multiple visibility flags (Read | Create | Update | ...), they were incorrectly filtered out, producing empty interfaces and downstream TypeScript compile failures.

Changes

  • src/modular/emitModels.ts — Tighten the ARM metadata filter condition from p.visibility?.includes(Visibility.Read) to p.visibility?.length === 1 && p.visibility?.includes(Visibility.Read), so only properties that are exclusively read-only are removed.

  • test/modularUnit/scenarios/models/arm/pathPropertyInParameterBag.md — New scenario test reproducing the reported pattern: an ARM service with a plain PrivateLinkParameters model carrying a @path privateLinkName property. Verifies the property survives into the generated interface.

  • test/modularUnit/scenarios/models/arm/armReadCreateVisibility.md — Scenario test verifying a @path property with Read & Create visibility is preserved in the generated interface.

  • test/modularUnit/scenarios/models/arm/armReadOnlyVisibility.md — Scenario test verifying a @path property with exclusively Read visibility is correctly stripped (interface remains empty).

  • test/modularUnit/scenarios/models/arm/armReadUpdateCreateVisibility.md — Scenario test verifying a @path property with Read & Update & Create visibility is preserved in the generated interface.

- p.visibility?.includes(Visibility.Read)
+ p.visibility?.length === 1 && p.visibility?.includes(Visibility.Read)

Before fix:

export interface PrivateLinkParameters {}  // @path property stripped

After fix:

export interface PrivateLinkParameters {
  privateLinkName: string;  // correctly preserved
}

…roperties

The condition in buildModelInterface was too broad - it stripped any property
with Visibility.Read (even if it had other visibilities too), which caused @path
properties on parameter bag models to be incorrectly removed.

Fix: require p.visibility?.length === 1 so only truly read-only (exclusively
Visibility.Read) properties are filtered out in ARM mode.

Add scenario test: models/arm/pathPropertyInParameterBag.md

Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/d8d0fef5-8c72-4a9c-aecd-e64f91755e1c

Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ARM metadata filter for parameter bag models fix: narrow ARM metadata filter to only strip exclusively read-only properties Apr 22, 2026
Copilot AI requested a review from kazrael2119 April 22, 2026 06:46
@kazrael2119
Copy link
Copy Markdown
Member

@copilot could you add more uts about visibility cases like Read & Create, Read, Read & Update & Create?

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 22, 2026

@copilot could you add more uts about visibility cases like Read & Create, Read, Read & Update & Create?

Added three new scenario files in test/modularUnit/scenarios/models/arm/ (commit 5b2dc63):

  • armReadCreateVisibility.md@visibility(Lifecycle.Read, Lifecycle.Create) → property preserved in interface
  • armReadOnlyVisibility.md@visibility(Lifecycle.Read) only → property stripped (interface is empty {})
  • armReadUpdateCreateVisibility.md@visibility(Lifecycle.Read, Lifecycle.Update, Lifecycle.Create) → property preserved in interface

@@ -0,0 +1,66 @@
# ARM metadata filter should preserve @path property with Read & Create visibility
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are four ut files for this case. Does it make sense to combine them into one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot could you resolve this comment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 94b2fca. All four scenario files are now consolidated into a single armMetadataFilter.md with four #-level scenarios (default multi-flag @path, Read & Create, Read only, and Read & Update & Create).

@JialinHuang803 JialinHuang803 enabled auto-merge (squash) April 23, 2026 03:52
@JialinHuang803 JialinHuang803 merged commit 0148c04 into main Apr 23, 2026
16 checks passed
@JialinHuang803 JialinHuang803 deleted the copilot/fix-arm-metadata-filter branch April 23, 2026 04:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] ARM metadata filter incorrectly strips @path properties from parameter bag models with no base class

4 participants