Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -262,7 +262,7 @@
</ItemGroup>

<ItemGroup Condition="'$(IsGeneratorLibrary)' == 'true'">
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250211.5" />
<PackageReference Update="Microsoft.TypeSpec.Generator.ClientModel" Version="1.0.0-alpha.20250219.6" />
</ItemGroup>

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

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

export async function $onEmit(context: EmitContext<NetEmitterOptions>) {
export async function $onEmit(context: EmitContext<CSharpEmitterOptions>) {
context.options["plugin-name"] ??= "AzureClientPlugin";
context.options["emitter-extension-path"] = import.meta.url;
setSDKContextOptions(azureSDKContextOptions);
Expand Down
1 change: 1 addition & 0 deletions eng/packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ $failingSpecs = @(
Join-Path 'http' 'encode' 'datetime'
Join-Path 'http' 'encode' 'duration'
Join-Path 'http' 'parameters' 'collection-format'
Join-Path 'http' 'response' 'status-code-range' # Response namespace conflicts with Azure.Response
Join-Path 'http' 'routes'
Join-Path 'http' 'type' 'array'
Join-Path 'http' 'type' 'dictionary'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Azure.Generator;
/// </summary>
[Export(typeof(CodeModelPlugin))]
[ExportMetadata("PluginName", nameof(AzureClientPlugin))]
public class AzureClientPlugin : ClientModelPlugin
public class AzureClientPlugin : ScmCodeModelPlugin
{
private static AzureClientPlugin? _instance;
internal static AzureClientPlugin Instance => _instance ?? throw new InvalidOperationException("AzureClientPlugin is not loaded.");
Expand Down Expand Up @@ -56,6 +56,7 @@ public override void Configure()
if (IsAzureArm.Value)
{
AddVisitor(new RestClientVisitor());
AddVisitor(new ResourceVisitor());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,6 @@ public override MethodBodyStatement SerializeJsonValue(Type valueType, ValueExpr
return transformedClient is null ? null : base.CreateClientCore(transformedClient);
}

/// <inheritdoc/>
protected override IReadOnlyList<TypeProvider> CreateSerializationsCore(InputType inputType, TypeProvider typeProvider)
{
if (inputType is InputModelType inputModel
&& typeProvider is ModelProvider modelProvider
&& AzureClientPlugin.Instance.OutputLibrary.IsResource(inputType.Name)
&& inputModel.Usage.HasFlag(InputModelTypeUsage.Json))
{
return [new ResourceDataSerializationProvider(inputModel, modelProvider)];
}

return base.CreateSerializationsCore(inputType, typeProvider);
}

/// <inheritdoc/>
protected override ModelProvider? CreateModelCore(InputModelType model)
{
if (AzureClientPlugin.Instance.OutputLibrary.IsResource(model.Name))
{
return new ResourceDataProvider(model);
}
return base.CreateModelCore(model);
}

/// <inheritdoc/>
public override NewProjectScaffolding CreateNewProjectScaffolding()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal class NamespaceVisitor : ScmLibraryVisitor
}
else
{
type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.RootNamespace;
type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.GetCleanNameSpace(AzureClientPlugin.Instance.TypeFactory.PackageName);
}
return type;
}
Expand All @@ -57,7 +57,7 @@ private static void UpdateModelsNamespace(TypeProvider type)
// TODO: need to take consideration of model-namespace configuration
// if model-namespace is false, set namespace to $"{AzureClientPlugin.Instance.TypeFactory.RootNamespace}"
// if model-namespace is true, set namespace to $"{AzureClientPlugin.Instance.TypeFactory.RootNamespace}.Models"
type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.GetCleanNameSpace($"{AzureClientPlugin.Instance.TypeFactory.RootNamespace}.Models");
type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.GetCleanNameSpace($"{AzureClientPlugin.Instance.TypeFactory.PackageName}.Models");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ protected override string GetSourceProjectFileContent()
{
var builder = new CSharpProjectWriter()
{
Description = $"This is the {AzureClientPlugin.Instance.TypeFactory.RootNamespace} client library for developing .NET applications with rich experience.",
AssemblyTitle = $"SDK Code Generation {AzureClientPlugin.Instance.TypeFactory.RootNamespace}",
Description = $"This is the {AzureClientPlugin.Instance.TypeFactory.PackageName} client library for developing .NET applications with rich experience.",
AssemblyTitle = $"SDK Code Generation {AzureClientPlugin.Instance.TypeFactory.PackageName}",
Version = "1.0.0-beta.1",
PackageTags = AzureClientPlugin.Instance.TypeFactory.RootNamespace,
PackageTags = AzureClientPlugin.Instance.TypeFactory.PackageName,
GenerateDocumentationFile = true,
};

Expand All @@ -36,7 +36,7 @@ protected override string GetSourceProjectFileContent()
}

int pathSegmentCount = GetPathSegmentCount();
if (AzureClientPlugin.Instance.InputLibrary.InputNamespace.Auth.ApiKey is not null)
if (AzureClientPlugin.Instance.InputLibrary.InputNamespace.Auth?.ApiKey is not null)
{
builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("AzureKeyCredentialPolicy.cs", pathSegmentCount), "Shared/Core"));
}
Expand Down Expand Up @@ -162,7 +162,7 @@ protected override string GetSolutionFileContent()
EndGlobalSection
EndGlobal
";
return string.Format(slnContent, AzureClientPlugin.Instance.TypeFactory.RootNamespace);
return string.Format(slnContent, AzureClientPlugin.Instance.TypeFactory.PackageName);
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.TypeSpec.Generator.ClientModel;
using Microsoft.TypeSpec.Generator.Input;
using Microsoft.TypeSpec.Generator.Providers;
using System.IO;

namespace Azure.Generator
{
internal class ResourceVisitor : ScmLibraryVisitor
{
protected override ModelProvider? Visit(InputModelType model, ModelProvider? type)
{
if (type is not null)
{
TransformResource(type);
}
return type;
}

protected override TypeProvider? Visit(TypeProvider type)
{
TransformResource(type);
return type;
}

private static void TransformResource(TypeProvider type)
{
if (type is ModelProvider && AzureClientPlugin.Instance.OutputLibrary.IsResource(type.Name))
{
type.RelativeFilePath = TransformRelativeFilePath(type);
type.Type.Name = TransformName(type);
foreach (var serialization in type.SerializationProviders)
{
serialization.RelativeFilePath = TransformRelativeFilePathForSerialization(serialization);
serialization.Type.Name = TransformName(serialization);
}
}
}

private static string TransformName(TypeProvider model) => $"{model.Name}Data";

private static string TransformRelativeFilePath(TypeProvider model)
=> Path.Combine("src", "Generated", $"{TransformName(model)}.cs");

private static string TransformRelativeFilePathForSerialization(TypeProvider model)
=> Path.Combine("src", "Generated", $"{TransformName(model)}.Serialization.cs");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ internal class RestClientVisitor : ScmLibraryVisitor
/// <inheritdoc/>
protected override TypeProvider? Visit(TypeProvider type)
{
base.Visit(type);

if (type is ClientProvider)
if (type is not null && type is ClientProvider)
{
type.Update(modifiers: TransfromPublicModifiersToInternal(type), relativeFilePath: TransformRelativeFilePathForClient(type));
type.DeclarationModifiers = TransfromPublicModifiersToInternal(type);
type.RelativeFilePath = TransformRelativeFilePathForClient(type);
}
// TODO: uncomment this once resources are generated
//if (type is RestClientProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static OperationResponse OperationResponse(IEnumerable<int>? statusCodes
["application/json"]);
}

public static InputClient Client(string name, string clientNamespace = "Sample", string? doc = null, IEnumerable<InputOperation>? operations = null, IEnumerable<InputParameter>? parameters = null, string? parent = null)
public static InputClient Client(string name, string clientNamespace = "Samples", string? doc = null, IEnumerable<InputOperation>? operations = null, IEnumerable<InputParameter>? parameters = null, string? parent = null)
{
return new InputClient(
name,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"output-folder": "./outputFolder",
"project-folder": "./projectFolder",
"unknown-bool-property": false,
"library-name": "sample-library",
"package-name": "sample-library",
"unknown-string-property": "unknownPropertyValue"
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static Mock<AzureClientPlugin> LoadMockPlugin(

// initialize the mock singleton instance of the plugin
var codeModelInstance = typeof(CodeModelPlugin).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);
var clientModelInstance = typeof(ClientModelPlugin).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);
var clientModelInstance = typeof(ScmCodeModelPlugin).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);
var azureInstance = typeof(AzureClientPlugin).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic);
// invoke the load method with the config file path
var loadMethod = typeof(Configuration).GetMethod("Load", BindingFlags.Static | BindingFlags.NonPublic);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"output-folder": ".",
"namespace": "BasicTypeSpec",
"library-name": "BasicTypeSpec"
"package-name": "BasicTypeSpec"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"output-folder": ".",
"namespace": "MgmtTypeSpec",
"library-name": "MgmtTypeSpec"
"package-name": "MgmtTypeSpec"
}

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

Loading
Loading