-
Couldn't load subscription status.
- Fork 318
[http-client-csharp] Implement support for external type references #8770
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
497cfa3
Initial plan
Copilot 493aa60
Add InputExternalType and external type conversion support
Copilot 4f54dad
Add C# InputExternalType and generator support
Copilot 41e8231
Fix CSharpType constructor call for external types
Copilot a7cfd42
Emit diagnostic for unsupported external types and return null
Copilot a36175f
Move diagnostic emission from emitter to generator code
Copilot 6a86688
Update packages/http-client-csharp/generator/Microsoft.TypeSpec.Gener…
JoshLove-msft b860183
Remove unused UnsupportedExternalType diagnostic code constant
Copilot d0b8dab
Add tests for external type functionality to ModelProviderTests
Copilot 729508c
Rename external type tests to follow existing naming convention
Copilot 66014de
Add InputExternalTypeConverter for JSON deserialization
Copilot cc44f24
Remove manual imports/usings from tests, use IsTCGCNeeded option
Copilot 76ede4f
format
JoshLove-msft 8e9d047
Update test to use C# identity instead of Python package
Copilot 8850356
Update diagnostic message and make CreateExternalType private
Copilot 9a1eb09
Revert diagnostic message to original simpler version
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...t-csharp/generator/Microsoft.TypeSpec.Generator.Input/src/InputTypes/InputExternalType.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Microsoft.TypeSpec.Generator.Input | ||
| { | ||
| /// <summary> | ||
| /// Represents an external type reference in the input model. | ||
| /// </summary> | ||
| public sealed class InputExternalType : InputType | ||
| { | ||
| /// <summary> | ||
| /// Construct a new <see cref="InputExternalType"/> instance | ||
| /// </summary> | ||
| /// <param name="identity">The fully qualified name of the external type.</param> | ||
| /// <param name="package">The package that exports the external type.</param> | ||
| /// <param name="minVersion">The minimum version of the package.</param> | ||
| public InputExternalType(string identity, string? package, string? minVersion) : base("external") | ||
| { | ||
| Identity = identity; | ||
| Package = package; | ||
| MinVersion = minVersion; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The fully qualified name of the external type. For example, "Azure.Core.Expressions.DataFactoryExpression" | ||
| /// </summary> | ||
| public string Identity { get; } | ||
|
|
||
| /// <summary> | ||
| /// The package that exports the external type. For example, "Azure.Core.Expressions" | ||
| /// </summary> | ||
| public string? Package { get; } | ||
|
|
||
| /// <summary> | ||
| /// The minimum version of the package to use for the external type. For example, "1.0.0" | ||
| /// </summary> | ||
| public string? MinVersion { get; } | ||
| } | ||
| } | ||
62 changes: 62 additions & 0 deletions
62
...osoft.TypeSpec.Generator.Input/src/InputTypes/Serialization/InputExternalTypeConverter.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Microsoft.TypeSpec.Generator.Input | ||
| { | ||
| internal class InputExternalTypeConverter : JsonConverter<InputExternalType> | ||
| { | ||
| private readonly TypeSpecReferenceHandler _referenceHandler; | ||
|
|
||
| public InputExternalTypeConverter(TypeSpecReferenceHandler referenceHandler) | ||
| { | ||
| _referenceHandler = referenceHandler; | ||
| } | ||
|
|
||
| public override InputExternalType Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| => reader.ReadReferenceAndResolve<InputExternalType>(_referenceHandler.CurrentResolver) ?? CreateInputExternalType(ref reader, null, options, _referenceHandler.CurrentResolver); | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, InputExternalType value, JsonSerializerOptions options) | ||
| => throw new NotSupportedException("Writing not supported"); | ||
|
|
||
| public static InputExternalType CreateInputExternalType(ref Utf8JsonReader reader, string? id, JsonSerializerOptions options, ReferenceResolver resolver) | ||
| { | ||
| string? identity = null; | ||
| string? package = null; | ||
| string? minVersion = null; | ||
| IReadOnlyList<InputDecoratorInfo>? decorators = null; | ||
|
|
||
| while (reader.TokenType != JsonTokenType.EndObject) | ||
| { | ||
| var isKnownProperty = reader.TryReadReferenceId(ref id) | ||
| || reader.TryReadString("identity", ref identity) | ||
| || reader.TryReadString("package", ref package) | ||
| || reader.TryReadString("minVersion", ref minVersion) | ||
| || reader.TryReadComplexType("decorators", options, ref decorators); | ||
|
|
||
| if (!isKnownProperty) | ||
| { | ||
| reader.SkipProperty(); | ||
| } | ||
| } | ||
|
|
||
| identity = identity ?? throw new JsonException("InputExternalType must have identity"); | ||
|
|
||
| var externalType = new InputExternalType(identity, package, minVersion) | ||
| { | ||
| Decorators = decorators ?? [] | ||
| }; | ||
|
|
||
| if (id != null) | ||
| { | ||
| resolver.AddReference(id, externalType); | ||
| } | ||
|
|
||
| return externalType; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.