Skip to content

Resolve Azure.Core.Expressions.DataFactory identities in AzureTypeFactory.CreateFrameworkType#59365

Merged
JoshLove-msft merged 5 commits into
mainfrom
copilot/fix-azure-type-factory-identity-issue
Jun 1, 2026
Merged

Resolve Azure.Core.Expressions.DataFactory identities in AzureTypeFactory.CreateFrameworkType#59365
JoshLove-msft merged 5 commits into
mainfrom
copilot/fix-azure-type-factory-identity-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 20, 2026

Description

Properties whose model type is identity-aliased to an Azure.Core.Expressions.DataFactory.* type via @@alternateType(..., { identity: "..." }, "csharp") were silently dropped from generated SDKs (e.g. SecretBase, LinkedServiceReference, SecureString in Azure.ResourceManager.DataFactory).

The base generator routes InputType.External != null through CreateExternalTypeCreateFrameworkType(Identity). The base CreateFrameworkType resolves via Type.GetType, which cannot find types in Azure.Core.Expressions.DataFactory without an assembly-qualified name. Resolution returns null, CreateExternalType fails, and the property is dropped with no diagnostic.

Changes

  • AzureTypeFactory.CreateFrameworkType: added three explicit fully-qualified-name cases to the existing switch — Azure.Core.Expressions.DataFactory.DataFactorySecret, Azure.Core.Expressions.DataFactory.DataFactoryLinkedServiceReference, and Azure.Core.Expressions.DataFactory.DataFactorySecretString — mapped to their respective typeof(...) values, matching the existing style used for ResourceIdentifier, AzureLocation, ResponseError, and ETag. ManagementTypeFactory inherits the fix.
  • InputFactory.Model (test helper): added an optional externalTypeMetadata parameter so tests can construct InputModelTypes with External set (mirrors the existing Union helper).
  • AzureTypeFactoryTests: end-to-end coverage through CreateCSharpType for an Azure.Core identity and the issue's DataFactorySecret case, plus direct CreateFrameworkType cases for all three documented DataFactory identities.
return fullyQualifiedTypeName switch
{
    "Azure.Core.ResourceIdentifier" => typeof(ResourceIdentifier),
    "Azure.Core.AzureLocation" => typeof(AzureLocation),
    "Azure.ResponseError" => typeof(ResponseError),
    "Azure.ETag" => typeof(ETag),
    "Azure.Core.Expressions.DataFactory.DataFactorySecret" => typeof(DataFactorySecret),
    "Azure.Core.Expressions.DataFactory.DataFactoryLinkedServiceReference" => typeof(DataFactoryLinkedServiceReference),
    "Azure.Core.Expressions.DataFactory.DataFactorySecretString" => typeof(DataFactorySecretString),
    _ => base.CreateFrameworkType(fullyQualifiedTypeName)
};

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

SDK Generation Guidelines

  • If an SDK is being regenerated based on a new swagger spec, a link to the pull request containing these swagger spec changes has been included above.
  • The generate.cmd file for the SDK has been updated with the version of AutoRest, as well as the commitid of your swagger spec or link to the swagger spec, used to generate the code.
  • The *.csproj and AssemblyInfo.cs files have been updated with the new version of the SDK.

…tory.CreateFrameworkType

Agent-Logs-Url: https://github.com/Azure/azure-sdk-for-net/sessions/6129c2eb-fa15-474f-97e0-14f33da46f49

