Skip to content

Commit 24c81e2

Browse files
authored
Replace ResourceDataProvdier with ResoruceVisitor (Azure#48362)
1 parent 311d8f1 commit 24c81e2

File tree

58 files changed

+2608
-876
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2608
-876
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@
262262
</ItemGroup>
263263

264264
<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
265-
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250211.5" />
265+
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250223.1" />
266266
</ItemGroup>
267267

268268
<!--

eng/packages/http-client-csharp/emitter/src/emitter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ import { EmitContext } from "@typespec/compiler";
55

66
import {
77
$onEmit as $OnMGCEmit,
8-
NetEmitterOptions,
8+
CSharpEmitterOptions,
99
setSDKContextOptions
1010
} from "@typespec/http-client-csharp";
1111
import { azureSDKContextOptions } from "./sdk-context-options.js";
1212

13-
export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
13+
export async function $onEmit(context: EmitContext<CSharpEmitterOptions>) {
1414
context.options["plugin-name"] ??= "AzureClientPlugin";
1515
context.options["emitter-extension-path"] = import.meta.url;
1616
setSDKContextOptions(azureSDKContextOptions);

eng/packages/http-client-csharp/eng/scripts/Generate.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ $failingSpecs = @(
8080
Join-Path 'http' 'encode' 'datetime'
8181
Join-Path 'http' 'encode' 'duration'
8282
Join-Path 'http' 'parameters' 'collection-format'
83+
Join-Path 'http' 'response' 'status-code-range' # Response namespace conflicts with Azure.Response
8384
Join-Path 'http' 'routes'
8485
Join-Path 'http' 'type' 'array'
8586
Join-Path 'http' 'type' 'dictionary'

eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubVisitor.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class AzureStubVisitor : ScmLibraryVisitor
1818
private readonly ValueExpression _throwNull = ThrowExpression(Null);
1919
private readonly XmlDocProvider _emptyDocs = new();
2020

21-
protected override TypeProvider? Visit(TypeProvider type)
21+
protected override TypeProvider? VisitType(TypeProvider type)
2222
{
2323
if (!type.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Public) &&
2424
!type.Name.StartsWith("Unknown", StringComparison.Ordinal) &&
@@ -31,7 +31,7 @@ internal class AzureStubVisitor : ScmLibraryVisitor
3131
return type;
3232
}
3333

34-
protected override TypeProvider? PostVisit(TypeProvider type)
34+
protected override TypeProvider? PostVisitType(TypeProvider type)
3535
{
3636
if (type is RestClientProvider &&
3737
type.Methods.Count == 0 &&
@@ -45,7 +45,7 @@ internal class AzureStubVisitor : ScmLibraryVisitor
4545
return type;
4646
}
4747

48-
protected override ConstructorProvider? Visit(ConstructorProvider constructor)
48+
protected override ConstructorProvider? VisitConstructor(ConstructorProvider constructor)
4949
{
5050
if (!IsCallingBaseCtor(constructor) &&
5151
!IsEffectivelyPublic(constructor.Signature.Modifiers) &&
@@ -69,15 +69,15 @@ private static bool IsCallingBaseCtor(ConstructorProvider constructor)
6969
constructor.Signature.Initializer.Arguments.Count > 0;
7070
}
7171

72-
protected override FieldProvider? Visit(FieldProvider field)
72+
protected override FieldProvider? VisitField(FieldProvider field)
7373
{
7474
// For ClientOptions, keep the non-public field as this currently represents the latest service version for a client.
7575
return (field.Modifiers.HasFlag(FieldModifiers.Public) || field.EnclosingType.Implements.Any(i => i.Equals(typeof(ClientPipelineOptions))))
7676
? field
7777
: null;
7878
}
7979

80-
protected override MethodProvider? Visit(MethodProvider method)
80+
protected override MethodProvider? VisitMethod(MethodProvider method)
8181
{
8282
if (method.Signature.ExplicitInterface is null && !IsEffectivelyPublic(method.Signature.Modifiers))
8383
{
@@ -98,7 +98,7 @@ private static bool IsCallingBaseCtor(ConstructorProvider constructor)
9898
return method;
9999
}
100100

101-
protected override PropertyProvider? Visit(PropertyProvider property)
101+
protected override PropertyProvider? VisitProperty(PropertyProvider property)
102102
{
103103
if (!property.IsDiscriminator && !IsEffectivelyPublic(property.Modifiers))
104104
{

eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureClientPlugin.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace Azure.Generator;
1717
/// </summary>
1818
[Export(typeof(CodeModelPlugin))]
1919
[ExportMetadata("PluginName", nameof(AzureClientPlugin))]
20-
public class AzureClientPlugin : ClientModelPlugin
20+
public class AzureClientPlugin : ScmCodeModelPlugin
2121
{
2222
private static AzureClientPlugin? _instance;
2323
internal static AzureClientPlugin Instance => _instance ?? throw new InvalidOperationException("AzureClientPlugin is not loaded.");
@@ -56,6 +56,7 @@ public override void Configure()
5656
if (IsAzureArm.Value)
5757
{
5858
AddVisitor(new RestClientVisitor());
59+
AddVisitor(new ResourceVisitor());
5960
}
6061
}
6162

eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -122,30 +122,6 @@ public override MethodBodyStatement SerializeJsonValue(Type valueType, ValueExpr
122122
return transformedClient is null ? null : base.CreateClientCore(transformedClient);
123123
}
124124

125-
/// <inheritdoc/>
126-
protected override IReadOnlyList<TypeProvider> CreateSerializationsCore(InputType inputType, TypeProvider typeProvider)
127-
{
128-
if (inputType is InputModelType inputModel
129-
&& typeProvider is ModelProvider modelProvider
130-
&& AzureClientPlugin.Instance.OutputLibrary.IsResource(inputType.Name)
131-
&& inputModel.Usage.HasFlag(InputModelTypeUsage.Json))
132-
{
133-
return [new ResourceDataSerializationProvider(inputModel, modelProvider)];
134-
}
135-
136-
return base.CreateSerializationsCore(inputType, typeProvider);
137-
}
138-
139-
/// <inheritdoc/>
140-
protected override ModelProvider? CreateModelCore(InputModelType model)
141-
{
142-
if (AzureClientPlugin.Instance.OutputLibrary.IsResource(model.Name))
143-
{
144-
return new ResourceDataProvider(model);
145-
}
146-
return base.CreateModelCore(model);
147-
}
148-
149125
/// <inheritdoc/>
150126
public override NewProjectScaffolding CreateNewProjectScaffolding()
151127
{

eng/packages/http-client-csharp/generator/Azure.Generator/src/NamespaceVisitor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Azure.Generator
1010
{
1111
internal class NamespaceVisitor : ScmLibraryVisitor
1212
{
13-
protected override ModelProvider? Visit(InputModelType model, ModelProvider? type)
13+
protected override ModelProvider? PreVisitModel(InputModelType model, ModelProvider? type)
1414
{
1515
if (type is not null)
1616
{
@@ -19,7 +19,7 @@ internal class NamespaceVisitor : ScmLibraryVisitor
1919
return type;
2020
}
2121

22-
protected override TypeProvider? Visit(InputEnumType enumType, TypeProvider? type)
22+
protected override EnumProvider? PreVisitEnum(InputEnumType enumType, EnumProvider? type)
2323
{
2424
if (enumType.Usage.HasFlag(InputModelTypeUsage.ApiVersionEnum))
2525
{
@@ -33,7 +33,7 @@ internal class NamespaceVisitor : ScmLibraryVisitor
3333
return type;
3434
}
3535

36-
protected override TypeProvider? Visit(TypeProvider type)
36+
protected override TypeProvider? VisitType(TypeProvider type)
3737
{
3838
if (type is EnumProvider && type.Name == "ServiceVersion")
3939
{
@@ -47,7 +47,7 @@ internal class NamespaceVisitor : ScmLibraryVisitor
4747
}
4848
else
4949
{
50-
type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.RootNamespace;
50+
type.Type.Update(@namespace: AzureClientPlugin.Instance.TypeFactory.PackageName);
5151
}
5252
return type;
5353
}
@@ -57,7 +57,7 @@ private static void UpdateModelsNamespace(TypeProvider type)
5757
// TODO: need to take consideration of model-namespace configuration
5858
// if model-namespace is false, set namespace to $"{AzureClientPlugin.Instance.TypeFactory.RootNamespace}"
5959
// if model-namespace is true, set namespace to $"{AzureClientPlugin.Instance.TypeFactory.RootNamespace}.Models"
60-
type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.GetCleanNameSpace($"{AzureClientPlugin.Instance.TypeFactory.RootNamespace}.Models");
60+
type.Type.Update(@namespace: AzureClientPlugin.Instance.TypeFactory.GetCleanNameSpace($"{AzureClientPlugin.Instance.TypeFactory.PackageName}.Models"));
6161
}
6262
}
6363
}

eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/NewAzureProjectScaffolding.cs

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ protected override string GetSourceProjectFileContent()
2323
{
2424
var builder = new CSharpProjectWriter()
2525
{
26-
Description = $"This is the {AzureClientPlugin.Instance.TypeFactory.RootNamespace} client library for developing .NET applications with rich experience.",
27-
AssemblyTitle = $"SDK Code Generation {AzureClientPlugin.Instance.TypeFactory.RootNamespace}",
26+
Description = $"This is the {AzureClientPlugin.Instance.TypeFactory.PackageName} client library for developing .NET applications with rich experience.",
27+
AssemblyTitle = $"SDK Code Generation {AzureClientPlugin.Instance.TypeFactory.PackageName}",
2828
Version = "1.0.0-beta.1",
29-
PackageTags = AzureClientPlugin.Instance.TypeFactory.RootNamespace,
29+
PackageTags = AzureClientPlugin.Instance.TypeFactory.PackageName,
3030
GenerateDocumentationFile = true,
3131
};
3232

@@ -36,7 +36,7 @@ protected override string GetSourceProjectFileContent()
3636
}
3737

3838
int pathSegmentCount = GetPathSegmentCount();
39-
if (AzureClientPlugin.Instance.InputLibrary.InputNamespace.Auth.ApiKey is not null)
39+
if (AzureClientPlugin.Instance.InputLibrary.InputNamespace.Auth?.ApiKey is not null)
4040
{
4141
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("AzureKeyCredentialPolicy.cs", pathSegmentCount), "Shared/Core"));
4242
}
@@ -133,36 +133,5 @@ private string GetCompileInclude(string fileName, int pathSegmentCount)
133133
new("System.ClientModel"),
134134
new("System.Text.Json")
135135
];
136-
137-
/// <inheritdoc/>
138-
protected override string GetSolutionFileContent()
139-
{
140-
string slnContent = @"Microsoft Visual Studio Solution File, Format Version 12.00
141-
# Visual Studio Version 17
142-
VisualStudioVersion = 17.10.35201.131
143-
MinimumVisualStudioVersion = 10.0.40219.1
144-
Project(""{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}"") = ""{0}"", ""src\{0}.csproj"", ""{{28FF4005-4467-4E36-92E7-DEA27DEB1519}}""
145-
EndProject
146-
Global
147-
GlobalSection(SolutionConfigurationPlatforms) = preSolution
148-
Debug|Any CPU = Debug|Any CPU
149-
Release|Any CPU = Release|Any CPU
150-
EndGlobalSection
151-
GlobalSection(ProjectConfigurationPlatforms) = postSolution
152-
{{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
153-
{{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Debug|Any CPU.Build.0 = Debug|Any CPU
154-
{{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Release|Any CPU.ActiveCfg = Release|Any CPU
155-
{{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Release|Any CPU.Build.0 = Release|Any CPU
156-
EndGlobalSection
157-
GlobalSection(SolutionProperties) = preSolution
158-
HideSolutionNode = FALSE
159-
EndGlobalSection
160-
GlobalSection(ExtensibilityGlobals) = postSolution
161-
SolutionGuid = {{A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}}
162-
EndGlobalSection
163-
EndGlobal
164-
";
165-
return string.Format(slnContent, AzureClientPlugin.Instance.TypeFactory.RootNamespace);
166-
}
167136
}
168137
}

eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataProvider.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataSerializationProvider.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)