Skip to content

Commit

Permalink
Add IsAzureArm to distinguish MPG and DPG (#47374)
Browse files Browse the repository at this point in the history
  • Loading branch information
live1206 authored Dec 2, 2024
1 parent ebf909b commit d454341
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eng/Packages.Data.props
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@
</ItemGroup>

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

<!--
Expand Down
5 changes: 4 additions & 1 deletion eng/packages/http-client-csharp/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ import { EmitContext } from "@typespec/compiler";

import {
$onEmit as $OnMGCEmit,
NetEmitterOptions
NetEmitterOptions,
setSDKContextOptions
} from "@typespec/http-client-csharp";
import { azureSDKContextOptions } from "./sdk-context-options.js";

export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
context.options["plugin-name"] = "AzureClientPlugin";
context.options["emitter-extension-path"] = import.meta.url;
setSDKContextOptions(azureSDKContextOptions);
await $OnMGCEmit(context);
}
14 changes: 14 additions & 0 deletions eng/packages/http-client-csharp/emitter/src/sdk-context-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

import { CreateSdkContextOptions } from "@azure-tools/typespec-client-generator-core";

export const azureSDKContextOptions: CreateSdkContextOptions = {
versioning: {},
additionalDecorators: [
// https://github.com/Azure/typespec-azure/blob/main/packages/typespec-client-generator-core/README.md#usesystemtextjsonconverter
"Azure\\.ClientGenerator\\.Core\\.@useSystemTextJsonConverter",
// https://github.com/Azure/typespec-azure/blob/main/packages/typespec-azure-resource-manager/README.md#armprovidernamespace
"Azure\\.ResourceManager\\.@armProviderNamespace"
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using Microsoft.CodeAnalysis;
using Microsoft.Generator.CSharp;
using Microsoft.Generator.CSharp.ClientModel;
using Microsoft.Generator.CSharp.Input;
using System;
using System.ComponentModel.Composition;
using System.IO;
using System.Linq;

namespace Azure.Generator;

Expand Down Expand Up @@ -56,4 +58,9 @@ public override void Configure()
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
""";

/// <summary>
/// Identify if the input is generated for Azure ARM.
/// </summary>
internal Lazy<bool> IsAzureArm => new Lazy<bool>(() => InputLibrary.InputNamespace.Clients.Any(c => c.Decorators.Any(d => d.Name.Equals("Azure.ResourceManager.@armProviderNamespace"))));
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d454341

Please sign in to comment.