Co-authored-by: haiyuazhang <1924967+haiyuazhang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix AzureTypeFactory dropping properties for identity-aliased models Resolve Azure.Core.Expressions.DataFactory identities in AzureTypeFactory.CreateFrameworkType May 20, 2026
Copilot AI requested a review from haiyuazhang May 20, 2026 12:05
/// <inheritdoc/>
protected override Type? CreateFrameworkType(string fullyQualifiedTypeName)
{
// Resolve types from the Azure.Core.Expressions.DataFactory assembly. These types are
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.

This approach is brittle and not a direction that I'm comfortable with. We shouldn't be special casing libraries via hardcode. We'll want to come up with a more generic approach before moving forward.

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.

I'm not sure this is needed as DFE is already handled through the CreateCSharpType override.

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.

Copy link
Copy Markdown
Member

@JoshLove-msft JoshLove-msft May 20, 2026

Choose a reason for hiding this comment

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

This approach is brittle and not a direction that I'm comfortable with. We shouldn't be special casing libraries via hardcode. We'll want to come up with a more generic approach before moving forward.

Azure.Core.Expressions.DataFactory is a core library that the azure generator already takes a dependency on. However based on my other two comments, I'm not sure why this change is needed.

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 can you clarify why the existing code path in CreateCSharpType is not sufficient? DFE is used as a union type so we need the additional union metadata to resolve the generic arg.

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.

Per offline conversation with Josh, I've come to learn that this is an efficiency pattern already established, not a new pattern. Clearing my blocker.

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.

You're right on both counts — I've reverted the change in 8086b37.

To clarify the original concern: the issue is about non-DFE types (DataFactorySecret, DataFactoryLinkedServiceReference, DataFactorySecretString) appearing as InputModelType.External.Identity, not as union variants — so the CreateCSharpType union override doesn't apply here. However, the base TypeFactory.CreateExternalType (decompiled) does already have the generic fallback you pointed at: when CreateFrameworkType returns null, it calls ExternalTypeReferenceResolver.TryResolve(externalProperties) using the Package/MinVersion metadata, and reports an unsupported-external-type diagnostic only when both fail.

So my fix was special-casing what the generic resolver should handle. The real gap is on the emitter side — @@alternateType(..., { identity: "..." }, "csharp") needs to also emit package (and ideally minVersion) metadata on the InputExternalTypeMetadata so ExternalTypeReferenceResolver can locate the type without hardcoded assembly lookups in the generator. Happy to look at the emitter side if you'd like, but wanted to confirm direction before moving forward.

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.

Since the Azure Generatory is already aware of DataFactory types I think we can extend to include them here. Though, I would prefer just hardcoding the fully qualified name for each type rather than using the startswith and looking up the type from the assembly.
@copilot

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 3d25ee1 — added the three DataFactory FQNs (DataFactorySecret, DataFactoryLinkedServiceReference, DataFactorySecretString) as explicit cases in the existing switch alongside ResourceIdentifier/AzureLocation/ResponseError/ETag, no StartsWith or reflection-based assembly lookup. All 41 AzureTypeFactoryTests pass.

Copilot AI changed the title Resolve Azure.Core.Expressions.DataFactory identities in AzureTypeFactory.CreateFrameworkType Investigate AzureTypeFactory dropping properties for identity-aliased models (no code change) May 20, 2026
@jsquire jsquire dismissed their stale review May 20, 2026 17:01

concerns resolved by offline discussion

Copilot AI requested a review from JoshLove-msft May 20, 2026 17:01
Copilot AI changed the title Investigate AzureTypeFactory dropping properties for identity-aliased models (no code change) Resolve Azure.Core.Expressions.DataFactory identities in AzureTypeFactory.CreateFrameworkType May 20, 2026
"Azure.Core.AzureLocation" => typeof(AzureLocation),
"Azure.ResponseError" => typeof(ResponseError),
"Azure.ETag" => typeof(ETag),
// Types from Azure.Core.Expressions.DataFactory are commonly referenced via
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 remove these comments

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.

Removed in aa8aaac.

Copilot AI requested a review from JoshLove-msft May 20, 2026 18:39
@haiyuazhang haiyuazhang marked this pull request as ready for review May 26, 2026 22:06
Copilot AI review requested due to automatic review settings May 26, 2026 22:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a generator type-resolution gap where @@alternateType(..., { identity: "Azure.Core.Expressions.DataFactory.*" }, "csharp") identities could not be resolved via Type.GetType, causing external/aliased model types to fail resolution and (downstream) generated properties to be dropped.

Changes:

  • Added explicit CreateFrameworkType switch mappings for DataFactorySecret, DataFactoryLinkedServiceReference, and DataFactorySecretString.
  • Extended the test InputFactory.Model helper to allow setting InputModelType.External metadata.
  • Added tests covering external identity resolution through CreateCSharpType and direct CreateFrameworkType resolution for the DataFactory identities.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs Adds explicit framework-type mappings for DataFactory identities to avoid Type.GetType resolution failures.
eng/packages/http-client-csharp/generator/Azure.Generator/test/common/InputFactory.cs Enables constructing InputModelType instances with External metadata for test scenarios.
eng/packages/http-client-csharp/generator/Azure.Generator/test/AzureTypeFactoryTests.cs Adds regression tests for external identity → framework type resolution, including DataFactory types.

Comment on lines 155 to 159
"Azure.ETag" => typeof(ETag),
"Azure.Core.Expressions.DataFactory.DataFactorySecret" => typeof(DataFactorySecret),
"Azure.Core.Expressions.DataFactory.DataFactoryLinkedServiceReference" => typeof(DataFactoryLinkedServiceReference),
"Azure.Core.Expressions.DataFactory.DataFactorySecretString" => typeof(DataFactorySecretString),
_ => base.CreateFrameworkType(fullyQualifiedTypeName)
@JoshLove-msft JoshLove-msft merged commit 8d5aae1 into main Jun 1, 2026
37 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/fix-azure-type-factory-identity-issue branch June 1, 2026 19:14
LavishSingal added a commit to LavishSingal/azure-sdk-for-net that referenced this pull request Jun 3, 2026
Picks up upstream generator fixes:
- LRO OperationSource rename: *OperationSource -> *ResourceOperationSource
  (mgmt codegen LRO array action surface + generic OperationSource hardening, Azure#59522)
- Array body parameter handling (Azure#59566)
- Azure.Core.Expressions.DataFactory identity resolution (Azure#59365)
- Custom base type override for inheritable system types (Azure#56634)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

[Mgmt][CodeGen] AzureTypeFactory drops properties whose model type uses identity-aliased @@alternateType (InputModelType.External.Identity)

7 participants