Skip to content

Commit d454341

Browse files
authored
Add IsAzureArm to distinguish MPG and DPG (Azure#47374)
1 parent ebf909b commit d454341

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

eng/Packages.Data.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
</ItemGroup>
255255

256256
<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
257-
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20241121.2" />
257+
<PackageReference Update="Microsoft.Generator.CSharp.ClientModel" Version="1.0.0-alpha.20241128.1" />
258258
</ItemGroup>
259259

260260
<!--

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ import { EmitContext } from "@typespec/compiler";
55

66
import {
77
$onEmit as $OnMGCEmit,
8-
NetEmitterOptions
8+
NetEmitterOptions,
9+
setSDKContextOptions
910
} from "@typespec/http-client-csharp";
11+
import { azureSDKContextOptions } from "./sdk-context-options.js";
1012

1113
export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
1214
context.options["plugin-name"] = "AzureClientPlugin";
1315
context.options["emitter-extension-path"] = import.meta.url;
16+
setSDKContextOptions(azureSDKContextOptions);
1417
await $OnMGCEmit(context);
1518
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
import { CreateSdkContextOptions } from "@azure-tools/typespec-client-generator-core";
5+
6+
export const azureSDKContextOptions: CreateSdkContextOptions = {
7+
versioning: {},
8+
additionalDecorators: [
9+
// https://github.com/Azure/typespec-azure/blob/main/packages/typespec-client-generator-core/README.md#usesystemtextjsonconverter
10+
"Azure\\.ClientGenerator\\.Core\\.@useSystemTextJsonConverter",
11+
// https://github.com/Azure/typespec-azure/blob/main/packages/typespec-azure-resource-manager/README.md#armprovidernamespace
12+
"Azure\\.ResourceManager\\.@armProviderNamespace"
13+
]
14+
};

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
using Microsoft.CodeAnalysis;
55
using Microsoft.Generator.CSharp;
66
using Microsoft.Generator.CSharp.ClientModel;
7+
using Microsoft.Generator.CSharp.Input;
78
using System;
89
using System.ComponentModel.Composition;
910
using System.IO;
11+
using System.Linq;
1012

1113
namespace Azure.Generator;
1214

@@ -56,4 +58,9 @@ public override void Configure()
5658
// Copyright (c) Microsoft Corporation. All rights reserved.
5759
// Licensed under the MIT License.
5860
""";
61+
62+
/// <summary>
63+
/// Identify if the input is generated for Azure ARM.
64+
/// </summary>
65+
internal Lazy<bool> IsAzureArm => new Lazy<bool>(() => InputLibrary.InputNamespace.Clients.Any(c => c.Decorators.Any(d => d.Name.Equals("Azure.ResourceManager.@armProviderNamespace"))));
5966
}

eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.RestClient.cs

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)