Skip to content

Add External property to InputType to preserve original type information#9153

Merged
JoshLove-msft merged 9 commits intomainfrom
copilot/fix-dfe-input-type-info
Dec 8, 2025
Merged

Add External property to InputType to preserve original type information#9153
JoshLove-msft merged 9 commits intomainfrom
copilot/fix-dfe-input-type-info

Conversation

Copy link
Contributor

Copilot AI commented Dec 7, 2025

  • Add InputExternalTypeMetadata interface to TypeScript for external type metadata
  • Add external property to TypeScript InputTypeBase interface
  • Create fromSdkExternalTypeInfo helper function to convert TCGC external info
  • Update fromSdkType to use helper function instead of extracting inline
  • Remove separate InputExternalType handling and preserve original type structure
  • Create C# InputExternalTypeMetadata class
  • Add External property to C# InputType class
  • Create InputExternalTypeMetadataConverter for JSON serialization
  • Update all type converters to handle External property
  • Delete InputExternalType class and converter
  • Update TypeFactory.CreateCSharpTypeCore to check External property first
  • Update CreateExternalType to accept InputExternalTypeMetadata
  • Update tests to validate external property is set on original types
  • Add optional InputExternalTypeMetadata parameter to all applicable InputFactory methods (Union, Array, Dictionary, Model, Enum)
  • Add comprehensive tests for External property deserialization (Union, Model, Array, Dictionary, Enum)
  • Run all tests to ensure no regressions
Original prompt

This section details on the original issue you should resolve

<issue_title>Include original input type information for external types</issue_title>
<issue_description>For the case of DFE in particular, we expect tsp like the following:

@doc("Expression model for DataFactory expressions")
model DfeExpressionModel {
  @doc("The type of expression")
  type: "Expression";
  @doc("The expression value")
  value: string;
}

// DataFactoryElement alternate type pattern
@alternateType({identity: "Azure.Core.Expressions.DataFactoryElement"}, "csharp")
union Dfe<T> {
  T,
  DfeExpressionModel
}

@doc("Model with DataFactoryElement properties")
model DataFactoryElementModel {
  @doc("String property with DFE pattern")
  stringProperty: Dfe<string>;

  @doc("Int property with DFE pattern")
  intProperty: Dfe<int32>;

  @doc("Bool property with DFE pattern")
  boolProperty: Dfe<boolean>;

  @doc("String array property with DFE pattern")
  stringArrayProperty: Dfe<string[]>;
}

Right now, the union is replaced in the C# emitter with an external type. We should include a property on the external type that contains the original input type that was replaced. This is needed for DFE as we need to be able to get the union variant that represents the generic argument. There may be similar scenarios for other alternate types so we should just include the original input type as a property on the constructed external type in the emitter. We will need to update the C# InputExternalType to have a corresponding Original property of type InputType.</issue_description>

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


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 7, 2025 03:49
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@JoshLove-msft
Copy link
Contributor

@copilot we need to delete InputExternalType

Copilot AI changed the title [WIP] Include original input type information for external types Add External property to InputType to preserve original type information Dec 7, 2025
Copilot AI requested a review from JoshLove-msft December 7, 2025 04:01
- Renamed ExternalTypeInfo to InputExternalTypeProperties
- Created fromSdkExternalTypeInfo helper function instead of extracting inline
- Removed externalInfo parameter from all helper functions
- Deleted InputExternalType class and converter
- Updated TypeFactory to check External property and call CreateExternalType
- Updated tests to use new ExternalUnion helper

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 7, 2025

@copilot we need to delete InputExternalType

Done in 8075dd5. Deleted InputExternalType class and converter. Updated TypeFactory to check the External property on types and call CreateExternalType with InputExternalTypeProperties.

Applied rename across TypeScript and C# files as requested

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
- Removed ExternalUnion helper method
- Added optional InputExternalTypeMetadata parameter to Union method
- Updated all test usages to use Union method with external parameter

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@JoshLove-msft JoshLove-msft marked this pull request as ready for review December 8, 2025 01:55
@JoshLove-msft
Copy link
Contributor

Contributes to Azure/azure-sdk-for-net#54347

…ation tests

- Added InputExternalTypeMetadata parameter to Array, Dictionary, Model, and Enum factory methods
- Added 5 comprehensive tests for External property deserialization covering Union, Model, Array, Dictionary, and Enum types

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp label Dec 8, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 8, 2025

No changes needing a change description found.

@JoshLove-msft JoshLove-msft added this pull request to the merge queue Dec 8, 2025
Merged via the queue into main with commit dd00983 Dec 8, 2025
22 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/fix-dfe-input-type-info branch December 8, 2025 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:csharp Issue for the C# client emitter: @typespec/http-client-csharp

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve original input type information for external types

3 participants