Skip to content
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

Add IsAzureArm to distinguish MPG and DPG #47374

Merged
merged 5 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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: [
"Azure\\.ClientGenerator\\.Core\\.@useSystemTextJsonConverter",
live1206 marked this conversation as resolved.
Show resolved Hide resolved
"Azure\\.ResourceManager\\.@armProviderNamespace"
live1206 marked this conversation as resolved.
Show resolved Hide resolved
]
};
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class AzureClientPlugin : ClientModelPlugin
/// <inheritdoc/>
public override AzureOutputLibrary OutputLibrary => _azureOutputLibrary ??= new();

private AzureInputLibrary? _azureInputLibrary;
/// <inheritdoc/>
public override AzureInputLibrary InputLibrary => _azureInputLibrary ??= new(Instance.Configuration.OutputDirectory);

/// <summary>
/// The Azure client plugin to generate the Azure client SDK.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.Generator.CSharp.Input;
using System;
using System.Linq;

namespace Azure.Generator
{
/// <inheritdoc/>
public class AzureInputLibrary : InputLibrary
{
/// <inheritdoc/>
public AzureInputLibrary(string codeModelPath) : base(codeModelPath)
{
}

/// <summary>
/// Identify if the input is generated for Azure ARM.
/// </summary>
internal Lazy<bool> IsAzureArm => new Lazy<bool>(() => InputNamespace.Clients.Any(c => c.Decorators.Any(d => d.Name.Equals("Azure.ResourceManager.@armProviderNamespace"))));
live1206 marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static Mock<AzureClientPlugin> LoadMockPlugin(
inputNsModels,
inputNsClients,
inputNsAuth);
var mockInputLibrary = new Mock<InputLibrary>(_configFilePath);
var mockInputLibrary = new Mock<AzureInputLibrary>(_configFilePath);
mockInputLibrary.Setup(p => p.InputNamespace).Returns(mockInputNs.Object);

if (createCSharpTypeCore is not null)
Expand Down

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

Loading