diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index 61310d3a043c..3427c5c6c0ea 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -81,7 +81,7 @@
# ServiceOwners: @adamedx
# PRLabel: %AI Model Inference %AI Projects
-/sdk/ai/ @trangevi @dargilco @jhakulin @glharper @jhakulin
+/sdk/ai/ @trangevi @dargilco @jhakulin @glharper @jhakulin @nick863
# PRLabel: %AI Model Inference
/sdk/ai/Azure.AI.Inference @trangevi @dargilco @jhakulin @glharper
@@ -90,10 +90,10 @@
# ServiceOwners: @trangevi @dargilco @jhakulin @glharper
# PRLabel: %AI Projects
-/sdk/ai/Azure.AI.Projects @jhakulin
+/sdk/ai/Azure.AI.Projects @jhakulin @nick863
# ServiceLabel: %AI Projects
-# ServiceOwners: @dargilco @jhakulin
+# ServiceOwners: @dargilco @jhakulin @nick863
# ServiceLabel: %AKS
# ServiceOwners: @Azure/aks-pm
@@ -970,20 +970,14 @@
# ServiceLabel: %Astronomer %Mgmt
# ServiceOwners: @banggaurav
-# PRLabel: %Azure Stack Hci
-/sdk/azurestackhci/Azure.ResourceManager.Hci/ @priyjain358
-
-# ServiceLabel: %Azure Stack Hci %Mgmt
-# ServiceOwners: @priyjain358
-
# PRLabel: %Communication - Resource Manager
/sdk/communication/Azure.ResourceManager.Communication/ @archerzz @ArcturusZhang @ArthurMa1978
# PRLabel: %Compute - Fleet
-/sdk/computefleet/Azure.ResourceManager.*/ @sahilarora92 @dhruvil009 @rahuls-microsoft
+/sdk/computefleet/Azure.ResourceManager.*/ @sahilarora92 @rahuls-microsoft
# ServiceLabel: %Compute - Fleet %Mgmt
-# ServiceOwners: @sahilarora92 @dhruvil009 @rahuls-microsoft
+# ServiceOwners: @sahilarora92 @rahuls-microsoft
# PRLael: %Container Orchestrator Runtime
/sdk/containerorchestratorruntime/Azure.ResourceManager.*/ @HE-Xinyu @ddadaal
@@ -1111,3 +1105,6 @@
#PRLabel: %CodeGen %Client
/eng/packages/http-client-csharp/generator/Azure.Generator/ @JoshLove-msft @m-nash @jorgerangel-msft @jsquire @annelo-msft
+
+#PRLabel: %CodeGen %Client
+/eng/scripts/typespec/ @JoshLove-msft @m-nash @jorgerangel-msft @jsquire @annelo-msft
diff --git a/.vscode/cspell.json b/.vscode/cspell.json
index 9977a311186e..23632732e354 100644
--- a/.vscode/cspell.json
+++ b/.vscode/cspell.json
@@ -1638,6 +1638,15 @@
"words": [
"prebuilts"
]
+ },
+ {
+ "filename": "**/sdk/iotoperations/Azure.ResourceManager.IotOperations/api/*.cs",
+ "words": [
+ "sasl",
+ "Sasl",
+ "Acks",
+ "acks"
+ ]
}
],
"allowCompoundWords": true
diff --git a/README.md b/README.md
index 73419ed29159..85c322d54605 100644
--- a/README.md
+++ b/README.md
@@ -21,7 +21,7 @@ Each service might have a number of libraries available from each of the followi
New wave of packages that we are announcing as **GA** and several that are currently releasing in **preview**. These libraries follow the [Azure SDK Design Guidelines for .NET](https://azure.github.io/azure-sdk/dotnet/guidelines/) and share a number of core features such as HTTP retries, logging, transport protocols, authentication protocols, etc., so that once you learn how to use these features in one client library, you will know how to use them in other client libraries. You can learn about these shared features at [Azure.Core](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/README.md).
-These new client libraries can be identified by the naming used for their folder, package, and namespace. Each will start with `Azure`, followed by the service category, and then the name of the service. For example `Azure.Storage.Blobs`.
+These new client libraries can be identified by the naming used for their folder, package, and namespace. Each will start with `Azure`, followed by the service category, and then the name of the service. For example `Azure.Storage.Blobs`.
For a complete list of available packages, please see the [latest available packages](https://azure.github.io/azure-sdk/releases/latest/dotnet.html) page.
@@ -33,9 +33,9 @@ Last stable versions of packages that are production-ready. These libraries prov
### Management: New Releases
-A new set of management libraries that follow the [Azure SDK Design Guidelines for .NET](https://azure.github.io/azure-sdk/dotnet_introduction.html) and based on [Azure.Core libraries](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/core/Azure.Core) are now in Public Preview. These new libraries provide a number of core capabilities that are shared amongst all Azure SDKs, including the intuitive Azure Identity library, an HTTP Pipeline with custom policies, error-handling, distributed tracing, and much more. You can find the list of new packages [on this page](https://azure.github.io/azure-sdk/releases/latest/dotnet.html).
+A new set of management libraries that follow the [Azure SDK Design Guidelines for .NET](https://azure.github.io/azure-sdk/dotnet_introduction.html) and based on [Azure.Core libraries](https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/core/Azure.Core) are now in Public Preview. These new libraries provide a number of core capabilities that are shared amongst all Azure SDKs, including the intuitive Azure Identity library, an HTTP Pipeline with custom policies, error-handling, distributed tracing, and much more. You can find the list of new packages [on this page](https://azure.github.io/azure-sdk/releases/latest/dotnet.html).
-To get started with these new libraries, please see the [quickstart guide here](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/mgmt_preview_quickstart.md). These new libraries can be identified by namespaces that start with `Azure.ResourceManager`, e.g. `Azure.ResourceManager.Network`
+To get started with these new libraries, please see the [quickstart guide here](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/mgmt_preview_quickstart.md). These new libraries can be identified by namespaces that start with `Azure.ResourceManager`, e.g. `Azure.ResourceManager.Network`
> NOTE: If you need to ensure your code is ready for production use one of the stable, non-preview libraries.
@@ -80,5 +80,3 @@ https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
-
-
diff --git a/doc/README.md b/doc/README.md
index fbf070de9477..5916f50f93d6 100644
--- a/doc/README.md
+++ b/doc/README.md
@@ -4,5 +4,3 @@ This folder contains some documentations for this repository:
The folder structure is the following
- [dev](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev) : contains advanced documentation for _developers_ of SDK (not _consumers_ of SDK)
- [ApiDocGeneration](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/ApiDocGeneration) : contains scripts and assets for generating API documentation
-
-
diff --git a/eng/Microsoft.Build.CentralPackageVersions/2.0.46/Sdk/Sdk.targets b/eng/Microsoft.Build.CentralPackageVersions/2.0.46/Sdk/Sdk.targets
index 43139d8c12e4..abdfbfc01c63 100644
--- a/eng/Microsoft.Build.CentralPackageVersions/2.0.46/Sdk/Sdk.targets
+++ b/eng/Microsoft.Build.CentralPackageVersions/2.0.46/Sdk/Sdk.targets
@@ -130,7 +130,7 @@
+ Condition=" '$(EnableCentralPackageVersions)' != 'false' And '$(DesignTimeBuild)' != 'true' And @(PackageReference->Count()) > 0">
+
+
+
@@ -113,7 +117,7 @@
-
+
@@ -121,15 +125,15 @@
+
-
-
-
-
-
-
+
+
+
+
+
@@ -137,7 +141,7 @@
-
+
@@ -186,7 +190,7 @@
-
+
@@ -229,7 +233,7 @@
-
+
@@ -243,7 +247,7 @@
All should have PrivateAssets="All" set so they don't become package dependencies
-->
-
+
@@ -258,7 +262,7 @@
-
+
+
+
+
+
+
+
+
+
+
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubPlugin.cs b/eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubPlugin.cs
new file mode 100644
index 000000000000..f60918f41314
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubPlugin.cs
@@ -0,0 +1,32 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Microsoft.TypeSpec.Generator;
+using System.ComponentModel.Composition;
+
+namespace Azure.Generator.StubLibrary
+{
+ ///
+ /// The stub library plugin to generate the stub library.
+ ///
+ [Export(typeof(CodeModelPlugin))]
+ [ExportMetadata("PluginName", nameof(AzureStubPlugin))]
+ public class AzureStubPlugin : AzureClientPlugin
+ {
+ ///
+ /// The stub library plugin to generate the stub library.
+ ///
+ /// The Generator Context.
+ [ImportingConstructor]
+ public AzureStubPlugin(GeneratorContext context) : base(context) { }
+
+ ///
+ /// Customize the generation output for stub library.
+ ///
+ public override void Configure()
+ {
+ base.Configure();
+ AddVisitor(new AzureStubVisitor());
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubVisitor.cs b/eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubVisitor.cs
new file mode 100644
index 000000000000..890636388e29
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator.StubLibrary/src/AzureStubVisitor.cs
@@ -0,0 +1,132 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using System;
+using System.ClientModel.Primitives;
+using System.Linq;
+using Microsoft.TypeSpec.Generator.ClientModel;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
+
+namespace Azure.Generator.StubLibrary
+{
+ internal class AzureStubVisitor : ScmLibraryVisitor
+ {
+ private readonly ValueExpression _throwNull = ThrowExpression(Null);
+ private readonly XmlDocProvider _emptyDocs = new();
+
+ protected override TypeProvider? Visit(TypeProvider type)
+ {
+ if (!type.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Public) &&
+ !type.Name.StartsWith("Unknown", StringComparison.Ordinal) &&
+ !type.Name.Equals("MultiPartFormDataBinaryContent", StringComparison.Ordinal))
+ {
+ return null;
+ }
+
+ type.Update(xmlDocs: _emptyDocs);
+ return type;
+ }
+
+ protected override TypeProvider? PostVisit(TypeProvider type)
+ {
+ if (type is RestClientProvider &&
+ type.Methods.Count == 0 &&
+ type.Constructors.Count == 0 &&
+ type.Properties.Count == 0 &&
+ type.Fields.Count == 0)
+ {
+ return null;
+ }
+
+ return type;
+ }
+
+ protected override ConstructorProvider? Visit(ConstructorProvider constructor)
+ {
+ if (!IsCallingBaseCtor(constructor) &&
+ !IsEffectivelyPublic(constructor.Signature.Modifiers) &&
+ (constructor.EnclosingType is not ModelProvider model || model.DerivedModels.Count == 0))
+ {
+ return null;
+ }
+
+ constructor.Update(
+ bodyStatements: null,
+ bodyExpression: _throwNull,
+ xmlDocs: _emptyDocs);
+
+ return constructor;
+ }
+
+ private static bool IsCallingBaseCtor(ConstructorProvider constructor)
+ {
+ return constructor.Signature.Initializer is not null &&
+ constructor.Signature.Initializer.IsBase &&
+ constructor.Signature.Initializer.Arguments.Count > 0;
+ }
+
+ protected override FieldProvider? Visit(FieldProvider field)
+ {
+ // For ClientOptions, keep the non-public field as this currently represents the latest service version for a client.
+ return (field.Modifiers.HasFlag(FieldModifiers.Public) || field.EnclosingType.Implements.Any(i => i.Equals(typeof(ClientPipelineOptions))))
+ ? field
+ : null;
+ }
+
+ protected override MethodProvider? Visit(MethodProvider method)
+ {
+ if (method.Signature.ExplicitInterface is null && !IsEffectivelyPublic(method.Signature.Modifiers))
+ {
+ return null;
+ }
+
+ method.Signature.Update(modifiers: method.Signature.Modifiers & ~MethodSignatureModifiers.Async);
+
+ var docs = method.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Implicit)
+ ? method.XmlDocs
+ : _emptyDocs;
+
+ method.Update(
+ bodyStatements: null,
+ bodyExpression: _throwNull,
+ xmlDocProvider: docs);
+
+ return method;
+ }
+
+ protected override PropertyProvider? Visit(PropertyProvider property)
+ {
+ if (!property.IsDiscriminator && !IsEffectivelyPublic(property.Modifiers))
+ {
+ return null;
+ }
+
+ var propertyBody = new ExpressionPropertyBody(_throwNull, property.Body.HasSetter ? _throwNull : null);
+
+ property.Update(
+ body: propertyBody,
+ xmlDocs: _emptyDocs);
+
+ return property;
+ }
+
+ private bool IsEffectivelyPublic(MethodSignatureModifiers modifiers)
+ {
+ if (modifiers.HasFlag(MethodSignatureModifiers.Public))
+ {
+ return true;
+ }
+
+ if (modifiers.HasFlag(MethodSignatureModifiers.Protected) && !modifiers.HasFlag(MethodSignatureModifiers.Private))
+ {
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator.sln b/eng/packages/http-client-csharp/generator/Azure.Generator.sln
index 975f6a6f8cd1..c2022838d5dc 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator.sln
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator.sln
@@ -5,10 +5,14 @@ VisualStudioVersion = 17.10.35201.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Generator", "Azure.Generator\src\Azure.Generator.csproj", "{8DDB0B72-B3F6-4F87-8B04-163EB4880FC8}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicTypeSpec", "TestProjects\Local\Basic-TypeSpec\src\BasicTypeSpec.csproj", "{F8386530-1166-438C-99DC-AE855036A37C}"
-EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Generator.Tests", "Azure.Generator\test\Azure.Generator.Tests.csproj", "{A05E6873-DD18-44B2-88A8-DEE3AA103EC4}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProjects.Local.Tests", "TestProjects\Local.Tests\TestProjects.Local.Tests.csproj", "{0E941DC3-BC8B-1031-859C-EBB387036FD6}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Azure.Generator.StubLibrary", "Azure.Generator.StubLibrary\src\Azure.Generator.StubLibrary.csproj", "{CC2E7459-398A-60FA-5138-282707944E43}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProjects.Spector.Tests", "TestProjects\Spector.Tests\TestProjects.Spector.Tests.csproj", "{FD729CC8-FAAC-B384-0328-6F590DCAA5AA}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -19,14 +23,22 @@ Global
{8DDB0B72-B3F6-4F87-8B04-163EB4880FC8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DDB0B72-B3F6-4F87-8B04-163EB4880FC8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DDB0B72-B3F6-4F87-8B04-163EB4880FC8}.Release|Any CPU.Build.0 = Release|Any CPU
- {F8386530-1166-438C-99DC-AE855036A37C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {F8386530-1166-438C-99DC-AE855036A37C}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {F8386530-1166-438C-99DC-AE855036A37C}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {F8386530-1166-438C-99DC-AE855036A37C}.Release|Any CPU.Build.0 = Release|Any CPU
{A05E6873-DD18-44B2-88A8-DEE3AA103EC4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A05E6873-DD18-44B2-88A8-DEE3AA103EC4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A05E6873-DD18-44B2-88A8-DEE3AA103EC4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A05E6873-DD18-44B2-88A8-DEE3AA103EC4}.Release|Any CPU.Build.0 = Release|Any CPU
+ {0E941DC3-BC8B-1031-859C-EBB387036FD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {0E941DC3-BC8B-1031-859C-EBB387036FD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {0E941DC3-BC8B-1031-859C-EBB387036FD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {0E941DC3-BC8B-1031-859C-EBB387036FD6}.Release|Any CPU.Build.0 = Release|Any CPU
+ {CC2E7459-398A-60FA-5138-282707944E43}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {CC2E7459-398A-60FA-5138-282707944E43}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {CC2E7459-398A-60FA-5138-282707944E43}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {CC2E7459-398A-60FA-5138-282707944E43}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FD729CC8-FAAC-B384-0328-6F590DCAA5AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FD729CC8-FAAC-B384-0328-6F590DCAA5AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FD729CC8-FAAC-B384-0328-6F590DCAA5AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FD729CC8-FAAC-B384-0328-6F590DCAA5AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Azure.Generator.csproj b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Azure.Generator.csproj
index cc580e9ac201..8ee15c37f1ce 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Azure.Generator.csproj
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Azure.Generator.csproj
@@ -1,18 +1,21 @@
- net8.0
Azure.Generator
1.0.0-beta.1
true
- CS8002
- latest
-
-
-
-
+
+
+
+
+
+
+
+
+
+
@@ -20,6 +23,7 @@
+
@@ -30,6 +34,57 @@
Always
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureClientPlugin.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureClientPlugin.cs
index dc341ea919c1..066a1dd6c09e 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureClientPlugin.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureClientPlugin.cs
@@ -3,9 +3,8 @@
using Azure.Generator.Utilities;
using Microsoft.CodeAnalysis;
-using Microsoft.Generator.CSharp;
-using Microsoft.Generator.CSharp.ClientModel;
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator;
+using Microsoft.TypeSpec.Generator.ClientModel;
using System;
using System.ComponentModel.Composition;
using System.IO;
@@ -53,9 +52,10 @@ public override void Configure()
AddMetadataReference(MetadataReference.CreateFromFile(typeof(Response).Assembly.Location));
var sharedSourceDirectory = Path.Combine(Path.GetDirectoryName(typeof(AzureClientPlugin).Assembly.Location)!, "Shared", "Core");
AddSharedSourceDirectory(sharedSourceDirectory);
+ AddVisitor(new NamespaceVisitor());
if (IsAzureArm.Value)
{
- AddVisitor(new AzureArmVisitor());
+ AddVisitor(new RestClientVisitor());
}
}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureOutputLibrary.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureOutputLibrary.cs
index ad6c15eeaaef..d2e9a8da24f4 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureOutputLibrary.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureOutputLibrary.cs
@@ -4,8 +4,8 @@
using Azure.Generator.Mgmt.Models;
using Azure.Generator.Providers;
using Azure.Generator.Utilities;
-using Microsoft.Generator.CSharp.ClientModel;
-using Microsoft.Generator.CSharp.Providers;
+using Microsoft.TypeSpec.Generator.ClientModel;
+using Microsoft.TypeSpec.Generator.Providers;
using System.Collections.Generic;
namespace Azure.Generator
@@ -76,7 +76,20 @@ private Dictionary CategorizeClients()
///
// TODO: generate resources and collections
- protected override TypeProvider[] BuildTypeProviders() => [.. base.BuildTypeProviders(), new RequestContextExtensionsDefinition()];
+ protected override TypeProvider[] BuildTypeProviders()
+ {
+ if (AzureClientPlugin.Instance.IsAzureArm.Value == true)
+ {
+ var armOperation = new MgmtLongRunningOperationProvider(false);
+ var genericArmOperation = new MgmtLongRunningOperationProvider(true);
+
+ // TODO: remove them once they are referenced in Resource operation implementation
+ AzureClientPlugin.Instance.AddTypeToKeep(armOperation.Name);
+ AzureClientPlugin.Instance.AddTypeToKeep(genericArmOperation.Name);
+ return [.. base.BuildTypeProviders(), new RequestContextExtensionsDefinition(), armOperation, genericArmOperation];
+ }
+ return [.. base.BuildTypeProviders(), new RequestContextExtensionsDefinition()];
+ }
internal bool IsResource(string name) => _resourceDataBySpecNameMap.ContainsKey(name);
}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs
index b42b7fb532a4..93ce7107e0d2 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs
@@ -5,14 +5,14 @@
using Azure.Generator.Primitives;
using Azure.Generator.Providers;
using Azure.Generator.Providers.Abstraction;
-using Microsoft.Generator.CSharp.ClientModel;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Providers;
-using Microsoft.Generator.CSharp.Snippets;
-using Microsoft.Generator.CSharp.Statements;
+using Microsoft.TypeSpec.Generator.ClientModel;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.Snippets;
+using Microsoft.TypeSpec.Generator.Statements;
using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
@@ -78,7 +78,9 @@ public class AzureTypeFactory : ScmTypeFactory
}
///
+#pragma warning disable AZC0014 // Avoid using banned types in public API
public override ValueExpression DeserializeJsonValue(Type valueType, ScopedApi element, SerializationFormat format)
+#pragma warning restore AZC0014 // Avoid using banned types in public API
{
var expression = DeserializeJsonValueCore(valueType, element, format);
return expression ?? base.DeserializeJsonValue(valueType, element, format);
@@ -143,5 +145,11 @@ protected override IReadOnlyList CreateSerializationsCore(InputTyp
}
return base.CreateModelCore(model);
}
+
+ ///
+ public override NewProjectScaffolding CreateNewProjectScaffolding()
+ {
+ return new NewAzureProjectScaffolding();
+ }
}
}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/InputTransformation/InputClientTransformer.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/InputTransformation/InputClientTransformer.cs
index 1b5363ed9769..838f538f00b2 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/InputTransformation/InputClientTransformer.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/InputTransformation/InputClientTransformer.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator.Input;
using System;
using System.Collections.Generic;
@@ -26,7 +26,7 @@ internal static class InputClientTransformer
// There is no need to check sub-clients or custom code since it is specific to handle the above removing
if (operationsToKeep.Count == 0) return null;
- return new InputClient(client.Name, client.Summary, client.Doc, operationsToKeep, client.Parameters, client.Parent);
+ return new InputClient(client.Name, client.Namespace, client.Summary, client.Doc, operationsToKeep, client.Parameters, client.Parent);
}
private static IReadOnlyList TransformInputOperationParameters(InputOperation operation)
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Mgmt/Models/OperationSet.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Mgmt/Models/OperationSet.cs
index bf071b8dc06a..feebbee65b16 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Mgmt/Models/OperationSet.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Mgmt/Models/OperationSet.cs
@@ -3,7 +3,7 @@
using Azure.Core;
using Azure.Generator.Utilities;
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator.Input;
using System;
using System.Collections;
using System.Collections.Generic;
@@ -85,8 +85,6 @@ public bool Equals([AllowNull] OperationSet other)
return null;
}
-
-
private InputOperation? FindBestOperation()
{
// first we try GET operation
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/NamespaceVisitor.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/NamespaceVisitor.cs
new file mode 100644
index 000000000000..50451067f6ac
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/NamespaceVisitor.cs
@@ -0,0 +1,63 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Microsoft.TypeSpec.Generator.ClientModel;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Providers;
+
+namespace Azure.Generator
+{
+ internal class NamespaceVisitor : ScmLibraryVisitor
+ {
+ protected override ModelProvider? Visit(InputModelType model, ModelProvider? type)
+ {
+ if (type is not null)
+ {
+ UpdateModelsNamespace(type);
+ }
+ return type;
+ }
+
+ protected override TypeProvider? Visit(InputEnumType enumType, TypeProvider? type)
+ {
+ if (enumType.Usage.HasFlag(InputModelTypeUsage.ApiVersionEnum))
+ {
+ return type;
+ }
+
+ if (type is not null)
+ {
+ UpdateModelsNamespace(type);
+ }
+ return type;
+ }
+
+ protected override TypeProvider? Visit(TypeProvider type)
+ {
+ if (type is EnumProvider && type.Name == "ServiceVersion")
+ {
+ return type;
+ }
+
+ if (type is ModelProvider || type is EnumProvider || type is ModelFactoryProvider
+ || type is MrwSerializationTypeDefinition || type is FixedEnumSerializationProvider || type is ExtensibleEnumSerializationProvider)
+ {
+ UpdateModelsNamespace(type);
+ }
+ else
+ {
+ type.Type.Namespace = AzureClientPlugin.Instance.TypeFactory.RootNamespace;
+ }
+ return type;
+ }
+
+ 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");
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/KnownAzureTypes.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/KnownAzureTypes.cs
index 263e94ca0bd6..22127225b086 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/KnownAzureTypes.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/KnownAzureTypes.cs
@@ -2,19 +2,19 @@
// Licensed under the MIT License.
using Azure.Core;
-using Microsoft.Generator.CSharp.ClientModel.Snippets;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Snippets;
-using Microsoft.Generator.CSharp.Statements;
+using Microsoft.TypeSpec.Generator.ClientModel.Snippets;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Snippets;
+using Microsoft.TypeSpec.Generator.Statements;
using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Text.Json;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Primitives
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/NewAzureProjectScaffolding.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/NewAzureProjectScaffolding.cs
new file mode 100644
index 000000000000..6211ba5a5054
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Primitives/NewAzureProjectScaffolding.cs
@@ -0,0 +1,168 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Microsoft.TypeSpec.Generator;
+using Microsoft.TypeSpec.Generator.Primitives;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Azure.Generator.Primitives
+{
+ ///
+ /// Defines the new project scaffolding needed for an azure sdk.
+ ///
+ public class NewAzureProjectScaffolding : NewProjectScaffolding
+ {
+ private const string MSBuildThisFileDirectory = "$(MSBuildThisFileDirectory)";
+ private const string RelativeCoreSegment = "sdk/core/Azure.Core/src/Shared/";
+ private const string ParentDirectory = "../";
+
+ ///
+ 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}",
+ Version = "1.0.0-beta.1",
+ PackageTags = AzureClientPlugin.Instance.TypeFactory.RootNamespace,
+ GenerateDocumentationFile = true,
+ };
+
+ foreach (var packages in _azureDependencyPackages)
+ {
+ builder.PackageReferences.Add(packages);
+ }
+
+ int pathSegmentCount = GetPathSegmentCount();
+ if (AzureClientPlugin.Instance.InputLibrary.InputNamespace.Auth.ApiKey is not null)
+ {
+ builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("AzureKeyCredentialPolicy.cs", pathSegmentCount), "Shared/Core"));
+ }
+
+ TraverseInput(out bool hasOperation, out bool hasLongRunningOperation);
+ if (hasOperation)
+ {
+ builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude("RawRequestUriBuilder.cs", pathSegmentCount), "Shared/Core"));
+ }
+
+ if (hasLongRunningOperation)
+ {
+ foreach (var file in _lroSharedFiles)
+ {
+ builder.CompileIncludes.Add(new CSharpProjectWriter.CSProjCompileInclude(GetCompileInclude(file, pathSegmentCount), "Shared/Core"));
+ }
+ }
+
+ return builder.Write();
+ }
+
+ private static readonly IReadOnlyList _lroSharedFiles =
+ [
+ "AppContextSwitchHelper.cs",
+ "AsyncLockWithValue.cs",
+ "FixedDelayWithNoJitterStrategy.cs",
+ "ClientDiagnostics.cs",
+ "DiagnosticScopeFactory.cs",
+ "DiagnosticScope.cs",
+ "HttpMessageSanitizer.cs",
+ "IOperationSource.cs",
+ "NextLinkOperationImplementation.cs",
+ "OperationFinalStateVia.cs",
+ "OperationInternal.cs",
+ "OperationInternalBase.cs",
+ "OperationInternalOfT.cs",
+ "OperationPoller.cs",
+ "SequentialDelayStrategy.cs",
+ "TaskExtensions.cs",
+ "TrimmingAttribute.cs",
+ "VoidValue.cs"
+ ];
+
+ private static void TraverseInput(out bool hasOperation, out bool hasLongRunningOperation)
+ {
+ hasOperation = false;
+ hasLongRunningOperation = false;
+ foreach (var inputClient in AzureClientPlugin.Instance.InputLibrary.InputNamespace.Clients)
+ {
+ foreach (var operation in inputClient.Operations)
+ {
+ hasOperation = true;
+ if (operation.LongRunning != null)
+ {
+ hasLongRunningOperation = true;
+ return;
+ }
+ }
+ }
+ }
+
+ private static int GetPathSegmentCount()
+ {
+ ReadOnlySpan text = AzureClientPlugin.Instance.Configuration.OutputDirectory.AsSpan();
+ // we are either a spector project in the eng folder or a real sdk in the sdk folder
+ int beginning = text.IndexOf("eng");
+ if (beginning == -1)
+ {
+ beginning = text.IndexOf("sdk");
+ }
+ text = text.Slice(beginning);
+ // starting with 2 to include eng at the beginning and src at the end
+ int pathSegmentCount = 2 + text.Count('/');
+ // count both path separators to normalize
+ pathSegmentCount += text.Count('\\');
+ return pathSegmentCount;
+ }
+
+ private string GetCompileInclude(string fileName, int pathSegmentCount)
+ {
+ return $"{MSBuildThisFileDirectory}{string.Concat(Enumerable.Repeat(ParentDirectory, pathSegmentCount))}{RelativeCoreSegment}{fileName}";
+ }
+
+ private static readonly IReadOnlyList _azureDependencyPackages =
+ AzureClientPlugin.Instance.IsAzureArm.Value == true
+ ? [
+ new("Azure.Core"),
+ new("Azure.ResourceManager"),
+ new("System.ClientModel"),
+ new("System.Text.Json")
+ ]
+ : [
+ new("Azure.Core"),
+ new("System.ClientModel"),
+ new("System.Text.Json")
+ ];
+
+ ///
+ protected override string GetSolutionFileContent()
+ {
+ string slnContent = @"Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35201.131
+MinimumVisualStudioVersion = 10.0.40219.1
+Project(""{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}"") = ""{0}"", ""src\{0}.csproj"", ""{{28FF4005-4467-4E36-92E7-DEA27DEB1519}}""
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {{28FF4005-4467-4E36-92E7-DEA27DEB1519}}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {{A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}}
+ EndGlobalSection
+EndGlobal
+";
+ return string.Format(slnContent, AzureClientPlugin.Instance.TypeFactory.RootNamespace);
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json
index d2eb974d8e2f..1fd60a55a7a8 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json
@@ -1,9 +1,149 @@
-{
+{
"profiles": {
"Basic-TypeSpec": {
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Local/Basic-TypeSpec -p AzureClientPlugin",
"commandName": "Executable",
"executablePath": "dotnet"
+ },
+ "http-authentication-api-key": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/authentication/api-key -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-authentication-http-custom": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/authentication/http/custom -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-authentication-oauth2": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/authentication/oauth2 -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-authentication-union": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/authentication/union -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-client-structure-default": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/client/structure/default -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-encode-numeric": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/encode/numeric -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-parameters-basic": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/parameters/basic -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-parameters-body-optionality": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/parameters/body-optionality -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-parameters-spread": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/parameters/spread -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-payload-content-negotiation": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/payload/content-negotiation -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-payload-json-merge-patch": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/payload/json-merge-patch -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-payload-media-type": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/payload/media-type -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-serialization-encoded-name-json": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/serialization/encoded-name/json -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-server-endpoint-not-defined": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/server/endpoint/not-defined -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-server-path-single": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/server/path/single -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-server-versions-not-versioned": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/server/versions/not-versioned -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-special-headers-conditional-request": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/special-headers/conditional-request -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-special-headers-repeatability": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/special-headers/repeatability -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-special-words": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/special-words -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-enum-fixed": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/enum/fixed -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-empty": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/empty -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-inheritance-nested-discriminator": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/inheritance/nested-discriminator -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-inheritance-not-discriminated": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/inheritance/not-discriminated -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-inheritance-recursive": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/inheritance/recursive -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-inheritance-single-discriminator": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/inheritance/single-discriminator -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-usage": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/usage -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-model-visibility": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/model/visibility -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
+ },
+ "http-type-property-nullable": {
+ "commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.dll $(SolutionDir)/TestProjects/Spector/http/type/property/nullable -p AzureStubPlugin",
+ "commandName": "Executable",
+ "executablePath": "dotnet"
}
}
}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureClientResponseProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureClientResponseProvider.cs
index a47851a04548..1b874baefa79 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureClientResponseProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureClientResponseProvider.cs
@@ -1,11 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Snippets;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Snippets;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureResponseProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureResponseProvider.cs
index 11517a6a7f2e..06e5ce1ea362 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureResponseProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/AzureResponseProvider.cs
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Snippets;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Snippets;
using System;
using System.IO;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpMessageProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpMessageProvider.cs
index c8113b69c484..a8693ad164a8 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpMessageProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpMessageProvider.cs
@@ -2,11 +2,10 @@
// Licensed under the MIT License.
using Azure.Core;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Statements;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Statements;
namespace Azure.Generator.Providers
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpPipelineProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpPipelineProvider.cs
index 6894d95402cb..aa6fe8374432 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpPipelineProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpPipelineProvider.cs
@@ -3,14 +3,14 @@
using Azure.Core;
using Azure.Core.Pipeline;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Providers;
-using Microsoft.Generator.CSharp.Snippets;
-using Microsoft.Generator.CSharp.Statements;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.Snippets;
+using Microsoft.TypeSpec.Generator.Statements;
using System.Threading;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers.Abstraction
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestOptionsProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestOptionsProvider.cs
index 5a1240531892..63505af515a7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestOptionsProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestOptionsProvider.cs
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers.Abstraction
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestProvider.cs
index b09ce221e158..2d2142d636fc 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/HttpRequestProvider.cs
@@ -2,13 +2,13 @@
// Licensed under the MIT License.
using Azure.Core;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Statements;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Statements;
using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/RequestContentProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/RequestContentProvider.cs
index 8fbd2922aeda..0b37ebe3bf85 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/RequestContentProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/RequestContentProvider.cs
@@ -2,13 +2,13 @@
// Licensed under the MIT License.
using Azure.Core;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Snippets;
-using Microsoft.Generator.CSharp.Statements;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Snippets;
+using Microsoft.TypeSpec.Generator.Statements;
using System.ClientModel.Primitives;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/StatusCodeClassifierProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/StatusCodeClassifierProvider.cs
index 1fd171a0514b..1294f205bf1a 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/StatusCodeClassifierProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/Abstraction/StatusCodeClassifierProvider.cs
@@ -2,12 +2,12 @@
// Licensed under the MIT License.
using Azure.Core;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
using System.Collections.Generic;
using System.Linq;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers.Abstraction
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/MgmtLongRunningOperationProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/MgmtLongRunningOperationProvider.cs
new file mode 100644
index 000000000000..9082319badf7
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/MgmtLongRunningOperationProvider.cs
@@ -0,0 +1,234 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Azure.Core;
+using Azure.Core.Pipeline;
+using Azure.Generator.Utilities;
+using Azure.ResourceManager;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.Statements;
+using System;
+using System.ClientModel.Primitives;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading.Tasks;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
+
+namespace Azure.Generator.Providers
+{
+ internal class MgmtLongRunningOperationProvider : TypeProvider
+ {
+ private class Template { }
+ private readonly CSharpType _t = typeof(Template<>).GetGenericArguments()[0];
+
+ private bool _isGeneric;
+ private FieldProvider _operationField;
+ private FieldProvider _rehydrationTokenField;
+ private FieldProvider _nextLinkOperationField;
+ private FieldProvider _operationIdField;
+
+ public MgmtLongRunningOperationProvider(bool isGeneric)
+ {
+ _isGeneric = isGeneric;
+ _operationField = new FieldProvider(FieldModifiers.Private | FieldModifiers.ReadOnly, isGeneric ? new CSharpType(typeof(OperationInternal<>), _t) : typeof(OperationInternal), "_operation", this);
+ _rehydrationTokenField = new FieldProvider(FieldModifiers.Private | FieldModifiers.ReadOnly, new CSharpType(typeof(RehydrationToken), true), "_completeRehydrationToken", this);
+ _nextLinkOperationField = new FieldProvider(FieldModifiers.Private | FieldModifiers.ReadOnly, new CSharpType(typeof(NextLinkOperationImplementation), true), "_nextLinkOperation", this);
+ _operationIdField = new FieldProvider(FieldModifiers.Private | FieldModifiers.ReadOnly, typeof(string), "_operationId", this);
+ }
+
+ private readonly string _serviceName = AzureClientPlugin.Instance.InputLibrary.InputNamespace.Name.Split('.').Last();
+ protected override string BuildName() => $"{_serviceName}ArmOperation";
+
+ protected override CSharpType[] GetTypeArguments() => _isGeneric ? new CSharpType[] { _t } : base.GetTypeArguments();
+
+ protected override string BuildRelativeFilePath()
+ {
+ return Path.Combine("src", "Generated", "LongRunningOperation", GetFileName());
+
+ string GetFileName() => _isGeneric ? $"{_serviceName}ArmOperationOfT.cs" : $"{Name}.cs";
+ }
+
+ protected override CSharpType[] BuildImplements() => [_isGeneric ? new CSharpType(typeof(ArmOperation<>), _t) : typeof(ArmOperation)];
+
+ protected override FieldProvider[] BuildFields()
+ => [_operationField, _rehydrationTokenField, _nextLinkOperationField, _operationIdField];
+
+ protected override MethodProvider[] BuildMethods()
+ {
+ var getRehydrationTokenMethod = new MethodProvider(
+ new MethodSignature("GetRehydrationToken", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(RehydrationToken), true), null, []),
+ _nextLinkOperationField.NullConditional().Invoke(nameof(NextLinkOperationImplementation.GetRehydrationToken)).NullCoalesce(_rehydrationTokenField),
+ this, XmlDocProvider.InheritDocs);
+
+ var getRawResponseMethod = new MethodProvider(
+ new MethodSignature("GetRawResponse", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(Response), null, []),
+ _operationField.Property("RawResponse"),
+ this, XmlDocProvider.InheritDocs);
+
+ var updateStatusMethod = new MethodProvider(
+ new MethodSignature("UpdateStatus", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(Response), null, [KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("UpdateStatus", [KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs);
+
+ var updateStatusAsyncMethod = new MethodProvider(
+ new MethodSignature("UpdateStatusAsync", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(ValueTask<>), typeof(Response)), null, [KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("UpdateStatusAsync", [KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs);
+
+ var waitForCompletionResponseMethod = _isGeneric
+ ? new MethodProvider(
+ new MethodSignature("WaitForCompletion", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(Response<>), _t), null, [KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletion", [KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs)
+ : new MethodProvider(
+ new MethodSignature("WaitForCompletionResponse", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(Response), null, [KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletionResponse", [KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs);
+
+ var timeSpanParameter = new ParameterProvider("pollingInterval", $"The interval between pollings", typeof(TimeSpan));
+ var waitForCompletionResponseWithPolingMethod = _isGeneric
+ ? new MethodProvider(
+ new MethodSignature("WaitForCompletion", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(Response<>), _t), null, [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletion", [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs)
+ : new MethodProvider(
+ new MethodSignature("WaitForCompletionResponse", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(Response), null, [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletionResponse", [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs);
+
+ var waitForCompletionResponseAsyncMethod = _isGeneric
+ ? new MethodProvider(
+ new MethodSignature("WaitForCompletionAsync", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(ValueTask<>), new CSharpType(typeof(Response<>), _t)), null, [KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletionAsync", [KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs)
+ : new MethodProvider(
+ new MethodSignature("WaitForCompletionResponseAsync", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(ValueTask<>), typeof(Response)), null, [KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletionResponseAsync", [KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs);
+
+ var waitForCompletionResponseWithPollingAsyncMethod = _isGeneric
+ ? new MethodProvider(
+ new MethodSignature("WaitForCompletionAsync", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(ValueTask<>), new CSharpType(typeof(Response<>), _t)), null, [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletionAsync", [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs)
+ : new MethodProvider(
+ new MethodSignature("WaitForCompletionResponseAsync", null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, new CSharpType(typeof(ValueTask<>), typeof(Response)), null, [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ _operationField.Invoke("WaitForCompletionResponseAsync", [timeSpanParameter, KnownParameters.CancellationTokenParameter]),
+ this, XmlDocProvider.InheritDocs);
+
+ return [BuildGetOperationIdMethod(), getRehydrationTokenMethod, getRawResponseMethod, updateStatusMethod, updateStatusAsyncMethod, waitForCompletionResponseMethod, waitForCompletionResponseWithPolingMethod, waitForCompletionResponseAsyncMethod, waitForCompletionResponseWithPollingAsyncMethod];
+ }
+
+ private const string GetOperationIdName = "GetOperationId";
+ private MethodProvider BuildGetOperationIdMethod()
+ {
+ var rehydrationTokenParaemter = new ParameterProvider("rehydrationToken", $"The token to rehydrate a long-running operation", new CSharpType(typeof(RehydrationToken), true));
+ var signature = new MethodSignature(GetOperationIdName, null, MethodSignatureModifiers.Private, typeof(string), null, [rehydrationTokenParaemter]);
+ var body = new MethodBodyStatement[]
+ {
+ new IfStatement(rehydrationTokenParaemter.Is(Null))
+ {
+ Return(Null)
+ },
+ Declare("lroDetails", typeof(Dictionary), Static(typeof(ModelReaderWriter)).Invoke("Write", [rehydrationTokenParaemter, Static(typeof(ModelReaderWriterOptions)).Property("Json")]).Invoke("ToObjectFromJson", [], new List{ typeof(Dictionary) }, false), out var lroDetailsVariable),
+ Return(new IndexerExpression(lroDetailsVariable, Literal("id")))
+ };
+ return new MethodProvider(signature, body, this);
+ }
+
+ protected override ConstructorProvider[] BuildConstructors()
+ => [ConstructorProviderHelper.BuildMockingConstructor(this), BuildRehydrationConstructor(), BuildInitializationConstructor()];
+
+ private ConstructorProvider BuildInitializationConstructor()
+ {
+ var sourceParameter = new ParameterProvider("source", $"The instance of ", new CSharpType(typeof(IOperationSource<>), _t));
+ var clientDiagnosticsParameter = new ParameterProvider("clientDiagnostics", $"The instance of ", typeof(ClientDiagnostics));
+ var pipelineParameter = new ParameterProvider("pipeline", $"The instance of ", typeof(HttpPipeline));
+ var requestParameter = new ParameterProvider("request", $"The operation request", typeof(Request));
+ var responseParameter = new ParameterProvider("response", $"The opertion response", typeof(Response));
+ var finalStateViaParameter = new ParameterProvider("finalStateVia", $"The finalStateVia of the operation", typeof(OperationFinalStateVia));
+ var skipApiVersionOverrideParameter = new ParameterProvider("skipApiVersionOverride", $"If should skip Api version override", typeof(bool), defaultValue: Literal(false));
+ var apiVersionOverrideValueParameter = new ParameterProvider("apiVersionOverrideValue", $"The Api version override value", typeof(string), defaultValue: Null);
+ var parameters = _isGeneric
+ ? new List
+ {
+ sourceParameter,
+ clientDiagnosticsParameter,
+ pipelineParameter,
+ requestParameter,
+ responseParameter,
+ finalStateViaParameter,
+ skipApiVersionOverrideParameter,
+ apiVersionOverrideValueParameter,
+ }
+ : new List
+ {
+ clientDiagnosticsParameter,
+ pipelineParameter,
+ requestParameter,
+ responseParameter,
+ finalStateViaParameter,
+ skipApiVersionOverrideParameter,
+ apiVersionOverrideValueParameter,
+ };
+ var signature = new ConstructorSignature(Type, $"", MethodSignatureModifiers.Internal, parameters, null);
+ var responseDeclaration = Declare("nextLinkOperation", typeof(IOperation), Static(typeof(NextLinkOperationImplementation)).Invoke("Create", [pipelineParameter, requestParameter.Property("Method"), requestParameter.Property("Uri").Invoke("ToUri"), responseParameter, finalStateViaParameter, skipApiVersionOverrideParameter, apiVersionOverrideValueParameter]), out var nextLinkOperationVariable);
+
+ var body = new MethodBodyStatement[]
+ {
+ responseDeclaration,
+ new IfElseStatement(
+ nextLinkOperationVariable.Is(Declare("nextLinkOperationImplementation", out var nextLinkOperationImplementationVariable)),
+ new MethodBodyStatements([
+ _nextLinkOperationField.Assign(nextLinkOperationImplementationVariable).Terminate(),
+ _operationIdField.Assign(_nextLinkOperationField.Property("OperationId")).Terminate(),
+ ]),
+ new MethodBodyStatements([
+ _rehydrationTokenField.Assign(Static(typeof(NextLinkOperationImplementation)).Invoke("GetRehydrationToken", [requestParameter.Property("Method"), requestParameter.Property("Uri").Invoke("ToUri"), responseParameter, finalStateViaParameter])).Terminate(),
+ _operationIdField.Assign(This.Invoke(GetOperationIdName, _rehydrationTokenField)).Terminate(),
+ ])),
+ _operationField.Assign(_isGeneric
+ ? New.Instance(new CSharpType(typeof(OperationInternal<>), _t), [Static().Invoke("Create", sourceParameter, nextLinkOperationVariable), clientDiagnosticsParameter, responseParameter, Literal(Name), Null, New.Instance(typeof(SequentialDelayStrategy))])
+ : New.Instance(typeof(OperationInternal), [nextLinkOperationVariable, clientDiagnosticsParameter, responseParameter, Literal(Name), Null, New.Instance(typeof(SequentialDelayStrategy))])).Terminate(),
+ };
+ return new ConstructorProvider(signature, body, this);
+ }
+
+ private ConstructorProvider BuildRehydrationConstructor()
+ {
+ var responseParameter = new ParameterProvider("response", $"The operation response", _isGeneric ? new CSharpType(typeof(Response<>), _t) : typeof(Response));
+ var rehydrationTokenParameter = new ParameterProvider("rehydrationToken", $"The token to rehydrate the operation", new CSharpType(typeof(RehydrationToken), true), Null);
+ var signature = new ConstructorSignature(Type, $"", MethodSignatureModifiers.Internal, [responseParameter, rehydrationTokenParameter], null);
+ var body = new MethodBodyStatement[]
+ {
+ _operationField.Assign(_isGeneric
+ ? Static(new CSharpType(typeof(OperationInternal<>), _t)).Invoke(nameof(OperationInternal.Succeeded), [responseParameter.Invoke("GetRawResponse"), responseParameter.Property("Value")])
+ : Static(typeof(OperationInternal)).Invoke(nameof(OperationInternal.Succeeded), [responseParameter])
+ ).Terminate(),
+ _rehydrationTokenField.Assign(rehydrationTokenParameter).Terminate(),
+ _operationIdField.Assign(This.Invoke(GetOperationIdName, rehydrationTokenParameter)).Terminate(),
+ };
+ return new ConstructorProvider(signature, body, this);
+ }
+
+ protected override PropertyProvider[] BuildProperties()
+ {
+ var idProperty = new PropertyProvider(null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(string), "Id", new ExpressionPropertyBody(_operationIdField.NullCoalesce(Static().Property(nameof(NextLinkOperationImplementation.NotSet)))), this);
+ var hasCompletedProperty = new PropertyProvider(null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(bool), "HasCompleted", new ExpressionPropertyBody(_operationField.Property("HasCompleted")), this);
+
+ if (_isGeneric)
+ {
+ var valueProperty = new PropertyProvider(null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, _t, "Value", new ExpressionPropertyBody(_operationField.Property("Value")), this);
+ var hasValueProperty = new PropertyProvider(null, MethodSignatureModifiers.Public | MethodSignatureModifiers.Override, typeof(bool), "HasValue", new ExpressionPropertyBody(_operationField.Property("HasValue")), this);
+ return [idProperty, valueProperty, hasValueProperty, hasCompletedProperty];
+ }
+
+ return [idProperty, hasCompletedProperty];
+ }
+
+ protected override TypeSignatureModifiers BuildDeclarationModifiers() => TypeSignatureModifiers.Internal;
+ }
+}
\ No newline at end of file
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/RequestContextExtensionsDefinition.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/RequestContextExtensionsDefinition.cs
index 9b34571045dc..9dc9c6b6526d 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/RequestContextExtensionsDefinition.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/RequestContextExtensionsDefinition.cs
@@ -1,14 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Providers;
-using Microsoft.Generator.CSharp.Snippets;
-using Microsoft.Generator.CSharp.Statements;
+using Microsoft.TypeSpec.Generator.Expressions;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.Statements;
using System.IO;
using System.Threading;
-using static Microsoft.Generator.CSharp.Snippets.Snippet;
+using static Microsoft.TypeSpec.Generator.Snippets.Snippet;
namespace Azure.Generator.Providers
{
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataProvider.cs
index 6fdd890e490e..451689bebe0d 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataProvider.cs
@@ -1,8 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Providers;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Providers;
using System.IO;
namespace Azure.Generator.Providers
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataSerializationProvider.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataSerializationProvider.cs
index 6b415610dcbe..e2a7993997e7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataSerializationProvider.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Providers/ResourceDataSerializationProvider.cs
@@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Providers;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Providers;
using System.IO;
namespace Azure.Generator.Providers
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/RestClientVisitor.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/RestClientVisitor.cs
new file mode 100644
index 000000000000..c7b44c825670
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/RestClientVisitor.cs
@@ -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.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using System.IO;
+
+namespace Azure.Generator
+{
+ // only apply for MPG
+ internal class RestClientVisitor : ScmLibraryVisitor
+ {
+ ///
+ protected override TypeProvider? Visit(TypeProvider type)
+ {
+ base.Visit(type);
+
+ if (type is ClientProvider)
+ {
+ type.Update(modifiers: TransfromPublicModifiersToInternal(type), relativeFilePath: TransformRelativeFilePathForClient(type));
+ }
+ // TODO: uncomment this once resources are generated
+ //if (type is RestClientProvider)
+ //{
+ // type.Update(modifiers: TransfromPublicModifiersToInternal(type), relativeFilePath: TransformRelativeFilePathForRestClient(type));
+ //}
+ return type;
+ }
+
+ private static string TransformRelativeFilePathForClient(TypeProvider type)
+ => Path.Combine("src", "Generated", "RestOperations", $"{type.Name}RestOperations.cs");
+
+ private static string TransformRelativeFilePathForRestClient(TypeProvider type)
+ => Path.Combine("src", "Generated", "RestOperations", $"{type.Name}.RestClient.cs");
+
+ private static TypeSignatureModifiers TransfromPublicModifiersToInternal(TypeProvider type)
+ {
+ var modifiers = type.DeclarationModifiers;
+ if (modifiers.HasFlag(TypeSignatureModifiers.Public))
+ {
+ modifiers &= ~TypeSignatureModifiers.Public;
+ modifiers |= TypeSignatureModifiers.Internal;
+ }
+
+ return modifiers;
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ConstructorProviderHelper.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ConstructorProviderHelper.cs
new file mode 100644
index 000000000000..d93c8c0060df
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ConstructorProviderHelper.cs
@@ -0,0 +1,24 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.Statements;
+
+namespace Azure.Generator.Utilities
+{
+ internal static class ConstructorProviderHelper
+ {
+ ///
+ /// Builds a constructor for the enclosing type for mocking purposes.
+ ///
+ /// The type provider to build the constructor for.
+ public static ConstructorProvider BuildMockingConstructor(TypeProvider enclosingType)
+ {
+ return new ConstructorProvider(
+ new ConstructorSignature(enclosingType.Type, $"Initializes a new instance of {enclosingType.Name} for mocking.", MethodSignatureModifiers.Protected, []),
+ new MethodBodyStatement[] { MethodBodyStatement.Empty },
+ enclosingType);
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/InputExtensions.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/InputExtensions.cs
index 1a43d1e0af4b..7a77b71592be 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/InputExtensions.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/InputExtensions.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator.Input;
using System.Collections.Generic;
using System.Linq;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/OperationExtensions.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/OperationExtensions.cs
index 12f1b72ee315..8553556a2576 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/OperationExtensions.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/OperationExtensions.cs
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator.Input;
using System;
using System.Linq;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ResourceDetection.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ResourceDetection.cs
index c99ea619555d..0a956705fde3 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ResourceDetection.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/src/Utilities/ResourceDetection.cs
@@ -3,7 +3,7 @@
using Azure.Core;
using Azure.Generator.Mgmt.Models;
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator.Input;
using System;
using System.Collections.Concurrent;
using System.Diagnostics.CodeAnalysis;
@@ -99,7 +99,6 @@ private bool TryOperationWithMethod(OperationSet set, RequestMethod method, [May
return true;
}
-
private static bool IsResourceModel(InputModelType inputModelType)
{
var allProperties = inputModelType.GetAllProperties();
@@ -114,7 +113,10 @@ private static bool IsResourceModel(InputModelType inputModelType)
return true;
}
- switch (property.SerializedName)
+ var serializationName = property.SerializationOptions?.Json?.Name;
+ if (serializationName is null)
+ continue;
+ switch (serializationName)
{
case "id":
if (property.Type.GetImplementType() is InputPrimitiveType { Kind: InputPrimitiveTypeKind.String } inputPrimitiveType)
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Azure.Generator.Tests.csproj b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Azure.Generator.Tests.csproj
index c837d9c3531e..b61e487a47da 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Azure.Generator.Tests.csproj
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Azure.Generator.Tests.csproj
@@ -1,32 +1,33 @@
-
- net8.0
+
+ net8.0
latest
-
- CS8002
-
+
+ CS8002
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
- PreserveNewest
-
-
+
+
+ PreserveNewest
+
+
-
-
-
+
+
+
-
-
- PreserveNewest
-
-
-
+
+
+ PreserveNewest
+
+
+
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/AzureTypeFactoryTests.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/AzureTypeFactoryTests.cs
index a1891afa3f61..d2868007023e 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/AzureTypeFactoryTests.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/AzureTypeFactoryTests.cs
@@ -4,14 +4,11 @@
using Azure.Core;
using Azure.Generator.Tests.Common;
using Azure.Generator.Tests.TestHelpers;
-using Microsoft.Generator.CSharp.Expressions;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Providers;
-using Microsoft.Generator.CSharp.Snippets;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.Snippets;
using NUnit.Framework;
using System;
-using System.Buffers;
using System.ClientModel.Primitives;
using System.Net;
using System.Text.Json;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/Helpers.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/Helpers.cs
index 942a4e483bc0..47348ac96aaa 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/Helpers.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/Helpers.cs
@@ -23,7 +23,6 @@ private static string GetAssetFileOrDirectoryPath(
[CallerMemberName] string method = "",
[CallerFilePath] string filePath = "")
{
-
var callingClass = Path.GetFileName(filePath).Split('.').First();
var paramString = parameters is null ? string.Empty : $"({parameters})";
var extName = isFile ? ".cs" : string.Empty;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/InputFactory.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/InputFactory.cs
index 06626d67fea9..e4a4a355b9e4 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/InputFactory.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Common/InputFactory.cs
@@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Linq;
-using Microsoft.Generator.CSharp.Input;
+using Microsoft.TypeSpec.Generator.Input;
namespace Azure.Generator.Tests.Common
{
@@ -121,10 +121,12 @@ public static InputEnumType Enum(
string access = "public",
InputModelTypeUsage usage = InputModelTypeUsage.Output | InputModelTypeUsage.Input,
IEnumerable? values = null,
- bool isExtensible = false)
+ bool isExtensible = false,
+ string clientNamespace = "Sample.Models")
{
return new InputEnumType(
name,
+ clientNamespace,
name,
access,
null,
@@ -148,17 +150,18 @@ public static InputModelProperty Property(
{
return new InputModelProperty(
name,
- wireName ?? name,
summary,
description ?? $"Description for {name}",
type,
isRequired,
isReadOnly,
- isDiscriminator);
+ isDiscriminator,
+ new(json: new(wireName ?? name)));
}
public static InputModelType Model(
string name,
+ string clientNamespace = "Sample.Models",
string access = "public",
InputModelTypeUsage usage = InputModelTypeUsage.Output | InputModelTypeUsage.Input | InputModelTypeUsage.Json,
IEnumerable? properties = null,
@@ -172,6 +175,7 @@ public static InputModelType Model(
IEnumerable propertiesList = properties ?? [Property("StringProperty", InputPrimitiveType.String)];
return new InputModelType(
name,
+ clientNamespace,
name,
access,
null,
@@ -185,7 +189,8 @@ public static InputModelType Model(
propertiesList.FirstOrDefault(p => p.IsDiscriminator),
discriminatedModels is null ? new Dictionary() : discriminatedModels.AsReadOnly(),
additionalProperties,
- modelAsStruct);
+ modelAsStruct,
+ new());
}
public static InputType Array(InputType elementType)
@@ -244,12 +249,13 @@ public static OperationResponse OperationResponse(IEnumerable? statusCodes
["application/json"]);
}
- public static InputClient Client(string name, IEnumerable? operations = null, IEnumerable? parameters = null, string? parent = null)
+ public static InputClient Client(string name, string clientNamespace = "Sample", string? doc = null, IEnumerable? operations = null, IEnumerable? parameters = null, string? parent = null)
{
return new InputClient(
name,
- null,
- $"{name} description",
+ clientNamespace,
+ string.Empty,
+ doc ?? $"{name} description",
operations is null ? [] : [.. operations],
parameters is null ? [] : [.. parameters],
parent);
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/Abstractions/AzureClientResponseProviderTests.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/Abstractions/AzureClientResponseProviderTests.cs
index 47e8a0bf90ee..9bb94fe56ad2 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/Abstractions/AzureClientResponseProviderTests.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/Abstractions/AzureClientResponseProviderTests.cs
@@ -3,10 +3,10 @@
using Azure.Generator.Tests.Common;
using Azure.Generator.Tests.TestHelpers;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
using System.Linq;
using NUnit.Framework;
using Azure.Generator.Providers;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
namespace Azure.Generator.Tests.Providers.Abstractions
{
@@ -49,7 +49,7 @@ public void ValidateClientResponseExceptionTypeIsOverridden()
private static ClientProvider CreateMockClientProvider()
{
- var client = InputFactory.Client("TestClient", [InputFactory.Operation("foo")]);
+ var client = InputFactory.Client("TestClient", operations: [InputFactory.Operation("foo")]);
MockHelpers.LoadMockPlugin(clientResponseApi: AzureClientResponseProvider.Instance);
var clientProvider = AzureClientPlugin.Instance.TypeFactory.CreateClient(client)!;
return clientProvider;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ClientProviderTests.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ClientProviderTests.cs
index 8254f232db7b..f0cac25c0cc7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ClientProviderTests.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ClientProviderTests.cs
@@ -1,10 +1,13 @@
-using Azure.Core;
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Azure.Core;
using Azure.Generator.Tests.Common;
using Azure.Generator.Tests.TestHelpers;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Providers;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
using NUnit.Framework;
using System;
using System.Collections.Generic;
@@ -19,9 +22,9 @@ internal class ClientProviderTests
private const string KeyAuthCategory = "WithKeyAuth";
private const string OAuth2Category = "WithOAuth2";
private const string TestClientName = "TestClient";
- private static readonly InputClient _animalClient = new("animal", null, "AnimalClient description", [], [], TestClientName);
- private static readonly InputClient _dogClient = new("dog", null, "DogClient description", [], [], _animalClient.Name);
- private static readonly InputClient _huskyClient = new("husky", null, "HuskyClient description", [], [], _dogClient.Name);
+ private static readonly InputClient _animalClient = new("animal", "Samples", "AnimalClient description", null, [], [], TestClientName);
+ private static readonly InputClient _dogClient = new("dog", "Samples", "DogClient description", null, [], [], _animalClient.Name);
+ private static readonly InputClient _huskyClient = new("husky", "Samples", "HuskyClient description", null, [], [], _dogClient.Name);
private bool _containsSubClients;
private bool _hasKeyAuth;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/MgmtLongRunningOperationProviderTests.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/MgmtLongRunningOperationProviderTests.cs
new file mode 100644
index 000000000000..a6e0e6ab332d
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/MgmtLongRunningOperationProviderTests.cs
@@ -0,0 +1,44 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Azure.Generator.Providers;
+using Azure.Generator.Tests.Common;
+using Azure.Generator.Tests.TestHelpers;
+using Microsoft.TypeSpec.Generator.Primitives;
+using NUnit.Framework;
+
+namespace Azure.Generator.Tests.Providers
+{
+ internal class MgmtLongRunningOperationProviderTests
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ MockHelpers.LoadMockPlugin();
+ }
+
+ [TestCase]
+ public void Verify_NonGeneric_MgmtLROProviderGeneration()
+ {
+ var nonGenericLROProvider = new MgmtLongRunningOperationProvider(false);
+ var codeFile = new TypeProviderWriter(nonGenericLROProvider).Write();
+ var result = codeFile.Content;
+
+ var exptected = Helpers.GetExpectedFromFile();
+
+ Assert.AreEqual(exptected, result);
+ }
+
+ [TestCase]
+ public void Verify_Generic_MgmtLROProviderGeneration()
+ {
+ var genericLROProvider = new MgmtLongRunningOperationProvider(true);
+ var codeFile = new TypeProviderWriter(genericLROProvider).Write();
+ var result = codeFile.Content;
+
+ var exptected = Helpers.GetExpectedFromFile();
+
+ Assert.AreEqual(exptected, result);
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ResourceDataProviderTests.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ResourceDataProviderTests.cs
index 8f826276b3c2..fc129892454c 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ResourceDataProviderTests.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/ResourceDataProviderTests.cs
@@ -1,8 +1,11 @@
-using Azure.Generator.Providers;
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+using Azure.Generator.Providers;
using Azure.Generator.Tests.Common;
using Azure.Generator.Tests.TestHelpers;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Providers;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Providers;
using NUnit.Framework;
using System.Linq;
@@ -12,7 +15,7 @@ internal class ResourceDataProviderTests
{
private const string TestClientName = "TestClient";
- [TestCase()]
+ [TestCase]
public void ValidateResourceDataProviderIsGenerated()
{
var resourceModelName = "responseType";
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,False,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,False,0).cs
index 5aec0d8cb783..d0a1a7addb6c 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,False,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,False,0).cs
@@ -1,6 +1,6 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
Pipeline = global::Azure.Core.Pipeline.HttpPipelineBuilder.Build(options, Array.Empty());
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,True,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,True,0).cs
index f9be93c9763e..822997991bc9 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,True,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,False,True,0).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_tokenCredential = tokenCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,False,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,False,0).cs
index ccf0e0c75201..53e13d59b2c7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,False,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,False,0).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_keyCredential = keyCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,0).cs
index ccf0e0c75201..53e13d59b2c7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,0).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_keyCredential = keyCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,1).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,1).cs
index f9be93c9763e..822997991bc9 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,1).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithDefault,True,True,1).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_tokenCredential = tokenCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,False,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,False,0).cs
index 5aec0d8cb783..d0a1a7addb6c 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,False,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,False,0).cs
@@ -1,6 +1,6 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
Pipeline = global::Azure.Core.Pipeline.HttpPipelineBuilder.Build(options, Array.Empty());
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,True,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,True,0).cs
index f9be93c9763e..822997991bc9 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,True,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,False,True,0).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_tokenCredential = tokenCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,False,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,False,0).cs
index ccf0e0c75201..53e13d59b2c7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,False,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,False,0).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_keyCredential = keyCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,0).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,0).cs
index ccf0e0c75201..53e13d59b2c7 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,0).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,0).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(keyCredential, nameof(keyCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_keyCredential = keyCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,1).cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,1).cs
index f9be93c9763e..822997991bc9 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,1).cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/ClientProviderTests/TestBuildConstructors_PrimaryConstructor(WithRequired,True,True,1).cs
@@ -1,7 +1,7 @@
-global::sample.namespace.Argument.AssertNotNull(endpoint, nameof(endpoint));
-global::sample.namespace.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
+global::Samples.Argument.AssertNotNull(endpoint, nameof(endpoint));
+global::Samples.Argument.AssertNotNull(tokenCredential, nameof(tokenCredential));
-options ??= new global::sample.namespace.TestClientOptions();
+options ??= new global::Samples.TestClientOptions();
_endpoint = endpoint;
_tokenCredential = tokenCredential;
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/MgmtLongRunningOperationProviderTests/Verify_Generic_MgmtLROProviderGeneration.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/MgmtLongRunningOperationProviderTests/Verify_Generic_MgmtLROProviderGeneration.cs
new file mode 100644
index 000000000000..163ff18cade1
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/MgmtLongRunningOperationProviderTests/Verify_Generic_MgmtLROProviderGeneration.cs
@@ -0,0 +1,106 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ClientModel.Primitives;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.Core;
+using Azure.Core.Pipeline;
+using Azure.ResourceManager;
+
+namespace Samples
+{
+ internal partial class SamplesArmOperation : global::Azure.ResourceManager.ArmOperation
+ {
+ private readonly global::Azure.Core.OperationInternal _operation;
+ private readonly global::Azure.Core.RehydrationToken? _completeRehydrationToken;
+ private readonly global::Azure.Core.NextLinkOperationImplementation _nextLinkOperation;
+ private readonly string _operationId;
+
+ protected SamplesArmOperation()
+ {
+ }
+
+ internal SamplesArmOperation(global::Azure.Response response, global::Azure.Core.RehydrationToken? rehydrationToken = null)
+ {
+ _operation = global::Azure.Core.OperationInternal.Succeeded(response.GetRawResponse(), response.Value);
+ _completeRehydrationToken = rehydrationToken;
+ _operationId = this.GetOperationId(rehydrationToken);
+ }
+
+ internal SamplesArmOperation(global::Azure.Core.IOperationSource source, global::Azure.Core.Pipeline.ClientDiagnostics clientDiagnostics, global::Azure.Core.Pipeline.HttpPipeline pipeline, global::Azure.Core.Request request, global::Azure.Response response, global::Azure.Core.OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null)
+ {
+ global::Azure.Core.IOperation nextLinkOperation = global::Azure.Core.NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue);
+ if ((nextLinkOperation is global::Azure.Core.NextLinkOperationImplementation nextLinkOperationImplementation))
+ {
+ _nextLinkOperation = nextLinkOperationImplementation;
+ _operationId = _nextLinkOperation.OperationId;
+ }
+ else
+ {
+ _completeRehydrationToken = global::Azure.Core.NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia);
+ _operationId = this.GetOperationId(_completeRehydrationToken);
+ }
+ _operation = new global::Azure.Core.OperationInternal(
+ global::Azure.Core.NextLinkOperationImplementation.Create(source, nextLinkOperation),
+ clientDiagnostics,
+ response,
+ "SamplesArmOperation",
+ null,
+ new global::Azure.Core.SequentialDelayStrategy());
+ }
+
+ /// Gets the Id.
+ public override string Id => (_operationId ?? global::Azure.Core.NextLinkOperationImplementation.NotSet);
+
+ /// Gets the Value.
+ public override T Value => _operation.Value;
+
+ /// Gets the HasValue.
+ public override bool HasValue => _operation.HasValue;
+
+ /// Gets the HasCompleted.
+ public override bool HasCompleted => _operation.HasCompleted;
+
+ private string GetOperationId(global::Azure.Core.RehydrationToken? rehydrationToken)
+ {
+ if ((rehydrationToken is null))
+ {
+ return null;
+ }
+ global::System.Collections.Generic.Dictionary lroDetails = global::System.ClientModel.Primitives.ModelReaderWriter.Write(rehydrationToken, global::System.ClientModel.Primitives.ModelReaderWriterOptions.Json).ToObjectFromJson>();
+ return lroDetails["id"];
+ }
+
+ ///
+ public override global::Azure.Core.RehydrationToken? GetRehydrationToken() => (_nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken);
+
+ ///
+ public override global::Azure.Response GetRawResponse() => _operation.RawResponse;
+
+ ///
+ public override global::Azure.Response UpdateStatus(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.UpdateStatus(cancellationToken);
+
+ ///
+ public override global::System.Threading.Tasks.ValueTask UpdateStatusAsync(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.UpdateStatusAsync(cancellationToken);
+
+ ///
+ public override global::Azure.Response WaitForCompletion(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletion(cancellationToken);
+
+ ///
+ public override global::Azure.Response WaitForCompletion(global::System.TimeSpan pollingInterval, global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletion(pollingInterval, cancellationToken);
+
+ ///
+ public override global::System.Threading.Tasks.ValueTask> WaitForCompletionAsync(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletionAsync(cancellationToken);
+
+ ///
+ public override global::System.Threading.Tasks.ValueTask> WaitForCompletionAsync(global::System.TimeSpan pollingInterval, global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken);
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/MgmtLongRunningOperationProviderTests/Verify_NonGeneric_MgmtLROProviderGeneration.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/MgmtLongRunningOperationProviderTests/Verify_NonGeneric_MgmtLROProviderGeneration.cs
new file mode 100644
index 000000000000..99fa4a262f0a
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/Providers/TestData/MgmtLongRunningOperationProviderTests/Verify_NonGeneric_MgmtLROProviderGeneration.cs
@@ -0,0 +1,100 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.ClientModel.Primitives;
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.Core;
+using Azure.Core.Pipeline;
+using Azure.ResourceManager;
+
+namespace Samples
+{
+ internal partial class SamplesArmOperation : global::Azure.ResourceManager.ArmOperation
+ {
+ private readonly global::Azure.Core.OperationInternal _operation;
+ private readonly global::Azure.Core.RehydrationToken? _completeRehydrationToken;
+ private readonly global::Azure.Core.NextLinkOperationImplementation _nextLinkOperation;
+ private readonly string _operationId;
+
+ protected SamplesArmOperation()
+ {
+ }
+
+ internal SamplesArmOperation(global::Azure.Response response, global::Azure.Core.RehydrationToken? rehydrationToken = null)
+ {
+ _operation = global::Azure.Core.OperationInternal.Succeeded(response);
+ _completeRehydrationToken = rehydrationToken;
+ _operationId = this.GetOperationId(rehydrationToken);
+ }
+
+ internal SamplesArmOperation(global::Azure.Core.Pipeline.ClientDiagnostics clientDiagnostics, global::Azure.Core.Pipeline.HttpPipeline pipeline, global::Azure.Core.Request request, global::Azure.Response response, global::Azure.Core.OperationFinalStateVia finalStateVia, bool skipApiVersionOverride = false, string apiVersionOverrideValue = null)
+ {
+ global::Azure.Core.IOperation nextLinkOperation = global::Azure.Core.NextLinkOperationImplementation.Create(pipeline, request.Method, request.Uri.ToUri(), response, finalStateVia, skipApiVersionOverride, apiVersionOverrideValue);
+ if ((nextLinkOperation is global::Azure.Core.NextLinkOperationImplementation nextLinkOperationImplementation))
+ {
+ _nextLinkOperation = nextLinkOperationImplementation;
+ _operationId = _nextLinkOperation.OperationId;
+ }
+ else
+ {
+ _completeRehydrationToken = global::Azure.Core.NextLinkOperationImplementation.GetRehydrationToken(request.Method, request.Uri.ToUri(), response, finalStateVia);
+ _operationId = this.GetOperationId(_completeRehydrationToken);
+ }
+ _operation = new global::Azure.Core.OperationInternal(
+ nextLinkOperation,
+ clientDiagnostics,
+ response,
+ "SamplesArmOperation",
+ null,
+ new global::Azure.Core.SequentialDelayStrategy());
+ }
+
+ /// Gets the Id.
+ public override string Id => (_operationId ?? global::Azure.Core.NextLinkOperationImplementation.NotSet);
+
+ /// Gets the HasCompleted.
+ public override bool HasCompleted => _operation.HasCompleted;
+
+ private string GetOperationId(global::Azure.Core.RehydrationToken? rehydrationToken)
+ {
+ if ((rehydrationToken is null))
+ {
+ return null;
+ }
+ global::System.Collections.Generic.Dictionary lroDetails = global::System.ClientModel.Primitives.ModelReaderWriter.Write(rehydrationToken, global::System.ClientModel.Primitives.ModelReaderWriterOptions.Json).ToObjectFromJson>();
+ return lroDetails["id"];
+ }
+
+ ///
+ public override global::Azure.Core.RehydrationToken? GetRehydrationToken() => (_nextLinkOperation?.GetRehydrationToken() ?? _completeRehydrationToken);
+
+ ///
+ public override global::Azure.Response GetRawResponse() => _operation.RawResponse;
+
+ ///
+ public override global::Azure.Response UpdateStatus(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.UpdateStatus(cancellationToken);
+
+ ///
+ public override global::System.Threading.Tasks.ValueTask UpdateStatusAsync(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.UpdateStatusAsync(cancellationToken);
+
+ ///
+ public override global::Azure.Response WaitForCompletionResponse(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletionResponse(cancellationToken);
+
+ ///
+ public override global::Azure.Response WaitForCompletionResponse(global::System.TimeSpan pollingInterval, global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletionResponse(pollingInterval, cancellationToken);
+
+ ///
+ public override global::System.Threading.Tasks.ValueTask WaitForCompletionResponseAsync(global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletionResponseAsync(cancellationToken);
+
+ ///
+ public override global::System.Threading.Tasks.ValueTask WaitForCompletionResponseAsync(global::System.TimeSpan pollingInterval, global::System.Threading.CancellationToken cancellationToken = ((global::System.Threading.CancellationToken)default)) => _operation.WaitForCompletionResponseAsync(pollingInterval, cancellationToken);
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/Configuration.json b/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/Configuration.json
index f34eb20cbc6f..c49f9d0d580b 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/Configuration.json
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/Configuration.json
@@ -1,7 +1,6 @@
{
"output-folder": "./outputFolder",
"project-folder": "./projectFolder",
- "namespace": "sample.namespace",
"unknown-bool-property": false,
"library-name": "sample-library",
"unknown-string-property": "unknownPropertyValue"
diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/MockHelpers.cs b/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/MockHelpers.cs
index 330656827305..d3f796564713 100644
--- a/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/MockHelpers.cs
+++ b/eng/packages/http-client-csharp/generator/Azure.Generator/test/TestHelpers/MockHelpers.cs
@@ -1,13 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
-using Microsoft.Generator.CSharp;
-using Microsoft.Generator.CSharp.ClientModel;
-using Microsoft.Generator.CSharp.ClientModel.Providers;
-using Microsoft.Generator.CSharp.Input;
-using Microsoft.Generator.CSharp.Primitives;
-using Microsoft.Generator.CSharp.Providers;
-using Microsoft.Generator.CSharp.SourceInput;
+using Microsoft.TypeSpec.Generator;
+using Microsoft.TypeSpec.Generator.ClientModel;
+using Microsoft.TypeSpec.Generator.ClientModel.Providers;
+using Microsoft.TypeSpec.Generator.Input;
+using Microsoft.TypeSpec.Generator.Primitives;
+using Microsoft.TypeSpec.Generator.Providers;
+using Microsoft.TypeSpec.Generator.SourceInput;
using Moq;
using Moq.Protected;
using System;
@@ -41,12 +41,13 @@ public static Mock LoadMockPlugin(
IReadOnlyList inputNsModels = inputModels?.Invoke() ?? [];
InputAuth inputNsAuth = new InputAuth(apiKeyAuth?.Invoke(), oauth2Auth?.Invoke());
var mockInputNs = new Mock(
- string.Empty,
+ "Samples",
inputNsApiVersions,
inputNsEnums,
inputNsModels,
inputNsClients,
- inputNsAuth);
+ inputNsAuth,
+ null);
var mockInputLibrary = new Mock(_configFilePath);
mockInputLibrary.Setup(p => p.InputNamespace).Returns(mockInputNs.Object);
diff --git a/eng/packages/http-client-csharp/generator/Directory.Build.props b/eng/packages/http-client-csharp/generator/Directory.Build.props
index 054d97162e4b..167d97e85200 100644
--- a/eng/packages/http-client-csharp/generator/Directory.Build.props
+++ b/eng/packages/http-client-csharp/generator/Directory.Build.props
@@ -1,10 +1,12 @@
- false
- enable
+ enable
+ false
+ false
+ $(NoWarn);CS8002
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Directory.Build.props b/eng/packages/http-client-csharp/generator/TestProjects/Directory.Build.props
new file mode 100644
index 000000000000..aa6a7a08734f
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Directory.Build.props
@@ -0,0 +1,9 @@
+
+
+ true
+
+
+
+
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local.Tests/TestProjects.Local.Tests.csproj b/eng/packages/http-client-csharp/generator/TestProjects/Local.Tests/TestProjects.Local.Tests.csproj
new file mode 100644
index 000000000000..de21ce011954
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local.Tests/TestProjects.Local.Tests.csproj
@@ -0,0 +1,32 @@
+
+
+
+ net8.0
+ net8.0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Basic-TypeSpec.tsp b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Basic-TypeSpec.tsp
index e772a8aa1ead..17f98a98f443 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Basic-TypeSpec.tsp
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Basic-TypeSpec.tsp
@@ -104,8 +104,8 @@ union StringExtensibleEnum {
}
@doc("A model with a few properties of literal types")
-model Thing {
- @doc("name of the Thing")
+model ThingModel {
+ @doc("name of the ThingModel")
name: string;
@doc("required Union")
@@ -158,7 +158,7 @@ model ModelWithRequiredNullableProperties {
}
@doc("this is not a friendly model but with a friendly name")
-@friendlyName("Friend")
+@friendlyName("FriendModel")
model NotFriend {
@doc("name of the NotFriend")
name: string;
@@ -186,7 +186,7 @@ model RoundTripModel {
requiredDictionary: Record;
@doc("Required model")
- requiredModel: Thing;
+ requiredModel: ThingModel;
@doc("this is an int based extensible enum")
intExtensibleEnum?: IntExtensibleEnum;
@@ -266,7 +266,7 @@ op sayHi(
@header headParameter: string,
@query queryParameter: string,
@query optionalQuery?: string,
-): Thing;
+): ThingModel;
@route("/againHi")
@doc("Return hi again")
@@ -293,43 +293,43 @@ op noContentType(
@doc("Return hi in demo2")
@get
@convenientAPI(true)
-op helloDemo2(): Thing;
+op helloDemo2(): ThingModel;
@route("/literal")
@doc("Create with literal value")
@post
@convenientAPI(true)
-op createLiteral(@body body: Thing): Thing;
+op createLiteral(@body body: ThingModel): ThingModel;
@route("/helloLiteral")
@doc("Send literal parameters")
@get
@convenientAPI(true)
-op helloLiteral(@header p1: "test", @path p2: 123, @query p3: true): Thing;
+op helloLiteral(@header p1: "test", @path p2: 123, @query p3: true): ThingModel;
@route("/top")
@doc("top level method")
@get
@convenientAPI(true)
-op topAction(@path action: utcDateTime): Thing;
+op topAction(@path action: utcDateTime): ThingModel;
@route("/top2")
@doc("top level method2")
@get
@convenientAPI(false)
-op topAction2(): Thing;
+op topAction2(): ThingModel;
@route("/patch")
@doc("top level patch")
@patch
@convenientAPI(true)
-op patchAction(@body body: Thing): Thing;
+op patchAction(@body body: ThingModel): ThingModel;
@route("/anonymousBody")
@doc("body parameter without body decorator")
@post
@convenientAPI(true)
-op anonymousBody(...Thing): Thing;
+op anonymousBody(...ThingModel): ThingModel;
@route("/friendlyName")
@doc("Model can have its friendly name")
@@ -363,7 +363,7 @@ op getUnknownValue(): DaysOfWeekExtensibleEnum;
@post
@convenientAPI(true)
@protocolAPI(false)
-op internalProtocol(@body body: Thing): Thing;
+op internalProtocol(@body body: ThingModel): ThingModel;
@doc("When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one")
@route("stillConvenient")
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/BasicTypeSpec.sln b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/BasicTypeSpec.sln
index 710635bbac0a..c6fbd1ba4e2c 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/BasicTypeSpec.sln
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/BasicTypeSpec.sln
@@ -1,48 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio Version 16
-VisualStudioVersion = 16.0.29709.97
+# Visual Studio Version 17
+VisualStudioVersion = 17.10.35201.131
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BasicTypeSpec", "src\BasicTypeSpec.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
- {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
- {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
- {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
- {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
- {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
- {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
- GlobalSection(ExtensibilityGlobals) = postSolution
- SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
- EndGlobalSection
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
+ EndGlobalSection
EndGlobal
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Configuration.json b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Configuration.json
index 5c6a39e33830..b6c25ae61d32 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Configuration.json
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/Configuration.json
@@ -1,6 +1,5 @@
{
"output-folder": ".",
"namespace": "BasicTypeSpec",
- "library-name": "BasicTypeSpec",
- "use-model-reader-writer": true
+ "library-name": "BasicTypeSpec"
}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj
index de5464ba7117..5a82b2866e93 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj
@@ -4,15 +4,18 @@
SDK Code Generation BasicTypeSpec
1.0.0-beta.1
BasicTypeSpec
- netstandard2.0
- latest
true
-
-
-
+
+
+
+
+
+
+
+
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.cs
index 842b3b3c8b1c..e8ffe4cea722 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.cs
@@ -141,13 +141,13 @@ public virtual async Task SayHiAsync(string headParameter, string quer
/// The cancellation token that can be used to cancel the operation.
/// or is null.
/// Service returned a non-success status code.
- public virtual Response SayHi(string headParameter, string queryParameter, string optionalQuery = null, CancellationToken cancellationToken = default)
+ public virtual Response SayHi(string headParameter, string queryParameter, string optionalQuery = null, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(headParameter, nameof(headParameter));
Argument.AssertNotNull(queryParameter, nameof(queryParameter));
Response result = SayHi(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// Return hi.
@@ -157,13 +157,13 @@ public virtual Response SayHi(string headParameter, string queryParameter
/// The cancellation token that can be used to cancel the operation.
/// or is null.
/// Service returned a non-success status code.
- public virtual async Task> SayHiAsync(string headParameter, string queryParameter, string optionalQuery = null, CancellationToken cancellationToken = default)
+ public virtual async Task> SayHiAsync(string headParameter, string queryParameter, string optionalQuery = null, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(headParameter, nameof(headParameter));
Argument.AssertNotNull(queryParameter, nameof(queryParameter));
Response result = await SayHiAsync(headParameter, queryParameter, optionalQuery, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
@@ -337,19 +337,19 @@ public virtual async Task HelloDemo2Async(RequestContext context)
/// Return hi in demo2.
/// The cancellation token that can be used to cancel the operation.
/// Service returned a non-success status code.
- public virtual Response HelloDemo2(CancellationToken cancellationToken = default)
+ public virtual Response HelloDemo2(CancellationToken cancellationToken = default)
{
Response result = HelloDemo2(cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// Return hi in demo2.
/// The cancellation token that can be used to cancel the operation.
/// Service returned a non-success status code.
- public virtual async Task> HelloDemo2Async(CancellationToken cancellationToken = default)
+ public virtual async Task> HelloDemo2Async(CancellationToken cancellationToken = default)
{
Response result = await HelloDemo2Async(cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
@@ -399,12 +399,12 @@ public virtual async Task CreateLiteralAsync(RequestContent content, R
/// The cancellation token that can be used to cancel the operation.
/// is null.
/// Service returned a non-success status code.
- public virtual Response CreateLiteral(Thing body, CancellationToken cancellationToken = default)
+ public virtual Response CreateLiteral(ThingModel body, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(body, nameof(body));
Response result = CreateLiteral(body, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// Create with literal value.
@@ -412,12 +412,12 @@ public virtual Response CreateLiteral(Thing body, CancellationToken cance
/// The cancellation token that can be used to cancel the operation.
/// is null.
/// Service returned a non-success status code.
- public virtual async Task> CreateLiteralAsync(Thing body, CancellationToken cancellationToken = default)
+ public virtual async Task> CreateLiteralAsync(ThingModel body, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(body, nameof(body));
Response result = await CreateLiteralAsync(body, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
@@ -457,19 +457,19 @@ public virtual async Task HelloLiteralAsync(RequestContext context)
/// Send literal parameters.
/// The cancellation token that can be used to cancel the operation.
/// Service returned a non-success status code.
- public virtual Response HelloLiteral(CancellationToken cancellationToken = default)
+ public virtual Response HelloLiteral(CancellationToken cancellationToken = default)
{
Response result = HelloLiteral(cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// Send literal parameters.
/// The cancellation token that can be used to cancel the operation.
/// Service returned a non-success status code.
- public virtual async Task> HelloLiteralAsync(CancellationToken cancellationToken = default)
+ public virtual async Task> HelloLiteralAsync(CancellationToken cancellationToken = default)
{
Response result = await HelloLiteralAsync(cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
@@ -512,20 +512,20 @@ public virtual async Task TopActionAsync(DateTimeOffset action, Reques
///
/// The cancellation token that can be used to cancel the operation.
/// Service returned a non-success status code.
- public virtual Response TopAction(DateTimeOffset action, CancellationToken cancellationToken = default)
+ public virtual Response TopAction(DateTimeOffset action, CancellationToken cancellationToken = default)
{
Response result = TopAction(action, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// top level method.
///
/// The cancellation token that can be used to cancel the operation.
/// Service returned a non-success status code.
- public virtual async Task> TopActionAsync(DateTimeOffset action, CancellationToken cancellationToken = default)
+ public virtual async Task> TopActionAsync(DateTimeOffset action, CancellationToken cancellationToken = default)
{
Response result = await TopActionAsync(action, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
@@ -647,7 +647,7 @@ public virtual async Task AnonymousBodyAsync(RequestContent content, R
}
/// body parameter without body decorator.
- /// name of the Thing.
+ /// name of the ThingModel.
/// required Union.
/// required literal string.
/// required literal int.
@@ -663,13 +663,13 @@ public virtual async Task AnonymousBodyAsync(RequestContent content, R
/// The cancellation token that can be used to cancel the operation.
/// , or is null.
/// Service returned a non-success status code.
- public virtual Response AnonymousBody(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default)
+ public virtual Response AnonymousBody(string name, BinaryData requiredUnion, ThingModelRequiredLiteralString requiredLiteralString, ThingModelRequiredLiteralInt requiredLiteralInt, ThingModelRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, ThingModelOptionalLiteralString? optionalLiteralString = default, ThingModelOptionalLiteralInt? optionalLiteralInt = default, ThingModelOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(name, nameof(name));
Argument.AssertNotNull(requiredUnion, nameof(requiredUnion));
Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription));
- Thing spreadModel = new Thing(
+ ThingModel spreadModel = new ThingModel(
name,
requiredUnion,
requiredLiteralString,
@@ -685,11 +685,11 @@ public virtual Response AnonymousBody(string name, BinaryData requiredUni
requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(),
null);
Response result = AnonymousBody(spreadModel, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// body parameter without body decorator.
- /// name of the Thing.
+ /// name of the ThingModel.
/// required Union.
/// required literal string.
/// required literal int.
@@ -705,13 +705,13 @@ public virtual Response AnonymousBody(string name, BinaryData requiredUni
/// The cancellation token that can be used to cancel the operation.
/// , or is null.
/// Service returned a non-success status code.
- public virtual async Task> AnonymousBodyAsync(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default)
+ public virtual async Task> AnonymousBodyAsync(string name, BinaryData requiredUnion, ThingModelRequiredLiteralString requiredLiteralString, ThingModelRequiredLiteralInt requiredLiteralInt, ThingModelRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, ThingModelOptionalLiteralString? optionalLiteralString = default, ThingModelOptionalLiteralInt? optionalLiteralInt = default, ThingModelOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(name, nameof(name));
Argument.AssertNotNull(requiredUnion, nameof(requiredUnion));
Argument.AssertNotNull(requiredBadDescription, nameof(requiredBadDescription));
- Thing spreadModel = new Thing(
+ ThingModel spreadModel = new ThingModel(
name,
requiredUnion,
requiredLiteralString,
@@ -727,7 +727,7 @@ public virtual async Task> AnonymousBodyAsync(string name, Binar
requiredNullableList?.ToList() as IList ?? new ChangeTrackingList(),
null);
Response result = await AnonymousBodyAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
@@ -777,13 +777,13 @@ public virtual async Task FriendlyModelAsync(RequestContent content, R
/// The cancellation token that can be used to cancel the operation.
/// is null.
/// Service returned a non-success status code.
- public virtual Response FriendlyModel(string name, CancellationToken cancellationToken = default)
+ public virtual Response FriendlyModel(string name, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(name, nameof(name));
- Friend spreadModel = new Friend(name, null);
+ FriendModel spreadModel = new FriendModel(name, null);
Response result = FriendlyModel(spreadModel, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Friend)result, result);
+ return Response.FromValue((FriendModel)result, result);
}
/// Model can have its friendly name.
@@ -791,13 +791,13 @@ public virtual Response FriendlyModel(string name, CancellationToken can
/// The cancellation token that can be used to cancel the operation.
/// is null.
/// Service returned a non-success status code.
- public virtual async Task> FriendlyModelAsync(string name, CancellationToken cancellationToken = default)
+ public virtual async Task> FriendlyModelAsync(string name, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(name, nameof(name));
- Friend spreadModel = new Friend(name, null);
+ FriendModel spreadModel = new FriendModel(name, null);
Response result = await FriendlyModelAsync(spreadModel, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Friend)result, result);
+ return Response.FromValue((FriendModel)result, result);
}
///
@@ -1087,12 +1087,12 @@ public virtual async Task InternalProtocolAsync(RequestContent content
/// The cancellation token that can be used to cancel the operation.
/// is null.
/// Service returned a non-success status code.
- public virtual Response InternalProtocol(Thing body, CancellationToken cancellationToken = default)
+ public virtual Response InternalProtocol(ThingModel body, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(body, nameof(body));
Response result = InternalProtocol(body, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
/// When set protocol false and convenient true, then the protocol method should be internal.
@@ -1100,12 +1100,12 @@ public virtual Response InternalProtocol(Thing body, CancellationToken ca
/// The cancellation token that can be used to cancel the operation.
/// is null.
/// Service returned a non-success status code.
- public virtual async Task> InternalProtocolAsync(Thing body, CancellationToken cancellationToken = default)
+ public virtual async Task> InternalProtocolAsync(ThingModel body, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(body, nameof(body));
Response result = await InternalProtocolAsync(body, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false);
- return Response.FromValue((Thing)result, result);
+ return Response.FromValue((ThingModel)result, result);
}
///
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClientOptions.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClientOptions.cs
index ce57ff03d1bc..63f8b984ecd8 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClientOptions.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClientOptions.cs
@@ -27,6 +27,7 @@ public BasicTypeSpecClientOptions(ServiceVersion version = LatestVersion)
};
}
+ /// Gets the Version.
internal string Version { get; }
/// The version of the service to use.
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecModelFactory.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecModelFactory.cs
index c14a249fd60e..be59be858fed 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecModelFactory.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecModelFactory.cs
@@ -16,7 +16,7 @@ namespace BasicTypeSpec.Models
public static partial class BasicTypeSpecModelFactory
{
/// A model with a few properties of literal types.
- /// name of the Thing.
+ /// name of the ThingModel.
/// required Union.
/// required literal string.
/// required literal int.
@@ -29,13 +29,13 @@ public static partial class BasicTypeSpecModelFactory
/// description with xml <|endoftext|>.
/// optional nullable collection.
/// required nullable collection.
- /// A new instance for mocking.
- public static Thing Thing(string name = default, BinaryData requiredUnion = default, ThingRequiredLiteralString requiredLiteralString = default, ThingRequiredLiteralInt requiredLiteralInt = default, ThingRequiredLiteralFloat requiredLiteralFloat = default, bool requiredLiteralBool = default, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, string requiredBadDescription = default, IEnumerable optionalNullableList = default, IEnumerable requiredNullableList = default)
+ /// A new instance for mocking.
+ public static ThingModel ThingModel(string name = default, BinaryData requiredUnion = default, ThingModelRequiredLiteralString requiredLiteralString = default, ThingModelRequiredLiteralInt requiredLiteralInt = default, ThingModelRequiredLiteralFloat requiredLiteralFloat = default, bool requiredLiteralBool = default, ThingModelOptionalLiteralString? optionalLiteralString = default, ThingModelOptionalLiteralInt? optionalLiteralInt = default, ThingModelOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, string requiredBadDescription = default, IEnumerable optionalNullableList = default, IEnumerable requiredNullableList = default)
{
optionalNullableList ??= new ChangeTrackingList();
requiredNullableList ??= new ChangeTrackingList();
- return new Thing(
+ return new ThingModel(
name,
requiredUnion,
requiredLiteralString,
@@ -78,7 +78,7 @@ public static Thing Thing(string name = default, BinaryData requiredUnion = defa
/// this is a model with required nullable properties.
/// Required bytes.
/// A new instance for mocking.
- public static RoundTripModel RoundTripModel(string requiredString = default, int requiredInt = default, IEnumerable requiredCollection = default, IDictionary requiredDictionary = default, Thing requiredModel = default, IntExtensibleEnum? intExtensibleEnum = default, IEnumerable intExtensibleEnumCollection = default, FloatExtensibleEnum? floatExtensibleEnum = default, FloatExtensibleEnumWithIntValue? floatExtensibleEnumWithIntValue = default, IEnumerable floatExtensibleEnumCollection = default, FloatFixedEnum? floatFixedEnum = default, FloatFixedEnumWithIntValue? floatFixedEnumWithIntValue = default, IEnumerable floatFixedEnumCollection = default, IntFixedEnum? intFixedEnum = default, IEnumerable intFixedEnumCollection = default, StringFixedEnum? stringFixedEnum = default, BinaryData requiredUnknown = default, BinaryData optionalUnknown = default, IDictionary requiredRecordUnknown = default, IDictionary optionalRecordUnknown = default, IReadOnlyDictionary readOnlyRequiredRecordUnknown = default, IReadOnlyDictionary readOnlyOptionalRecordUnknown = default, ModelWithRequiredNullableProperties modelWithRequiredNullable = default, BinaryData requiredBytes = default)
+ public static RoundTripModel RoundTripModel(string requiredString = default, int requiredInt = default, IEnumerable requiredCollection = default, IDictionary requiredDictionary = default, ThingModel requiredModel = default, IntExtensibleEnum? intExtensibleEnum = default, IEnumerable intExtensibleEnumCollection = default, FloatExtensibleEnum? floatExtensibleEnum = default, FloatExtensibleEnumWithIntValue? floatExtensibleEnumWithIntValue = default, IEnumerable floatExtensibleEnumCollection = default, FloatFixedEnum? floatFixedEnum = default, FloatFixedEnumWithIntValue? floatFixedEnumWithIntValue = default, IEnumerable floatFixedEnumCollection = default, IntFixedEnum? intFixedEnum = default, IEnumerable intFixedEnumCollection = default, StringFixedEnum? stringFixedEnum = default, BinaryData requiredUnknown = default, BinaryData optionalUnknown = default, IDictionary requiredRecordUnknown = default, IDictionary optionalRecordUnknown = default, IReadOnlyDictionary readOnlyRequiredRecordUnknown = default, IReadOnlyDictionary readOnlyOptionalRecordUnknown = default, ModelWithRequiredNullableProperties modelWithRequiredNullable = default, BinaryData requiredBytes = default)
{
requiredCollection ??= new ChangeTrackingList();
requiredDictionary ??= new ChangeTrackingDictionary();
@@ -132,11 +132,11 @@ public static ModelWithRequiredNullableProperties ModelWithRequiredNullablePrope
/// this is not a friendly model but with a friendly name.
/// name of the NotFriend.
- /// A new instance for mocking.
- public static Friend Friend(string name = default)
+ /// A new instance for mocking.
+ public static FriendModel FriendModel(string name = default)
{
- return new Friend(name, additionalBinaryDataProperties: null);
+ return new FriendModel(name, additionalBinaryDataProperties: null);
}
/// this is a model with a projected name.
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs
index 37acbdc93da7..9b2442454da0 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs
@@ -42,16 +42,22 @@ public ChangeTrackingDictionary(IReadOnlyDictionary dictionary)
}
}
+ /// Gets the IsUndefined.
public bool IsUndefined => _innerDictionary == null;
+ /// Gets the Count.
public int Count => IsUndefined ? 0 : EnsureDictionary().Count;
+ /// Gets the IsReadOnly.
public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly;
+ /// Gets the Keys.
public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys;
+ /// Gets the Values.
public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values;
+ /// Gets or sets the value associated with the specified key.
public TValue this[TKey key]
{
get
@@ -68,8 +74,10 @@ public TValue this[TKey key]
}
}
+ /// Gets the Keys.
IEnumerable IReadOnlyDictionary.Keys => Keys;
+ /// Gets the Values.
IEnumerable IReadOnlyDictionary.Values => Values;
public IEnumerator> GetEnumerator()
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs
index 7475aea91e6a..9fceb42d0dca 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs
@@ -36,12 +36,16 @@ public ChangeTrackingList(IReadOnlyList innerList)
}
}
+ /// Gets the IsUndefined.
public bool IsUndefined => _innerList == null;
+ /// Gets the Count.
public int Count => IsUndefined ? 0 : EnsureList().Count;
+ /// Gets the IsReadOnly.
public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly;
+ /// Gets or sets the value associated with the specified key.
public T this[int index]
{
get
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenMemberAttribute.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenMemberAttribute.cs
new file mode 100644
index 000000000000..c47f5b7fd906
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenMemberAttribute.cs
@@ -0,0 +1,19 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+
+namespace BasicTypeSpec
+{
+ [AttributeUsage((AttributeTargets.Property | AttributeTargets.Field))]
+ internal partial class CodeGenMemberAttribute : CodeGenTypeAttribute
+ {
+ public CodeGenMemberAttribute(string originalName) : base(originalName)
+ {
+ }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenSerializationAttribute.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenSerializationAttribute.cs
new file mode 100644
index 000000000000..91d9439c2033
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenSerializationAttribute.cs
@@ -0,0 +1,45 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+
+namespace BasicTypeSpec
+{
+ [AttributeUsage((AttributeTargets.Class | AttributeTargets.Struct), AllowMultiple = true, Inherited = true)]
+ internal partial class CodeGenSerializationAttribute : Attribute
+ {
+ public CodeGenSerializationAttribute(string propertyName)
+ {
+ PropertyName = propertyName;
+ }
+
+ public CodeGenSerializationAttribute(string propertyName, string propertySerializationName)
+ {
+ PropertyName = propertyName;
+ PropertySerializationName = propertySerializationName;
+ }
+
+ /// Gets or sets the property name which these hooks should apply to.
+ public string PropertyName { get; }
+
+ /// Gets or sets the serialization name of the property.
+ public string PropertySerializationName { get; set; }
+
+ ///
+ /// Gets or sets the method name to use when serializing the property value (property name excluded).
+ /// The signature of the serialization hook method must be or compatible with when invoking: private void SerializeHook(Utf8JsonWriter writer);
+ ///
+ public string SerializationValueHook { get; set; }
+
+ ///
+ /// Gets or sets the method name to use when deserializing the property value from the JSON.
+ /// private static void DeserializationHook(JsonProperty property, ref TypeOfTheProperty propertyValue); // if the property is required
+ /// private static void DeserializationHook(JsonProperty property, ref Optional<TypeOfTheProperty> propertyValue); // if the property is optional
+ ///
+ public string DeserializationValueHook { get; set; }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenSuppressAttribute.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenSuppressAttribute.cs
new file mode 100644
index 000000000000..483c06d99f17
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenSuppressAttribute.cs
@@ -0,0 +1,27 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+
+namespace BasicTypeSpec
+{
+ [AttributeUsage((AttributeTargets.Class | AttributeTargets.Enum | AttributeTargets.Struct), AllowMultiple = true)]
+ internal partial class CodeGenSuppressAttribute : Attribute
+ {
+ public CodeGenSuppressAttribute(string member, params Type[] parameters)
+ {
+ Member = member;
+ Parameters = parameters;
+ }
+
+ /// Gets the Member.
+ public string Member { get; }
+
+ /// Gets the Parameters.
+ public Type[] Parameters { get; }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenTypeAttribute.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenTypeAttribute.cs
new file mode 100644
index 000000000000..0afbf0de6c8e
--- /dev/null
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/CodeGenTypeAttribute.cs
@@ -0,0 +1,23 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+
+namespace BasicTypeSpec
+{
+ [AttributeUsage((AttributeTargets.Class | AttributeTargets.Struct))]
+ internal partial class CodeGenTypeAttribute : Attribute
+ {
+ public CodeGenTypeAttribute(string originalName)
+ {
+ OriginalName = originalName;
+ }
+
+ /// Gets the OriginalName.
+ public string OriginalName { get; }
+ }
+}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ErrorResult.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ErrorResult.cs
index cc9535a76e79..2b801f065d70 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ErrorResult.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/ErrorResult.cs
@@ -20,6 +20,7 @@ public ErrorResult(Response response, RequestFailedException exception)
_exception = exception;
}
+ /// Gets the Value.
public override T Value => throw _exception;
public override Response GetRawResponse()
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs
index d7d35c3dfb08..250e1feee9e7 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs
@@ -25,6 +25,7 @@ public Utf8JsonBinaryContent()
JsonWriter = new Utf8JsonWriter(_stream);
}
+ /// Gets the JsonWriter.
public Utf8JsonWriter JsonWriter { get; }
public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default)
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Friend.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/FriendModel.Serialization.cs
similarity index 63%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Friend.Serialization.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/FriendModel.Serialization.cs
index 4f53647f4410..8072fce50f25 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Friend.Serialization.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/FriendModel.Serialization.cs
@@ -16,13 +16,13 @@
namespace BasicTypeSpec.Models
{
///
- public partial class Friend : IJsonModel
+ public partial class FriendModel : IJsonModel
{
- internal Friend()
+ internal FriendModel()
{
}
- void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
+ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
@@ -33,10 +33,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions op
/// The client options for reading and writing models.
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
- throw new FormatException($"The model {nameof(Friend)} does not support writing '{format}' format.");
+ throw new FormatException($"The model {nameof(FriendModel)} does not support writing '{format}' format.");
}
writer.WritePropertyName("name"u8);
writer.WriteStringValue(Name);
@@ -57,22 +57,22 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
}
}
- Friend IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
+ FriendModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
/// The JSON reader.
/// The client options for reading and writing models.
- protected virtual Friend JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
+ protected virtual FriendModel JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
- throw new FormatException($"The model {nameof(Friend)} does not support reading '{format}' format.");
+ throw new FormatException($"The model {nameof(FriendModel)} does not support reading '{format}' format.");
}
using JsonDocument document = JsonDocument.ParseValue(ref reader);
- return DeserializeFriend(document.RootElement, options);
+ return DeserializeFriendModel(document.RootElement, options);
}
- internal static Friend DeserializeFriend(JsonElement element, ModelReaderWriterOptions options)
+ internal static FriendModel DeserializeFriendModel(JsonElement element, ModelReaderWriterOptions options)
{
if (element.ValueKind == JsonValueKind.Null)
{
@@ -92,63 +92,63 @@ internal static Friend DeserializeFriend(JsonElement element, ModelReaderWriterO
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
}
- return new Friend(name, additionalBinaryDataProperties);
+ return new FriendModel(name, additionalBinaryDataProperties);
}
- BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
+ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
/// The client options for reading and writing models.
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
switch (format)
{
case "J":
return ModelReaderWriter.Write(this, options);
default:
- throw new FormatException($"The model {nameof(Friend)} does not support writing '{options.Format}' format.");
+ throw new FormatException($"The model {nameof(FriendModel)} does not support writing '{options.Format}' format.");
}
}
- Friend IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
+ FriendModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
/// The data to parse.
/// The client options for reading and writing models.
- protected virtual Friend PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
+ protected virtual FriendModel PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
switch (format)
{
case "J":
using (JsonDocument document = JsonDocument.Parse(data))
{
- return DeserializeFriend(document.RootElement, options);
+ return DeserializeFriendModel(document.RootElement, options);
}
default:
- throw new FormatException($"The model {nameof(Friend)} does not support reading '{options.Format}' format.");
+ throw new FormatException($"The model {nameof(FriendModel)} does not support reading '{options.Format}' format.");
}
}
- string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
+ string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
- /// The to serialize into .
- public static implicit operator RequestContent(Friend friend)
+ /// The to serialize into .
+ public static implicit operator RequestContent(FriendModel friendModel)
{
- if (friend == null)
+ if (friendModel == null)
{
return null;
}
Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
- content.JsonWriter.WriteObjectValue(friend, ModelSerializationExtensions.WireOptions);
+ content.JsonWriter.WriteObjectValue(friendModel, ModelSerializationExtensions.WireOptions);
return content;
}
- /// The to deserialize the from.
- public static explicit operator Friend(Response result)
+ /// The to deserialize the from.
+ public static explicit operator FriendModel(Response result)
{
using Response response = result;
using JsonDocument document = JsonDocument.Parse(response.Content);
- return DeserializeFriend(document.RootElement, ModelSerializationExtensions.WireOptions);
+ return DeserializeFriendModel(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Friend.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/FriendModel.cs
similarity index 80%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Friend.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/FriendModel.cs
index f1419a822a26..1fcf55afa212 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Friend.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/FriendModel.cs
@@ -11,17 +11,17 @@
namespace BasicTypeSpec.Models
{
/// this is not a friendly model but with a friendly name.
- public partial class Friend
+ public partial class FriendModel
{
/// Keeps track of any properties unknown to the library.
private protected readonly IDictionary _additionalBinaryDataProperties;
- internal Friend(string name)
+ internal FriendModel(string name)
{
Name = name;
}
- internal Friend(string name, IDictionary additionalBinaryDataProperties)
+ internal FriendModel(string name, IDictionary additionalBinaryDataProperties)
{
Name = name;
_additionalBinaryDataProperties = additionalBinaryDataProperties;
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs
index d3c11e295c7e..0a1ae09a1d1c 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs
@@ -290,7 +290,7 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element, Mo
int requiredInt = default;
IList requiredCollection = default;
IDictionary requiredDictionary = default;
- Thing requiredModel = default;
+ ThingModel requiredModel = default;
IntExtensibleEnum? intExtensibleEnum = default;
IList intExtensibleEnumCollection = default;
FloatExtensibleEnum? floatExtensibleEnum = default;
@@ -345,7 +345,7 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element, Mo
}
if (prop.NameEquals("requiredModel"u8))
{
- requiredModel = Thing.DeserializeThing(prop.Value, options);
+ requiredModel = ThingModel.DeserializeThingModel(prop.Value, options);
continue;
}
if (prop.NameEquals("intExtensibleEnum"u8))
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.cs
index 3f660931d13c..5db69baeebff 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/RoundTripModel.cs
@@ -30,7 +30,7 @@ public partial class RoundTripModel
/// this is a model with required nullable properties.
/// Required bytes.
/// , , , , , , or is null.
- public RoundTripModel(string requiredString, int requiredInt, IEnumerable requiredCollection, IDictionary requiredDictionary, Thing requiredModel, BinaryData requiredUnknown, IDictionary requiredRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, BinaryData requiredBytes)
+ public RoundTripModel(string requiredString, int requiredInt, IEnumerable requiredCollection, IDictionary requiredDictionary, ThingModel requiredModel, BinaryData requiredUnknown, IDictionary requiredRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, BinaryData requiredBytes)
{
Argument.AssertNotNull(requiredString, nameof(requiredString));
Argument.AssertNotNull(requiredCollection, nameof(requiredCollection));
@@ -59,7 +59,7 @@ public RoundTripModel(string requiredString, int requiredInt, IEnumerable requiredCollection, IDictionary requiredDictionary, Thing requiredModel, IntExtensibleEnum? intExtensibleEnum, IList intExtensibleEnumCollection, FloatExtensibleEnum? floatExtensibleEnum, FloatExtensibleEnumWithIntValue? floatExtensibleEnumWithIntValue, IList floatExtensibleEnumCollection, FloatFixedEnum? floatFixedEnum, FloatFixedEnumWithIntValue? floatFixedEnumWithIntValue, IList floatFixedEnumCollection, IntFixedEnum? intFixedEnum, IList intFixedEnumCollection, StringFixedEnum? stringFixedEnum, BinaryData requiredUnknown, BinaryData optionalUnknown, IDictionary requiredRecordUnknown, IDictionary optionalRecordUnknown, IReadOnlyDictionary readOnlyRequiredRecordUnknown, IReadOnlyDictionary readOnlyOptionalRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, BinaryData requiredBytes, IDictionary additionalBinaryDataProperties)
+ internal RoundTripModel(string requiredString, int requiredInt, IList requiredCollection, IDictionary requiredDictionary, ThingModel requiredModel, IntExtensibleEnum? intExtensibleEnum, IList intExtensibleEnumCollection, FloatExtensibleEnum? floatExtensibleEnum, FloatExtensibleEnumWithIntValue? floatExtensibleEnumWithIntValue, IList floatExtensibleEnumCollection, FloatFixedEnum? floatFixedEnum, FloatFixedEnumWithIntValue? floatFixedEnumWithIntValue, IList floatFixedEnumCollection, IntFixedEnum? intFixedEnum, IList intFixedEnumCollection, StringFixedEnum? stringFixedEnum, BinaryData requiredUnknown, BinaryData optionalUnknown, IDictionary requiredRecordUnknown, IDictionary optionalRecordUnknown, IReadOnlyDictionary readOnlyRequiredRecordUnknown, IReadOnlyDictionary readOnlyOptionalRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, BinaryData requiredBytes, IDictionary additionalBinaryDataProperties)
{
RequiredString = requiredString;
RequiredInt = requiredInt;
@@ -101,7 +101,7 @@ internal RoundTripModel(string requiredString, int requiredInt, IList RequiredDictionary { get; }
/// Required model.
- public Thing RequiredModel { get; set; }
+ public ThingModel RequiredModel { get; set; }
/// this is an int based extensible enum.
public IntExtensibleEnum? IntExtensibleEnum { get; set; }
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Thing.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModel.Serialization.cs
similarity index 77%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Thing.Serialization.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModel.Serialization.cs
index d67702d57298..98b9fd91b356 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Thing.Serialization.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModel.Serialization.cs
@@ -16,13 +16,13 @@
namespace BasicTypeSpec.Models
{
///
- public partial class Thing : IJsonModel
+ public partial class ThingModel : IJsonModel
{
- internal Thing()
+ internal ThingModel()
{
}
- void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
+ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
@@ -33,10 +33,10 @@ void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions opt
/// The client options for reading and writing models.
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
- throw new FormatException($"The model {nameof(Thing)} does not support writing '{format}' format.");
+ throw new FormatException($"The model {nameof(ThingModel)} does not support writing '{format}' format.");
}
writer.WritePropertyName("name"u8);
writer.WriteStringValue(Name);
@@ -127,22 +127,22 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
}
}
- Thing IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
+ ThingModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
/// The JSON reader.
/// The client options for reading and writing models.
- protected virtual Thing JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
+ protected virtual ThingModel JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
- throw new FormatException($"The model {nameof(Thing)} does not support reading '{format}' format.");
+ throw new FormatException($"The model {nameof(ThingModel)} does not support reading '{format}' format.");
}
using JsonDocument document = JsonDocument.ParseValue(ref reader);
- return DeserializeThing(document.RootElement, options);
+ return DeserializeThingModel(document.RootElement, options);
}
- internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOptions options)
+ internal static ThingModel DeserializeThingModel(JsonElement element, ModelReaderWriterOptions options)
{
if (element.ValueKind == JsonValueKind.Null)
{
@@ -150,13 +150,13 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
}
string name = default;
BinaryData requiredUnion = default;
- ThingRequiredLiteralString requiredLiteralString = default;
- ThingRequiredLiteralInt requiredLiteralInt = default;
- ThingRequiredLiteralFloat requiredLiteralFloat = default;
+ ThingModelRequiredLiteralString requiredLiteralString = default;
+ ThingModelRequiredLiteralInt requiredLiteralInt = default;
+ ThingModelRequiredLiteralFloat requiredLiteralFloat = default;
bool requiredLiteralBool = default;
- ThingOptionalLiteralString? optionalLiteralString = default;
- ThingOptionalLiteralInt? optionalLiteralInt = default;
- ThingOptionalLiteralFloat? optionalLiteralFloat = default;
+ ThingModelOptionalLiteralString? optionalLiteralString = default;
+ ThingModelOptionalLiteralInt? optionalLiteralInt = default;
+ ThingModelOptionalLiteralFloat? optionalLiteralFloat = default;
bool? optionalLiteralBool = default;
string requiredBadDescription = default;
IList optionalNullableList = default;
@@ -176,17 +176,17 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
}
if (prop.NameEquals("requiredLiteralString"u8))
{
- requiredLiteralString = new ThingRequiredLiteralString(prop.Value.GetString());
+ requiredLiteralString = new ThingModelRequiredLiteralString(prop.Value.GetString());
continue;
}
if (prop.NameEquals("requiredLiteralInt"u8))
{
- requiredLiteralInt = new ThingRequiredLiteralInt(prop.Value.GetInt32());
+ requiredLiteralInt = new ThingModelRequiredLiteralInt(prop.Value.GetInt32());
continue;
}
if (prop.NameEquals("requiredLiteralFloat"u8))
{
- requiredLiteralFloat = new ThingRequiredLiteralFloat(prop.Value.GetSingle());
+ requiredLiteralFloat = new ThingModelRequiredLiteralFloat(prop.Value.GetSingle());
continue;
}
if (prop.NameEquals("requiredLiteralBool"u8))
@@ -200,7 +200,7 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
{
continue;
}
- optionalLiteralString = new ThingOptionalLiteralString(prop.Value.GetString());
+ optionalLiteralString = new ThingModelOptionalLiteralString(prop.Value.GetString());
continue;
}
if (prop.NameEquals("optionalLiteralInt"u8))
@@ -209,7 +209,7 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
{
continue;
}
- optionalLiteralInt = new ThingOptionalLiteralInt(prop.Value.GetInt32());
+ optionalLiteralInt = new ThingModelOptionalLiteralInt(prop.Value.GetInt32());
continue;
}
if (prop.NameEquals("optionalLiteralFloat"u8))
@@ -218,7 +218,7 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
{
continue;
}
- optionalLiteralFloat = new ThingOptionalLiteralFloat(prop.Value.GetSingle());
+ optionalLiteralFloat = new ThingModelOptionalLiteralFloat(prop.Value.GetSingle());
continue;
}
if (prop.NameEquals("optionalLiteralBool"u8))
@@ -269,7 +269,7 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
}
- return new Thing(
+ return new ThingModel(
name,
requiredUnion,
requiredLiteralString,
@@ -286,60 +286,60 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt
additionalBinaryDataProperties);
}
- BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
+ BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
/// The client options for reading and writing models.
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
switch (format)
{
case "J":
return ModelReaderWriter.Write(this, options);
default:
- throw new FormatException($"The model {nameof(Thing)} does not support writing '{options.Format}' format.");
+ throw new FormatException($"The model {nameof(ThingModel)} does not support writing '{options.Format}' format.");
}
}
- Thing IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
+ ThingModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
/// The data to parse.
/// The client options for reading and writing models.
- protected virtual Thing PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
+ protected virtual ThingModel PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
{
- string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
+ string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format;
switch (format)
{
case "J":
using (JsonDocument document = JsonDocument.Parse(data))
{
- return DeserializeThing(document.RootElement, options);
+ return DeserializeThingModel(document.RootElement, options);
}
default:
- throw new FormatException($"The model {nameof(Thing)} does not support reading '{options.Format}' format.");
+ throw new FormatException($"The model {nameof(ThingModel)} does not support reading '{options.Format}' format.");
}
}
- string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
+ string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
- /// The to serialize into .
- public static implicit operator RequestContent(Thing thing)
+ /// The to serialize into .
+ public static implicit operator RequestContent(ThingModel thingModel)
{
- if (thing == null)
+ if (thingModel == null)
{
return null;
}
Utf8JsonBinaryContent content = new Utf8JsonBinaryContent();
- content.JsonWriter.WriteObjectValue(thing, ModelSerializationExtensions.WireOptions);
+ content.JsonWriter.WriteObjectValue(thingModel, ModelSerializationExtensions.WireOptions);
return content;
}
- /// The to deserialize the from.
- public static explicit operator Thing(Response result)
+ /// The to deserialize the from.
+ public static explicit operator ThingModel(Response result)
{
using Response response = result;
using JsonDocument document = JsonDocument.Parse(response.Content);
- return DeserializeThing(document.RootElement, ModelSerializationExtensions.WireOptions);
+ return DeserializeThingModel(document.RootElement, ModelSerializationExtensions.WireOptions);
}
}
}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Thing.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModel.cs
similarity index 78%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Thing.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModel.cs
index 62e0c73a58db..40d550750eac 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/Thing.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModel.cs
@@ -14,18 +14,18 @@
namespace BasicTypeSpec.Models
{
/// A model with a few properties of literal types.
- public partial class Thing
+ public partial class ThingModel
{
/// Keeps track of any properties unknown to the library.
private protected readonly IDictionary _additionalBinaryDataProperties;
- /// Initializes a new instance of .
- /// name of the Thing.
+ /// Initializes a new instance of .
+ /// name of the ThingModel.
/// required Union.
/// description with xml <|endoftext|>.
/// required nullable collection.
/// , or is null.
- public Thing(string name, BinaryData requiredUnion, string requiredBadDescription, IEnumerable requiredNullableList)
+ public ThingModel(string name, BinaryData requiredUnion, string requiredBadDescription, IEnumerable requiredNullableList)
{
Argument.AssertNotNull(name, nameof(name));
Argument.AssertNotNull(requiredUnion, nameof(requiredUnion));
@@ -38,7 +38,7 @@ public Thing(string name, BinaryData requiredUnion, string requiredBadDescriptio
RequiredNullableList = requiredNullableList?.ToList();
}
- internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary additionalBinaryDataProperties)
+ internal ThingModel(string name, BinaryData requiredUnion, ThingModelRequiredLiteralString requiredLiteralString, ThingModelRequiredLiteralInt requiredLiteralInt, ThingModelRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingModelOptionalLiteralString? optionalLiteralString, ThingModelOptionalLiteralInt? optionalLiteralInt, ThingModelOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary additionalBinaryDataProperties)
{
Name = name;
RequiredUnion = requiredUnion;
@@ -56,7 +56,7 @@ internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString
_additionalBinaryDataProperties = additionalBinaryDataProperties;
}
- /// name of the Thing.
+ /// name of the ThingModel.
public string Name { get; set; }
///
@@ -104,25 +104,25 @@ internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString
public BinaryData RequiredUnion { get; set; }
/// required literal string.
- public ThingRequiredLiteralString RequiredLiteralString { get; } = "accept";
+ public ThingModelRequiredLiteralString RequiredLiteralString { get; } = "accept";
/// required literal int.
- public ThingRequiredLiteralInt RequiredLiteralInt { get; } = 123;
+ public ThingModelRequiredLiteralInt RequiredLiteralInt { get; } = 123;
/// required literal float.
- public ThingRequiredLiteralFloat RequiredLiteralFloat { get; } = 1.23F;
+ public ThingModelRequiredLiteralFloat RequiredLiteralFloat { get; } = 1.23F;
/// required literal bool.
public bool RequiredLiteralBool { get; } = false;
/// optional literal string.
- public ThingOptionalLiteralString? OptionalLiteralString { get; set; }
+ public ThingModelOptionalLiteralString? OptionalLiteralString { get; set; }
/// optional literal int.
- public ThingOptionalLiteralInt? OptionalLiteralInt { get; set; }
+ public ThingModelOptionalLiteralInt? OptionalLiteralInt { get; set; }
/// optional literal float.
- public ThingOptionalLiteralFloat? OptionalLiteralFloat { get; set; }
+ public ThingModelOptionalLiteralFloat? OptionalLiteralFloat { get; set; }
/// optional literal bool.
public bool? OptionalLiteralBool { get; set; }
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralFloat.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralFloat.Serialization.cs
similarity index 80%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralFloat.Serialization.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralFloat.Serialization.cs
index 54d5ba9097d5..3f9dbf5aff19 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralFloat.Serialization.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralFloat.Serialization.cs
@@ -8,7 +8,7 @@
namespace BasicTypeSpec.Models
{
///
- public readonly partial struct ThingOptionalLiteralFloat
+ public readonly partial struct ThingModelOptionalLiteralFloat
{
internal float ToSerialSingle() => _value;
}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralFloat.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralFloat.cs
similarity index 50%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralFloat.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralFloat.cs
index 8bdecf41d8e1..584521976cd3 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralFloat.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralFloat.cs
@@ -11,43 +11,43 @@
namespace BasicTypeSpec.Models
{
- /// The Thing_optionalLiteralFloat.
- public readonly partial struct ThingOptionalLiteralFloat : IEquatable
+ /// The ThingModel_optionalLiteralFloat.
+ public readonly partial struct ThingModelOptionalLiteralFloat : IEquatable
{
private readonly float _value;
/// 4.56.
private const float _456Value = 4.56F;
- /// Initializes a new instance of .
+ /// Initializes a new instance of .
/// The value.
- public ThingOptionalLiteralFloat(float value)
+ public ThingModelOptionalLiteralFloat(float value)
{
_value = value;
}
/// 4.56.
- public static ThingOptionalLiteralFloat _456 { get; } = new ThingOptionalLiteralFloat(_456Value);
+ public static ThingModelOptionalLiteralFloat _456 { get; } = new ThingModelOptionalLiteralFloat(_456Value);
- /// Determines if two values are the same.
+ /// Determines if two values are the same.
/// The left value to compare.
/// The right value to compare.
- public static bool operator ==(ThingOptionalLiteralFloat left, ThingOptionalLiteralFloat right) => left.Equals(right);
+ public static bool operator ==(ThingModelOptionalLiteralFloat left, ThingModelOptionalLiteralFloat right) => left.Equals(right);
- /// Determines if two values are not the same.
+ /// Determines if two values are not the same.
/// The left value to compare.
/// The right value to compare.
- public static bool operator !=(ThingOptionalLiteralFloat left, ThingOptionalLiteralFloat right) => !left.Equals(right);
+ public static bool operator !=(ThingModelOptionalLiteralFloat left, ThingModelOptionalLiteralFloat right) => !left.Equals(right);
- /// Converts a string to a .
+ /// Converts a string to a .
/// The value.
- public static implicit operator ThingOptionalLiteralFloat(float value) => new ThingOptionalLiteralFloat(value);
+ public static implicit operator ThingModelOptionalLiteralFloat(float value) => new ThingModelOptionalLiteralFloat(value);
/// The object to compare.
[EditorBrowsable(EditorBrowsableState.Never)]
- public override bool Equals(object obj) => obj is ThingOptionalLiteralFloat other && Equals(other);
+ public override bool Equals(object obj) => obj is ThingModelOptionalLiteralFloat other && Equals(other);
/// The instance to compare.
- public bool Equals(ThingOptionalLiteralFloat other) => Equals(_value, other._value);
+ public bool Equals(ThingModelOptionalLiteralFloat other) => Equals(_value, other._value);
///
[EditorBrowsable(EditorBrowsableState.Never)]
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralInt.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralInt.Serialization.cs
similarity index 80%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralInt.Serialization.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralInt.Serialization.cs
index 42226648eb0e..efa28872b748 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralInt.Serialization.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralInt.Serialization.cs
@@ -8,7 +8,7 @@
namespace BasicTypeSpec.Models
{
///
- public readonly partial struct ThingOptionalLiteralInt
+ public readonly partial struct ThingModelOptionalLiteralInt
{
internal int ToSerialInt32() => _value;
}
diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralInt.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralInt.cs
similarity index 50%
rename from eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralInt.cs
rename to eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralInt.cs
index a8e34d9deb2e..7e731005b4c5 100644
--- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingOptionalLiteralInt.cs
+++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/Models/ThingModelOptionalLiteralInt.cs
@@ -11,43 +11,43 @@
namespace BasicTypeSpec.Models
{
- /// The Thing_optionalLiteralInt.
- public readonly partial struct ThingOptionalLiteralInt : IEquatable
+ /// The ThingModel_optionalLiteralInt.
+ public readonly partial struct ThingModelOptionalLiteralInt : IEquatable
{
private readonly int _value;
/// 456.
private const int _456Value = 456;
- /// Initializes a new instance of