Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 5, 2025

  • Understand the issue: Generate DataFactoryElement<T> properties from InputUnionType with InputExternalType identity "Azure.Core.Expressions.DataFactoryElement"
  • Implement DataFactoryElement detection in AzureTypeFactory.CreateCSharpTypeCore()
  • Add package reference for Azure.Core.Expressions.DataFactory
  • Add factory methods to create InputUnionType and InputExternalType in tests
  • Add unit tests for DataFactoryElement type creation (7 tests total)
  • Add tests validating serialization/deserialization patterns (2 new tests)
  • Address PR feedback:
    • Move DataFactoryElementIdentity constant to top of class
    • Add logging using AzureClientGenerator.Instance.Emitter.ReportDiagnostic
    • Remove InputExternalType branch (not needed)
    • Add test for model inner type
    • Add DataFactoryElement patterns to Basic-TypeSpec.tsp with alternateType decorators
    • Verify serialization/deserialization is handled automatically by base generator
    • Move alternateType decorator from each union to DfeExpressionModel

Summary

This PR adds support for generating DataFactoryElement<T> properties in the Azure generator when encountering an InputUnionType that contains an InputExternalType variant with identity "Azure.Core.Expressions.DataFactoryElement".

Key Changes:

  1. AzureTypeFactory.cs:

    • Added TryCreateDataFactoryElementTypeFromUnion() method
    • Creates DataFactoryElement<T> where T is derived from the other union variant
    • Logs warning via Emitter when union has multiple variants
  2. Azure.Generator.csproj: Added reference to Azure.Core.Expressions.DataFactory package

  3. Tests: 9 comprehensive unit tests covering:

    • Type creation for string/int/bool/array/model variants
    • Edge cases (non-DFE external type, multiple variants)
    • Serialization using WriteObjectValue pattern
    • Deserialization using DeserializeDataFactoryElement pattern
  4. Basic-TypeSpec.tsp: Added DataFactoryElement union patterns with alternateType decorator on DfeExpressionModel

Serialization/Deserialization

The base generator automatically handles DataFactoryElement<T> serialization and deserialization because:

  • Serialization uses WriteObjectValue<T> which leverages IJsonModel<T> internally
  • Deserialization uses the DeserializeDataFactoryElement static method
    No changes to KnownAzureTypes.cs were needed.
Original prompt

This section details on the original issue you should resolve

<issue_title>Support generating DataFactoryElement<> properties in the Azure generator</issue_title>
<issue_description>In https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs#L66, we need to handle InputUnionType that has a variant type of InputExternalType where the identity is "Azure.Core.Expressions.DataFactoryElement" in a special way. The logic should be that we create a generic type DataFactoryElement<T> where T is given by the other variant in the union. If there is more than one variant we should just log a warning and not apply this specialized logic.

We should update our test spec https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Basic-TypeSpec.tsp

This shows the full set of supported T values https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core.Expressions.DataFactory/src/DataFactoryElementJsonConverter.cs

include uses of this pattern. Here is the tsp:

union Dfe<T> {
  T,
  DfeModel,
}
model DfeModel {
  kind: "Expression";
  value: string;
}

/** A widget. */
@resource("widgets")
model Widget {
  /** The widget name. */
  @key("widgetName")
  @visibility(Lifecycle.Read)
  name: string;

  fooString: Dfe<string>;
  
  fooInt: Dfe<int>;

  fooModel: Dfe<SomeModel>;

  fooList: Dfe<string[]>;


  /** The widget color. */
  color: WidgetColor;

  /** The ID of the widget's manufacturer. */
  manufacturerId: string;
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Support generating DataFactoryElement properties in Azure generator Support generating DataFactoryElement<T> properties in the Azure generator Dec 5, 2025
Copilot finished work on behalf of JoshLove-msft December 5, 2025 21:36
Copilot AI requested a review from JoshLove-msft December 5, 2025 21:36
return base.CreateCSharpTypeCore(inputType);
}

private const string DataFactoryElementIdentity = "Azure.Core.Expressions.DataFactoryElement";
Copy link
Member

Choose a reason for hiding this comment

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

@copilot move this to the top of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 7074a2b.

// If there is more than one other variant, log a warning and don't apply specialized logic
if (otherVariantCount != 1 || otherVariantType == null)
{
// TODO: Add proper logging when logging infrastructure is available
Copy link
Member

Choose a reason for hiding this comment

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

@copilot we can log this with AzureClientGenerator.Instance.Emitter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0ea2c90. Using AzureClientGenerator.Instance.Emitter.ReportDiagnostic("DFE001", message) to log the warning.

}
}
else if (inputType is InputExternalType inputExternalType)
{
Copy link
Member

Choose a reason for hiding this comment

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

@copilot we can remove this branch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0ea2c90. Removed the InputExternalType branch.

@JoshLove-msft
Copy link
Member

}

[Test]
public void DataFactoryElementNotAppliedForNonDataFactoryExternalType()
Copy link
Member

Choose a reason for hiding this comment

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

@copilot let's also add a test where the inner type is a model.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 0ea2c90. Added DataFactoryElementWithModel() test that verifies the union type with an InputModelType inner type.

@JoshLove-msft
Copy link
Member

@copilot we need to update KnownAzureTypes to handle serialization/deserialization.

@JoshLove-msft
Copy link
Member

@copilot we need to update KnownAzureTypes to handle serialization/deserialization.

Or is this already handled automatically? We should add a test that validates ModelReaderWriter is used for these properties.

Copy link
Contributor Author

Copilot AI commented Dec 5, 2025

@copilot please also add models/properties using alternateType with Dfe to https://github.com/Azure/azure-sdk-for-net/blob/main/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeS...

Done in 0ea2c90. Added:

  • DfeExpressionModel - the expression model
  • DfeStringUnion, DfeIntUnion, DfeBoolUnion, DfeStringArrayUnion - union types
  • DataFactoryElementModel - model with DFE properties
  • @@alternateType decorators mapping to Azure.Core.Expressions.DataFactoryElement
  • Operations CreateDataFactoryModel and GetDataFactoryModel

Copy link
Contributor Author

Copilot AI commented Dec 5, 2025

@copilot we need to update KnownAzureTypes to handle serialization/deserialization.

Or is this already handled automatically? We should add a test that validates ModelReaderWriter is used for the...

Yes, it's handled automatically by the base generator. Added tests in b1eebe7 that validate:

  • Serialization uses WriteObjectValue<DataFactoryElement<T>> which internally leverages IJsonModel<T>
  • Deserialization uses DeserializeDataFactoryElement static method

No changes to KnownAzureTypes.cs were needed since the base generator already handles types implementing IJsonModel<T> correctly.

Copilot AI changed the title Support generating DataFactoryElement<T> properties in the Azure generator Support generating DataFactoryElement<> properties in the Azure generator Dec 5, 2025
Copilot finished work on behalf of JoshLove-msft December 5, 2025 22:42
package: "Azure.Core.Expressions.DataFactory",
}, "csharp");

@@alternateType(DfeStringArrayUnion, {
Copy link
Member

Choose a reason for hiding this comment

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

@copilot this shouldn't be repeated on each of the unions. It should instead go on DfeExpressionModel.

Copy link
Member

Choose a reason for hiding this comment

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

We should also add it inline rather than using an augment decorator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 18c9019. Moved the @@alternateType decorator to DfeExpressionModel instead of repeating it on each union.

Copilot AI requested a review from JoshLove-msft December 6, 2025 00:34
Copilot finished work on behalf of JoshLove-msft December 6, 2025 00:34
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.

Support generating DataFactoryElement<> properties in the Azure generator

2 participants