From 1207495a787794e29249c15c142ea928ee8c9b52 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 26 Nov 2024 11:44:07 +0800 Subject: [PATCH 1/5] Initialize generation test for mgmt --- .../generator/Azure.Generator.sln | 12 + .../src/Azure.Generator.csproj | 4 +- .../Azure.Generator/src/AzureTypeFactory.cs | 46 + .../BasicTypeSpecClient.RestClient.cs | 3 + .../Local/Mgmt-TypeSpec/Configuration.json | 6 + .../Local/Mgmt-TypeSpec/MgmtTypeSpec.sln | 48 + .../PrivateEndpointConnection.tsp | 44 + .../TestProjects/Local/Mgmt-TypeSpec/foo.tsp | 44 + .../TestProjects/Local/Mgmt-TypeSpec/main.tsp | 25 + .../src/Generated/Foos.RestClient.cs | 113 + .../Local/Mgmt-TypeSpec/src/Generated/Foos.cs | 339 ++ .../src/Generated/Internal/Argument.cs | 129 + .../Internal/ChangeTrackingDictionary.cs | 168 + .../Generated/Internal/ChangeTrackingList.cs | 153 + .../Internal/ClientPipelineExtensions.cs | 72 + .../src/Generated/Internal/ErrorResult.cs | 30 + .../Internal/ModelSerializationExtensions.cs | 254 ++ .../src/Generated/Internal/Optional.cs | 51 + .../Internal/RequestContextExtensions.cs | 25 + .../src/Generated/Internal/TypeFormatters.cs | 153 + .../Internal/Utf8JsonBinaryContent.cs | 55 + .../MgmtTypeSpecClient.RestClient.cs | 35 + .../src/Generated/MgmtTypeSpecClient.cs | 62 + .../Generated/MgmtTypeSpecClientOptions.cs | 38 + .../src/Generated/MgmtTypeSpecModelFactory.cs | 271 ++ .../src/Generated/Models/ActionType.cs | 62 + .../src/Generated/Models/CreatedByType.cs | 77 + .../Models/ExtendedLocation.Serialization.cs | 162 + .../src/Generated/Models/ExtendedLocation.cs | 45 + .../Generated/Models/ExtendedLocationType.cs | 67 + .../src/Generated/Models/Foo.Serialization.cs | 231 ++ .../Mgmt-TypeSpec/src/Generated/Models/Foo.cs | 39 + .../Models/FooListResult.Serialization.cs | 179 + .../src/Generated/Models/FooListResult.cs | 38 + .../Models/FooProperties.Serialization.cs | 219 + .../src/Generated/Models/FooProperties.cs | 49 + .../ManagedServiceIdentity.Serialization.cs | 210 + .../Models/ManagedServiceIdentity.cs | 47 + .../Models/ManagedServiceIdentityType.cs | 77 + .../Models/Operation.Serialization.cs | 219 + .../src/Generated/Models/Operation.cs | 48 + .../Models/OperationDisplay.Serialization.cs | 186 + .../src/Generated/Models/OperationDisplay.cs | 44 + .../OperationListResult.Serialization.cs | 179 + .../Generated/Models/OperationListResult.cs | 38 + .../src/Generated/Models/Origin.cs | 72 + .../PrivateLinkResource.Serialization.cs | 197 + .../Generated/Models/PrivateLinkResource.cs | 33 + ...ateLinkResourceListResult.Serialization.cs | 179 + .../Models/PrivateLinkResourceListResult.cs | 38 + ...ateLinkResourceProperties.Serialization.cs | 227 ++ .../Models/PrivateLinkResourceProperties.cs | 43 + .../Models/ProxyResource.Serialization.cs | 160 + .../src/Generated/Models/ProxyResource.cs | 25 + .../Models/Resource.Serialization.cs | 194 + .../src/Generated/Models/Resource.cs | 46 + .../Models/StartRequest.Serialization.cs | 157 + .../src/Generated/Models/StartRequest.cs | 33 + .../Models/SystemData.Serialization.cs | 231 ++ .../src/Generated/Models/SystemData.cs | 52 + .../Models/TrackedResource.Serialization.cs | 217 + .../src/Generated/Models/TrackedResource.cs | 41 + .../UserAssignedIdentity.Serialization.cs | 172 + .../Generated/Models/UserAssignedIdentity.cs | 36 + .../src/Generated/Operations.RestClient.cs | 50 + .../Mgmt-TypeSpec/src/Generated/Operations.cs | 90 + .../src/Generated/PrivateLinks.RestClient.cs | 76 + .../src/Generated/PrivateLinks.cs | 185 + .../Mgmt-TypeSpec/src/MgmtTypeSpec.csproj | 23 + .../Local/Mgmt-TypeSpec/tspCodeModel.json | 3528 +++++++++++++++++ .../Local/Mgmt-TypeSpec/tspconfig.yaml | 6 + eng/scripts/typespec/Generate-Code.ps1 | 8 + 72 files changed, 10514 insertions(+), 1 deletion(-) create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/Configuration.json create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/MgmtTypeSpec.sln create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/PrivateEndpointConnection.tsp create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/foo.tsp create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/main.tsp create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.RestClient.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Argument.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ClientPipelineExtensions.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ErrorResult.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ModelSerializationExtensions.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Optional.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/RequestContextExtensions.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/TypeFormatters.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.RestClient.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClientOptions.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecModelFactory.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ActionType.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/CreatedByType.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocationType.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentityType.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Origin.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.Serialization.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.RestClient.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.RestClient.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.cs create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/MgmtTypeSpec.csproj create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json create mode 100644 eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspconfig.yaml diff --git a/eng/packages/http-client-csharp/generator/Azure.Generator.sln b/eng/packages/http-client-csharp/generator/Azure.Generator.sln index 975f6a6f8cd18..17a5fbff0ed07 100644 --- a/eng/packages/http-client-csharp/generator/Azure.Generator.sln +++ b/eng/packages/http-client-csharp/generator/Azure.Generator.sln @@ -9,6 +9,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicTypeSpec", "TestProjec EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Azure.Generator.Tests", "Azure.Generator\test\Azure.Generator.Tests.csproj", "{A05E6873-DD18-44B2-88A8-DEE3AA103EC4}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Generator.CSharp.ClientModel", "..\..\..\..\..\..\work\typespec\packages\http-client-csharp\generator\Microsoft.Generator.CSharp.ClientModel\src\Microsoft.Generator.CSharp.ClientModel.csproj", "{9498A9AC-9CBA-4F63-B63A-E637E4BF18FC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MgmtTypeSpec", "TestProjects\Local\Mgmt-TypeSpec\src\MgmtTypeSpec.csproj", "{E9A906BE-C35C-4F4C-8C52-45761BC9F2D2}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -27,6 +31,14 @@ Global {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 + {9498A9AC-9CBA-4F63-B63A-E637E4BF18FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9498A9AC-9CBA-4F63-B63A-E637E4BF18FC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9498A9AC-9CBA-4F63-B63A-E637E4BF18FC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9498A9AC-9CBA-4F63-B63A-E637E4BF18FC}.Release|Any CPU.Build.0 = Release|Any CPU + {E9A906BE-C35C-4F4C-8C52-45761BC9F2D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E9A906BE-C35C-4F4C-8C52-45761BC9F2D2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E9A906BE-C35C-4F4C-8C52-45761BC9F2D2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E9A906BE-C35C-4F4C-8C52-45761BC9F2D2}.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 1be69ca02cf7c..21830ac017e53 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 @@ -10,7 +10,6 @@ - @@ -31,5 +30,8 @@ Always + + + 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 070aca4a2cf50..52c9433ac23fd 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 @@ -1,13 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using Azure.Core; 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.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 System; +using System.ClientModel.Primitives; +using System.Text.Json; +using static Microsoft.Generator.CSharp.Snippets.Snippet; namespace Azure.Generator { @@ -70,5 +79,42 @@ public class AzureTypeFactory : ScmTypeFactory return null; } + + /// + public override ValueExpression GetValueTypeDeserializationExpression(Type valueType, ScopedApi element, SerializationFormat format) + { + var expression = GetValueTypeDeserializationExpressionCore(valueType, element, format); + return expression ?? base.GetValueTypeDeserializationExpression(valueType, element, format); + } + + private ValueExpression? GetValueTypeDeserializationExpressionCore( + Type valueType, + ScopedApi element, + SerializationFormat format) + { + return valueType switch + { + Type t when t == typeof(ResourceIdentifier) => + New.Instance(valueType, element.GetString()), + _ => null, + }; + } + + /// + public override MethodBodyStatement SerializeValueType(CSharpType type, SerializationFormat serializationFormat, ValueExpression value, Type valueType, ScopedApi utf8JsonWriterSnippet, ScopedApi mrwOptionsParameterSnippet) + { + var statement = SerializeValueTypeCore(type, serializationFormat, value, valueType, utf8JsonWriterSnippet, mrwOptionsParameterSnippet); + return statement ?? base.SerializeValueType(type, serializationFormat, value, valueType, utf8JsonWriterSnippet, mrwOptionsParameterSnippet); + } + + private MethodBodyStatement? SerializeValueTypeCore(CSharpType type, SerializationFormat serializationFormat, ValueExpression value, Type valueType, ScopedApi utf8JsonWriterSnippet, ScopedApi mrwOptionsParameterSnippet) + { + return valueType switch + { + Type t when t == typeof(ResourceIdentifier) => + utf8JsonWriterSnippet.WriteStringValue(value.Property(nameof(ResourceIdentifier.Name))), + _ => null, + }; + } } } diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.RestClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.RestClient.cs index 14f2109f5695f..e98108ad75d58 100644 --- a/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.RestClient.cs +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Basic-TypeSpec/src/Generated/BasicTypeSpecClient.RestClient.cs @@ -16,6 +16,7 @@ public partial class BasicTypeSpecClient { private static ResponseClassifier _pipelineMessageClassifier200; private static ResponseClassifier _pipelineMessageClassifier201; + private static ResponseClassifier _pipelineMessageClassifier202; private static ResponseClassifier _pipelineMessageClassifier204; private static Classifier2xxAnd4xx _pipelineMessageClassifier2xxAnd4xx; @@ -23,6 +24,8 @@ public partial class BasicTypeSpecClient private static ResponseClassifier PipelineMessageClassifier201 => _pipelineMessageClassifier201 = new StatusCodeClassifier(stackalloc ushort[] { 201 }); + private static ResponseClassifier PipelineMessageClassifier202 => _pipelineMessageClassifier202 = new StatusCodeClassifier(stackalloc ushort[] { 202 }); + private static ResponseClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 = new StatusCodeClassifier(stackalloc ushort[] { 204 }); private static Classifier2xxAnd4xx PipelineMessageClassifier2xxAnd4xx => _pipelineMessageClassifier2xxAnd4xx ??= new Classifier2xxAnd4xx(); diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/Configuration.json b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/Configuration.json new file mode 100644 index 0000000000000..99e9686a9529b --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/Configuration.json @@ -0,0 +1,6 @@ +{ + "output-folder": ".", + "namespace": "MgmtTypeSpec", + "library-name": "MgmtTypeSpec", + "use-model-reader-writer": true +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/MgmtTypeSpec.sln b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/MgmtTypeSpec.sln new file mode 100644 index 0000000000000..dd844bd4f0342 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/MgmtTypeSpec.sln @@ -0,0 +1,48 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MgmtTypeSpec", "src\MgmtTypeSpec.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 +EndGlobal diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/PrivateEndpointConnection.tsp b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/PrivateEndpointConnection.tsp new file mode 100644 index 0000000000000..f9ab0866aa717 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/PrivateEndpointConnection.tsp @@ -0,0 +1,44 @@ +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using Azure.ResourceManager; +using Azure.ClientGenerator.Core; + +namespace MgmtTypeSpec; + +#suppress "@azure-tools/typespec-providerhub-controller/no-resource-operations" "Expected for private links" +model PrivateLinkResource is ProxyResource { + ...PrivateLinkResourceParameter; + ...ManagedServiceIdentityProperty; +} + +@armResourceOperations(PrivateLinkResource) +interface PrivateLinks { + /** list private links on the given resource */ + @clientName("GetAllPrivateLinkResources") + listByMongoCluster is ArmResourceListByParent; + + /** + * Starts the SAP Application Server Instance. + */ + start is ArmResourceActionAsync< + PrivateLinkResource, + { + @doc("SAP Application server instance start request body.") + @body + body?: StartRequest; + }, + Foundations.OperationStatusResult + >; +} + +/** + * Start SAP instance(s) request body. + */ +model StartRequest { + /** + * The boolean value indicates whether to start the virtual machines before starting the SAP instances. + */ + startVm?: boolean; +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/foo.tsp b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/foo.tsp new file mode 100644 index 0000000000000..01b6a5f748944 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/foo.tsp @@ -0,0 +1,44 @@ +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using Azure.ResourceManager; +using Azure.ClientGenerator.Core; + +namespace MgmtTypeSpec; + +@resource("foos") +model Foo is TrackedResource { + ...ResourceNameParameter; + + ...ExtendedLocationProperty; +} + +@useSystemTextJsonConverter("csharp") +model FooProperties { + /** the service url */ + serviceUrl?: url; + + /** something */ + something?: string; + + /** boolean value */ + boolValue?: boolean; + + /** float value */ + floatValue?: float32; + + /** double value */ + doubleValue?: float64; +} + +@armResourceOperations +interface Foos { + createOrUpdate is ArmResourceCreateOrUpdateAsync; + + get is ArmResourceRead; + + delete is ArmResourceDeleteWithoutOkAsync; + + list is ArmResourceListByParent; +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/main.tsp b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/main.tsp new file mode 100644 index 0000000000000..5340fa3f3c28e --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/main.tsp @@ -0,0 +1,25 @@ + +import "@azure-tools/typespec-azure-resource-manager"; +import "./PrivateEndpointConnection.tsp"; +import "./foo.tsp"; + +using TypeSpec.Versioning; +using Azure.ResourceManager; + +@armProviderNamespace +@service({ + title: "MgmtTestClient", +}) +@versioned(Versions) +@armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) +namespace MgmtTypeSpec; + +interface Operations extends Azure.ResourceManager.Operations {} + +/** The available API versions. */ +enum Versions { + /** Azure Cosmos DB for Mongo vCore clusters api version 2024-03-01-preview. */ + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @useDependency(Azure.Core.Versions.v1_0_Preview_1) + v2024_05_01: "2024-05-01", + } diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.RestClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.RestClient.cs new file mode 100644 index 0000000000000..3c86e4e4f41a7 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.RestClient.cs @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace MgmtTypeSpec +{ + /// + public partial class Foos + { + private static ResponseClassifier _pipelineMessageClassifier200; + private static ResponseClassifier _pipelineMessageClassifier201; + private static ResponseClassifier _pipelineMessageClassifier202; + private static ResponseClassifier _pipelineMessageClassifier204; + private static Classifier2xxAnd4xx _pipelineMessageClassifier2xxAnd4xx; + + private static ResponseClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 = new StatusCodeClassifier(stackalloc ushort[] { 200 }); + + private static ResponseClassifier PipelineMessageClassifier201 => _pipelineMessageClassifier201 = new StatusCodeClassifier(stackalloc ushort[] { 201 }); + + private static ResponseClassifier PipelineMessageClassifier202 => _pipelineMessageClassifier202 = new StatusCodeClassifier(stackalloc ushort[] { 202 }); + + private static ResponseClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 = new StatusCodeClassifier(stackalloc ushort[] { 204 }); + + private static Classifier2xxAnd4xx PipelineMessageClassifier2xxAnd4xx => _pipelineMessageClassifier2xxAnd4xx ??= new Classifier2xxAnd4xx(); + + internal HttpMessage CreateCreateOrUpdateRequest(string resourceGroupName, string fooName, RequestContent content, RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Method = RequestMethod.Put; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(_subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/MgmtTypeSpec/foos/", false); + uri.AppendPath(fooName, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Content-Type", "application/json"); + request.Headers.SetValue("Accept", "application/json"); + request.Content = content; + return message; + } + + internal HttpMessage CreateGetRequest(string resourceGroupName, string fooName, RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Method = RequestMethod.Get; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(_subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/MgmtTypeSpec/foos/", false); + uri.AppendPath(fooName, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateDeleteRequest(string resourceGroupName, string fooName, RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier202); + Request request = message.Request; + request.Method = RequestMethod.Delete; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(_subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/MgmtTypeSpec/foos/", false); + uri.AppendPath(fooName, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateListRequest(string resourceGroupName, RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Method = RequestMethod.Get; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(_subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/MgmtTypeSpec/foos", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + private class Classifier2xxAnd4xx : ResponseClassifier + { + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.cs new file mode 100644 index 0000000000000..d163d271d0ff6 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.cs @@ -0,0 +1,339 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using MgmtTypeSpec.Models; + +namespace MgmtTypeSpec +{ + /// + public partial class Foos + { + private readonly Uri _endpoint; + private readonly string _apiVersion; + private readonly Guid _subscriptionId; + + /// Initializes a new instance of Foos for mocking. + protected Foos() + { + } + + internal Foos(HttpPipeline pipeline, Uri endpoint, string apiVersion, Guid subscriptionId) + { + _endpoint = endpoint; + Pipeline = pipeline; + _apiVersion = apiVersion; + _subscriptionId = subscriptionId; + } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public HttpPipeline Pipeline { get; } + + /// + /// [Protocol Method] Create a Foo + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response CreateOrUpdate(string resourceGroupName, string fooName, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + Argument.AssertNotNull(content, nameof(content)); + + using HttpMessage message = CreateCreateOrUpdateRequest(resourceGroupName, fooName, content, context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] Create a Foo + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// , or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task CreateOrUpdateAsync(string resourceGroupName, string fooName, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + Argument.AssertNotNull(content, nameof(content)); + + using HttpMessage message = CreateCreateOrUpdateRequest(resourceGroupName, fooName, content, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// Create a Foo. + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// Resource create parameters. + /// , or is null. + /// Service returned a non-success status code. + public virtual Response CreateOrUpdate(string resourceGroupName, string fooName, Foo resource) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + Argument.AssertNotNull(resource, nameof(resource)); + + Response result = CreateOrUpdate(resourceGroupName, fooName, resource, context: null); + return Response.FromValue((Foo)result, result); + } + + /// Create a Foo. + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// Resource create parameters. + /// 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> CreateOrUpdateAsync(string resourceGroupName, string fooName, Foo resource, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + Argument.AssertNotNull(resource, nameof(resource)); + + Response result = await CreateOrUpdateAsync(resourceGroupName, fooName, resource, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return Response.FromValue((Foo)result, result); + } + + /// + /// [Protocol Method] Get a Foo + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response Get(string resourceGroupName, string fooName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + using HttpMessage message = CreateGetRequest(resourceGroupName, fooName, context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] Get a Foo + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetAsync(string resourceGroupName, string fooName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + using HttpMessage message = CreateGetRequest(resourceGroupName, fooName, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// Get a Foo. + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// or is null. + /// Service returned a non-success status code. + public virtual Response Get(string resourceGroupName, string fooName) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + Response result = Get(resourceGroupName, fooName, context: null); + return Response.FromValue((Foo)result, result); + } + + /// Get a Foo. + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// 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> GetAsync(string resourceGroupName, string fooName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + Response result = await GetAsync(resourceGroupName, fooName, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return Response.FromValue((Foo)result, result); + } + + /// + /// [Protocol Method] Delete a Foo + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response Delete(string resourceGroupName, string fooName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + using HttpMessage message = CreateDeleteRequest(resourceGroupName, fooName, context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] Delete a Foo + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task DeleteAsync(string resourceGroupName, string fooName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + using HttpMessage message = CreateDeleteRequest(resourceGroupName, fooName, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// Delete a Foo. + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// or is null. + /// Service returned a non-success status code. + public virtual Response Delete(string resourceGroupName, string fooName) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + return Delete(resourceGroupName, fooName, context: null); + } + + /// Delete a Foo. + /// The name of the resource group. The name is case insensitive. + /// The name of the Foo. + /// 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 DeleteAsync(string resourceGroupName, string fooName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(fooName, nameof(fooName)); + + return await DeleteAsync(resourceGroupName, fooName, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + + /// + /// [Protocol Method] List Foo resources by resource group + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response List(string resourceGroupName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + using HttpMessage message = CreateListRequest(resourceGroupName, context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] List Foo resources by resource group + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task ListAsync(string resourceGroupName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + using HttpMessage message = CreateListRequest(resourceGroupName, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// List Foo resources by resource group. + /// The name of the resource group. The name is case insensitive. + /// is null. + /// Service returned a non-success status code. + public virtual Response List(string resourceGroupName) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + Response result = List(resourceGroupName, context: null); + return Response.FromValue((FooListResult)result, result); + } + + /// List Foo resources by resource group. + /// The name of the resource group. The name is case insensitive. + /// The cancellation token that can be used to cancel the operation. + /// is null. + /// Service returned a non-success status code. + public virtual async Task> ListAsync(string resourceGroupName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + Response result = await ListAsync(resourceGroupName, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return Response.FromValue((FooListResult)result, result); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Argument.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Argument.cs new file mode 100644 index 0000000000000..1b6ccf85f3df2 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Argument.cs @@ -0,0 +1,129 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace MgmtTypeSpec +{ + internal static partial class Argument + { + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + + public static void AssertNotNullOrWhiteSpace(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); + } + } + + public static void AssertNotDefault(ref T value, string name) + where T : struct, IEquatable + { + if (value.Equals(default)) + { + throw new ArgumentException("Value cannot be empty.", name); + } + } + + public static void AssertInRange(T value, T minimum, T maximum, string name) + where T : notnull, IComparable + { + if (minimum.CompareTo(value) > 0) + { + throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); + } + if (maximum.CompareTo(value) < 0) + { + throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); + } + } + + public static void AssertEnumDefined(Type enumType, object value, string name) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); + } + } + + public static T CheckNotNull(T value, string name) + where T : class + { + AssertNotNull(value, name); + return value; + } + + public static string CheckNotNullOrEmpty(string value, string name) + { + AssertNotNullOrEmpty(value, name); + return value; + } + + public static void AssertNull(T value, string name, string message = null) + { + if (value != null) + { + throw new ArgumentException(message ?? "Value must be null.", name); + } + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 0000000000000..5acdb3569cc8b --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,168 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace MgmtTypeSpec +{ + internal partial class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary + where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + public bool IsUndefined => _innerDictionary == null; + + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 0000000000000..41d3b84aa3362 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace MgmtTypeSpec +{ + internal partial class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + public bool IsUndefined => _innerList == null; + + public int Count => IsUndefined ? 0 : EnsureList().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ClientPipelineExtensions.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ClientPipelineExtensions.cs new file mode 100644 index 0000000000000..da12bc8d2b0e7 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ClientPipelineExtensions.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace MgmtTypeSpec +{ + internal static partial class ClientPipelineExtensions + { + public static async ValueTask ProcessMessageAsync(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + (CancellationToken userCancellationToken, ErrorOptions statusOption) = context.Parse(); + await pipeline.SendAsync(message, userCancellationToken).ConfigureAwait(false); + + if (message.Response.IsError && (context?.ErrorOptions & ErrorOptions.NoThrow) != ErrorOptions.NoThrow) + { + throw new RequestFailedException(message.Response); + } + + return message.Response; + } + + public static Response ProcessMessage(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + (CancellationToken userCancellationToken, ErrorOptions statusOption) = context.Parse(); + pipeline.Send(message, userCancellationToken); + + if (message.Response.IsError && (context?.ErrorOptions & ErrorOptions.NoThrow) != ErrorOptions.NoThrow) + { + throw new RequestFailedException(message.Response); + } + + return message.Response; + } + + public static async ValueTask> ProcessHeadAsBoolMessageAsync(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + Response response = await pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + switch (response.Status) + { + case >= 200 and < 300: + return Response.FromValue(true, response); + case >= 400 and < 500: + return Response.FromValue(false, response); + default: + return new ErrorResult(response, new RequestFailedException(response)); + } + } + + public static Response ProcessHeadAsBoolMessage(this HttpPipeline pipeline, HttpMessage message, RequestContext context) + { + Response response = pipeline.ProcessMessage(message, context); + switch (response.Status) + { + case >= 200 and < 300: + return Response.FromValue(true, response); + case >= 400 and < 500: + return Response.FromValue(false, response); + default: + return new ErrorResult(response, new RequestFailedException(response)); + } + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ErrorResult.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ErrorResult.cs new file mode 100644 index 0000000000000..dde2d94820bf1 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ErrorResult.cs @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; + +namespace MgmtTypeSpec +{ + internal partial class ErrorResult : Response + { + private readonly Response _response; + private readonly RequestFailedException _exception; + + public ErrorResult(Response response, RequestFailedException exception) + { + _response = response; + _exception = exception; + } + + public override T Value => throw _exception; + + public override Response GetRawResponse() + { + return _response; + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ModelSerializationExtensions.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 0000000000000..ace6dc94b2307 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,254 @@ +// 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.Diagnostics; +using System.Globalization; +using System.Text.Json; + +namespace MgmtTypeSpec +{ + internal static partial class ModelSerializationExtensions + { + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + Dictionary dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + List list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + string text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty @property) + { + throw new JsonException($"A property '{@property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + string value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Optional.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Optional.cs new file mode 100644 index 0000000000000..211ca829d726f --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Optional.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace MgmtTypeSpec +{ + internal static partial class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(string value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/RequestContextExtensions.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/RequestContextExtensions.cs new file mode 100644 index 0000000000000..1389f2a57f778 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/RequestContextExtensions.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using Azure; + +namespace MgmtTypeSpec +{ + internal static partial class RequestContextExtensions + { + public static ValueTuple Parse(this RequestContext requestContext) + { + if (requestContext == null) + { + return (CancellationToken.None, ErrorOptions.Default); + } + return (requestContext.CancellationToken, requestContext.ErrorOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/TypeFormatters.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/TypeFormatters.cs new file mode 100644 index 0000000000000..f278d1694ec5b --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/TypeFormatters.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Xml; + +namespace MgmtTypeSpec +{ + internal static partial class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Generated clients require it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => System.Xml.XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked (value.Length + 2) / 3; + int size = checked (numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => System.Xml.XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => System.Xml.XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs new file mode 100644 index 0000000000000..280e6aef1e2ec --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace MgmtTypeSpec +{ + internal partial class Utf8JsonBinaryContent : RequestContent + { + private readonly MemoryStream _stream; + private readonly RequestContent _content; + + public Utf8JsonBinaryContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.RestClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.RestClient.cs new file mode 100644 index 0000000000000..db3cd03507c82 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.RestClient.cs @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.Core; + +namespace MgmtTypeSpec +{ + /// + public partial class MgmtTypeSpecClient + { + private static ResponseClassifier _pipelineMessageClassifier200; + private static ResponseClassifier _pipelineMessageClassifier201; + private static ResponseClassifier _pipelineMessageClassifier202; + private static ResponseClassifier _pipelineMessageClassifier204; + private static Classifier2xxAnd4xx _pipelineMessageClassifier2xxAnd4xx; + + private static ResponseClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 = new StatusCodeClassifier(stackalloc ushort[] { 200 }); + + private static ResponseClassifier PipelineMessageClassifier201 => _pipelineMessageClassifier201 = new StatusCodeClassifier(stackalloc ushort[] { 201 }); + + private static ResponseClassifier PipelineMessageClassifier202 => _pipelineMessageClassifier202 = new StatusCodeClassifier(stackalloc ushort[] { 202 }); + + private static ResponseClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 = new StatusCodeClassifier(stackalloc ushort[] { 204 }); + + private static Classifier2xxAnd4xx PipelineMessageClassifier2xxAnd4xx => _pipelineMessageClassifier2xxAnd4xx ??= new Classifier2xxAnd4xx(); + + private class Classifier2xxAnd4xx : ResponseClassifier + { + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.cs new file mode 100644 index 0000000000000..756512913ae8d --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClient.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using Azure.Core.Pipeline; + +namespace MgmtTypeSpec +{ + /// + public partial class MgmtTypeSpecClient + { + private readonly Uri _endpoint; + private Operations _cachedOperations; + private PrivateLinks _cachedPrivateLinks; + private Foos _cachedFoos; + + /// Initializes a new instance of MgmtTypeSpecClient. + public MgmtTypeSpecClient() : this(new Uri("https://management.azure.com"), new MgmtTypeSpecClientOptions()) + { + } + + /// Initializes a new instance of MgmtTypeSpecClient. + /// Service endpoint. + /// The options for configuring the client. + /// is null. + public MgmtTypeSpecClient(Uri endpoint, MgmtTypeSpecClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + + options ??= new MgmtTypeSpecClientOptions(); + + _endpoint = endpoint; + Pipeline = HttpPipelineBuilder.Build(options, Array.Empty()); + } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public HttpPipeline Pipeline { get; } + + /// Initializes a new instance of Operations. + public virtual Operations GetOperationsClient() + { + return Volatile.Read(ref _cachedOperations) ?? Interlocked.CompareExchange(ref _cachedOperations, new Operations(Pipeline, _endpoint), null) ?? _cachedOperations; + } + + /// Initializes a new instance of PrivateLinks. + public virtual PrivateLinks GetPrivateLinksClient() + { + return Volatile.Read(ref _cachedPrivateLinks) ?? Interlocked.CompareExchange(ref _cachedPrivateLinks, new PrivateLinks(Pipeline, _endpoint), null) ?? _cachedPrivateLinks; + } + + /// Initializes a new instance of Foos. + public virtual Foos GetFoosClient() + { + return Volatile.Read(ref _cachedFoos) ?? Interlocked.CompareExchange(ref _cachedFoos, new Foos(Pipeline, _endpoint), null) ?? _cachedFoos; + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClientOptions.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClientOptions.cs new file mode 100644 index 0000000000000..3165895bf52be --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecClientOptions.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using Azure.Core; + +namespace MgmtTypeSpec +{ + /// Client options for . + public partial class MgmtTypeSpecClientOptions : ClientOptions + { + private const ServiceVersion LatestVersion = ServiceVersion.V2024_05_01; + + /// Initializes a new instance of MgmtTypeSpecClientOptions. + /// The service version. + public MgmtTypeSpecClientOptions(ServiceVersion version = LatestVersion) + { + Version = version switch + { + ServiceVersion.V2024_05_01 => "2024-05-01", + _ => throw new NotSupportedException() + }; + } + + internal string Version { get; } + + /// The version of the service to use. + public enum ServiceVersion + { + /// Azure Cosmos DB for Mongo vCore clusters api version 2024-03-01-preview. + V2024_05_01 = 1 + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecModelFactory.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecModelFactory.cs new file mode 100644 index 0000000000000..f70ebc6187e5f --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/MgmtTypeSpecModelFactory.cs @@ -0,0 +1,271 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// A factory class for creating instances of the models for mocking. + public static partial class MgmtTypeSpecModelFactory + { + /// Concrete tracked resource types can be created by aliasing this type using a specific property type. + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// Resource tags. + /// The geo-location where the resource lives. + /// The resource-specific properties for this resource. + /// + /// A new instance for mocking. + public static Foo Foo(ResourceIdentifier id = default, string name = default, string @type = default, SystemData systemData = default, IDictionary tags = default, string location = default, FooProperties properties = default, ExtendedLocation extendedLocation = default) + { + tags ??= new ChangeTrackingDictionary(); + + return new Foo( + id, + name, + @type, + systemData, + additionalBinaryDataProperties: null, + tags, + location, + properties, + extendedLocation); + } + + /// The FooProperties. + /// the service url. + /// something. + /// boolean value. + /// float value. + /// double value. + /// A new instance for mocking. + public static FooProperties FooProperties(Uri serviceUrl = default, string something = default, bool? boolValue = default, float? floatValue = default, double? doubleValue = default) + { + + return new FooProperties( + serviceUrl, + something, + boolValue, + floatValue, + doubleValue, + additionalBinaryDataProperties: null); + } + + /// The complex type of the extended location. + /// The name of the extended location. + /// The type of the extended location. + /// A new instance for mocking. + public static ExtendedLocation ExtendedLocation(string name = default, ExtendedLocationType @type = default) + { + + return new ExtendedLocation(name, @type, additionalBinaryDataProperties: null); + } + + /// The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'. + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// Resource tags. + /// The geo-location where the resource lives. + /// A new instance for mocking. + public static TrackedResource TrackedResource(ResourceIdentifier id = default, string name = default, string @type = default, SystemData systemData = default, IDictionary tags = default, string location = default) + { + tags ??= new ChangeTrackingDictionary(); + + return new TrackedResource( + id, + name, + @type, + systemData, + additionalBinaryDataProperties: null, + tags, + location); + } + + /// Common fields that are returned in the response for all Azure Resource Manager resources. + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// A new instance for mocking. + public static Resource Resource(ResourceIdentifier id = default, string name = default, string @type = default, SystemData systemData = default) + { + + return new Resource(id, name, @type, systemData, additionalBinaryDataProperties: null); + } + + /// Metadata pertaining to creation and last modification of the resource. + /// The identity that created the resource. + /// The type of identity that created the resource. + /// The timestamp of resource creation (UTC). + /// The identity that last modified the resource. + /// The type of identity that last modified the resource. + /// The timestamp of resource last modification (UTC). + /// A new instance for mocking. + public static SystemData SystemData(string createdBy = default, CreatedByType? createdByType = default, DateTimeOffset? createdAt = default, string lastModifiedBy = default, CreatedByType? lastModifiedByType = default, DateTimeOffset? lastModifiedAt = default) + { + + return new SystemData( + createdBy, + createdByType, + createdAt, + lastModifiedBy, + lastModifiedByType, + lastModifiedAt, + additionalBinaryDataProperties: null); + } + + /// The response of a Foo list operation. + /// The Foo items on this page. + /// The link to the next page of items. + /// A new instance for mocking. + public static FooListResult FooListResult(IEnumerable value = default, Uri nextLink = default) + { + value ??= new ChangeTrackingList(); + + return new FooListResult(value?.ToList(), nextLink, additionalBinaryDataProperties: null); + } + + /// The response of a PrivateLinkResource list operation. + /// The PrivateLinkResource items on this page. + /// The link to the next page of items. + /// A new instance for mocking. + public static PrivateLinkResourceListResult PrivateLinkResourceListResult(IEnumerable value = default, Uri nextLink = default) + { + value ??= new ChangeTrackingList(); + + return new PrivateLinkResourceListResult(value?.ToList(), nextLink, additionalBinaryDataProperties: null); + } + + /// Concrete proxy resource types can be created by aliasing this type using a specific property type. + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// The resource-specific properties for this resource. + /// The managed service identities assigned to this resource. + /// A new instance for mocking. + public static PrivateLinkResource PrivateLinkResource(ResourceIdentifier id = default, string name = default, string @type = default, SystemData systemData = default, PrivateLinkResourceProperties properties = default, ManagedServiceIdentity identity = default) + { + + return new PrivateLinkResource( + id, + name, + @type, + systemData, + additionalBinaryDataProperties: null, + properties, + identity); + } + + /// Properties of a private link resource. + /// The private link resource group id. + /// The private link resource required member names. + /// The private link resource private link DNS zone name. + /// A new instance for mocking. + public static PrivateLinkResourceProperties PrivateLinkResourceProperties(string groupId = default, IEnumerable requiredMembers = default, IEnumerable requiredZoneNames = default) + { + requiredMembers ??= new ChangeTrackingList(); + requiredZoneNames ??= new ChangeTrackingList(); + + return new PrivateLinkResourceProperties(groupId, requiredMembers?.ToList(), requiredZoneNames?.ToList(), additionalBinaryDataProperties: null); + } + + /// Managed service identity (system assigned and/or user assigned identities). + /// The service principal ID of the system assigned identity. This property will only be provided for a system assigned identity. + /// The tenant ID of the system assigned identity. This property will only be provided for a system assigned identity. + /// The type of managed identity assigned to this resource. + /// The identities assigned to this resource by the user. + /// A new instance for mocking. + public static ManagedServiceIdentity ManagedServiceIdentity(Guid? principalId = default, Guid? tenantId = default, ManagedServiceIdentityType @type = default, IDictionary userAssignedIdentities = default) + { + userAssignedIdentities ??= new ChangeTrackingDictionary(); + + return new ManagedServiceIdentity(principalId, tenantId, @type, userAssignedIdentities, additionalBinaryDataProperties: null); + } + + /// User assigned identity properties. + /// The principal ID of the assigned identity. + /// The client ID of the assigned identity. + /// A new instance for mocking. + public static UserAssignedIdentity UserAssignedIdentity(Guid? principalId = default, Guid? clientId = default) + { + + return new UserAssignedIdentity(principalId, clientId, additionalBinaryDataProperties: null); + } + + /// The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location. + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + /// The name of the resource. + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + /// A new instance for mocking. + public static ProxyResource ProxyResource(ResourceIdentifier id = default, string name = default, string @type = default, SystemData systemData = default) + { + + return new ProxyResource(id, name, @type, systemData, additionalBinaryDataProperties: null); + } + + /// Start SAP instance(s) request body. + /// The boolean value indicates whether to start the virtual machines before starting the SAP instances. + /// A new instance for mocking. + public static StartRequest StartRequest(bool? startVm = default) + { + + return new StartRequest(startVm, additionalBinaryDataProperties: null); + } + + /// A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. + /// The Operation items on this page. + /// The link to the next page of items. + /// A new instance for mocking. + public static OperationListResult OperationListResult(IEnumerable value = default, Uri nextLink = default) + { + value ??= new ChangeTrackingList(); + + return new OperationListResult(value?.ToList(), nextLink, additionalBinaryDataProperties: null); + } + + /// Details of a REST API operation, returned from the Resource Provider Operations API. + /// The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + /// Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. + /// Localized display information for this particular operation. + /// The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system". + /// Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + /// A new instance for mocking. + public static Operation Operation(string name = default, bool? isDataAction = default, OperationDisplay display = default, Origin? origin = default, ActionType? actionType = default) + { + + return new Operation( + name, + isDataAction, + display, + origin, + actionType, + additionalBinaryDataProperties: null); + } + + /// Localized display information for and operation. + /// The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". + /// The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". + /// The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". + /// The short, localized friendly description of the operation; suitable for tool tips and detailed views. + /// A new instance for mocking. + public static OperationDisplay OperationDisplay(string provider = default, string resource = default, string operation = default, string description = default) + { + + return new OperationDisplay(provider, resource, operation, description, additionalBinaryDataProperties: null); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ActionType.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ActionType.cs new file mode 100644 index 0000000000000..d354f8cb41dfe --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ActionType.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + public readonly partial struct ActionType : IEquatable + { + private readonly string _value; + /// Actions are for internal-only APIs. + private const string InternalValue = "Internal"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public ActionType(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// Actions are for internal-only APIs. + public static ActionType Internal { get; } = new ActionType(InternalValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(ActionType left, ActionType right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(ActionType left, ActionType right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator ActionType(string value) => new ActionType(value); + + /// The object to compare. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ActionType other && Equals(other); + + /// The instance to compare. + public bool Equals(ActionType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/CreatedByType.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/CreatedByType.cs new file mode 100644 index 0000000000000..95c57771943c7 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/CreatedByType.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// The kind of entity that created the resource. + public readonly partial struct CreatedByType : IEquatable + { + private readonly string _value; + /// The entity was created by a user. + private const string UserValue = "User"; + /// The entity was created by an application. + private const string ApplicationValue = "Application"; + /// The entity was created by a managed identity. + private const string ManagedIdentityValue = "ManagedIdentity"; + /// The entity was created by a key. + private const string KeyValue = "Key"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public CreatedByType(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// The entity was created by a user. + public static CreatedByType User { get; } = new CreatedByType(UserValue); + + /// The entity was created by an application. + public static CreatedByType Application { get; } = new CreatedByType(ApplicationValue); + + /// The entity was created by a managed identity. + public static CreatedByType ManagedIdentity { get; } = new CreatedByType(ManagedIdentityValue); + + /// The entity was created by a key. + public static CreatedByType Key { get; } = new CreatedByType(KeyValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(CreatedByType left, CreatedByType right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(CreatedByType left, CreatedByType right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator CreatedByType(string value) => new CreatedByType(value); + + /// The object to compare. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is CreatedByType other && Equals(other); + + /// The instance to compare. + public bool Equals(CreatedByType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.Serialization.cs new file mode 100644 index 0000000000000..d645ccd289d94 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.Serialization.cs @@ -0,0 +1,162 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class ExtendedLocation : IJsonModel + { + internal ExtendedLocation() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExtendedLocation)} does not support writing '{format}' format."); + } + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + ExtendedLocation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual ExtendedLocation JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ExtendedLocation)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeExtendedLocation(document.RootElement, options); + } + + internal static ExtendedLocation DeserializeExtendedLocation(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + ExtendedLocationType @type = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = new ExtendedLocationType(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new ExtendedLocation(name, @type, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ExtendedLocation)} does not support writing '{options.Format}' format."); + } + } + + ExtendedLocation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual ExtendedLocation PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeExtendedLocation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ExtendedLocation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(ExtendedLocation extendedLocation) + { + if (extendedLocation == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(extendedLocation, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator ExtendedLocation(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeExtendedLocation(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.cs new file mode 100644 index 0000000000000..4f031dcbe4ff8 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocation.cs @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// The complex type of the extended location. + public partial class ExtendedLocation + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + /// The name of the extended location. + /// The type of the extended location. + /// is null. + public ExtendedLocation(string name, ExtendedLocationType @type) + { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + Type = @type; + } + + internal ExtendedLocation(string name, ExtendedLocationType @type, IDictionary additionalBinaryDataProperties) + { + Name = name; + Type = @type; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The name of the extended location. + public string Name { get; set; } + + /// The type of the extended location. + public ExtendedLocationType Type { get; set; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocationType.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocationType.cs new file mode 100644 index 0000000000000..14d6122eab046 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ExtendedLocationType.cs @@ -0,0 +1,67 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// The supported ExtendedLocation types. + public readonly partial struct ExtendedLocationType : IEquatable + { + private readonly string _value; + /// Azure Edge Zones location type. + private const string EdgeZoneValue = "EdgeZone"; + /// Azure Custom Locations type. + private const string CustomLocationValue = "CustomLocation"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public ExtendedLocationType(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// Azure Edge Zones location type. + public static ExtendedLocationType EdgeZone { get; } = new ExtendedLocationType(EdgeZoneValue); + + /// Azure Custom Locations type. + public static ExtendedLocationType CustomLocation { get; } = new ExtendedLocationType(CustomLocationValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(ExtendedLocationType left, ExtendedLocationType right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(ExtendedLocationType left, ExtendedLocationType right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator ExtendedLocationType(string value) => new ExtendedLocationType(value); + + /// The object to compare. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ExtendedLocationType other && Equals(other); + + /// The instance to compare. + public bool Equals(ExtendedLocationType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.Serialization.cs new file mode 100644 index 0000000000000..8369f00f87c54 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.Serialization.cs @@ -0,0 +1,231 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class Foo : IJsonModel + { + internal Foo() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Foo)} does not support writing '{format}' format."); + } + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Properties)) + { + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); + } + if (Optional.IsDefined(ExtendedLocation)) + { + writer.WritePropertyName("extendedLocation"u8); + writer.WriteObjectValue(ExtendedLocation, options); + } + } + + Foo IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (Foo)JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected override Resource JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Foo)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFoo(document.RootElement, options); + } + + internal static Foo DeserializeFoo(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + string @type = default; + SystemData systemData = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + IDictionary tags = default; + string location = default; + FooProperties properties = default; + ExtendedLocation extendedLocation = default; + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + id = new ResourceIdentifier(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("systemData"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = SystemData.DeserializeSystemData(prop.Value, options); + continue; + } + if (prop.NameEquals("tags"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var prop0 in prop.Value.EnumerateObject()) + { + if (prop0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(prop0.Name, null); + } + else + { + dictionary.Add(prop0.Name, prop0.Value.GetString()); + } + } + tags = dictionary; + continue; + } + if (prop.NameEquals("location"u8)) + { + location = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("properties"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = FooProperties.DeserializeFooProperties(prop.Value, options); + continue; + } + if (prop.NameEquals("extendedLocation"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + extendedLocation = ExtendedLocation.DeserializeExtendedLocation(prop.Value, options); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new Foo( + id, + name, + @type, + systemData, + additionalBinaryDataProperties, + tags ?? new ChangeTrackingDictionary(), + location, + properties, + extendedLocation); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + 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(Foo)} does not support writing '{options.Format}' format."); + } + } + + Foo IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => (Foo)PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected override Resource PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeFoo(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Foo)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(Foo foo) + { + if (foo == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(foo, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator Foo(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeFoo(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.cs new file mode 100644 index 0000000000000..1941d67def4ea --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Foo.cs @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// Concrete tracked resource types can be created by aliasing this type using a specific property type. + public partial class Foo : TrackedResource + { + /// Initializes a new instance of . + /// The geo-location where the resource lives. + /// is null. + public Foo(string location) : base(location) + { + Argument.AssertNotNull(location, nameof(location)); + + } + + internal Foo(ResourceIdentifier id, string name, string @type, SystemData systemData, IDictionary additionalBinaryDataProperties, IDictionary tags, string location, FooProperties properties, ExtendedLocation extendedLocation) : base(id, name, @type, systemData, additionalBinaryDataProperties, tags, location) + { + Properties = properties; + ExtendedLocation = extendedLocation; + } + + /// The resource-specific properties for this resource. + public FooProperties Properties { get; set; } + + /// Gets or sets the ExtendedLocation. + public ExtendedLocation ExtendedLocation { get; set; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.Serialization.cs new file mode 100644 index 0000000000000..f9efefbf6649a --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.Serialization.cs @@ -0,0 +1,179 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class FooListResult : IJsonModel + { + internal FooListResult() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(FooListResult)} does not support writing '{format}' format."); + } + writer.WritePropertyName("value"u8); + writer.WriteStartArray(); + foreach (Foo item in Value) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (Optional.IsDefined(NextLink)) + { + writer.WritePropertyName("nextLink"u8); + writer.WriteStringValue(NextLink.AbsoluteUri); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FooListResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual FooListResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FooListResult)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFooListResult(document.RootElement, options); + } + + internal static FooListResult DeserializeFooListResult(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList value = default; + Uri nextLink = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("value"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(Foo.DeserializeFoo(item, options)); + } + value = array; + continue; + } + if (prop.NameEquals("nextLink"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nextLink = new Uri(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new FooListResult(value, nextLink, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(FooListResult)} does not support writing '{options.Format}' format."); + } + } + + FooListResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual FooListResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeFooListResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FooListResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(FooListResult fooListResult) + { + if (fooListResult == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(fooListResult, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator FooListResult(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeFooListResult(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.cs new file mode 100644 index 0000000000000..d697c26d59899 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooListResult.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MgmtTypeSpec.Models +{ + /// The response of a Foo list operation. + public partial class FooListResult + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal FooListResult(IEnumerable value) + { + Value = value.ToList(); + } + + internal FooListResult(IList value, Uri nextLink, IDictionary additionalBinaryDataProperties) + { + Value = value; + NextLink = nextLink; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The Foo items on this page. + public IList Value { get; } + + /// The link to the next page of items. + public Uri NextLink { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.Serialization.cs new file mode 100644 index 0000000000000..a5b98bd8d5f12 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.Serialization.cs @@ -0,0 +1,219 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class FooProperties : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(FooProperties)} does not support writing '{format}' format."); + } + if (Optional.IsDefined(ServiceUrl)) + { + writer.WritePropertyName("serviceUrl"u8); + writer.WriteStringValue(ServiceUrl.AbsoluteUri); + } + if (Optional.IsDefined(Something)) + { + writer.WritePropertyName("something"u8); + writer.WriteStringValue(Something); + } + if (Optional.IsDefined(BoolValue)) + { + writer.WritePropertyName("boolValue"u8); + writer.WriteBooleanValue(BoolValue.Value); + } + if (Optional.IsDefined(FloatValue)) + { + writer.WritePropertyName("floatValue"u8); + writer.WriteNumberValue(FloatValue.Value); + } + if (Optional.IsDefined(DoubleValue)) + { + writer.WritePropertyName("doubleValue"u8); + writer.WriteNumberValue(DoubleValue.Value); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FooProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual FooProperties JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FooProperties)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFooProperties(document.RootElement, options); + } + + internal static FooProperties DeserializeFooProperties(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Uri serviceUrl = default; + string something = default; + bool? boolValue = default; + float? floatValue = default; + double? doubleValue = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("serviceUrl"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + serviceUrl = new Uri(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("something"u8)) + { + something = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("boolValue"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + boolValue = prop.Value.GetBoolean(); + continue; + } + if (prop.NameEquals("floatValue"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + floatValue = prop.Value.GetSingle(); + continue; + } + if (prop.NameEquals("doubleValue"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + doubleValue = prop.Value.GetDouble(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new FooProperties( + serviceUrl, + something, + boolValue, + floatValue, + doubleValue, + additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(FooProperties)} does not support writing '{options.Format}' format."); + } + } + + FooProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual FooProperties PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeFooProperties(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FooProperties)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(FooProperties fooProperties) + { + if (fooProperties == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(fooProperties, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator FooProperties(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeFooProperties(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.cs new file mode 100644 index 0000000000000..347b9382213b8 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/FooProperties.cs @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace MgmtTypeSpec.Models +{ + /// The FooProperties. + public partial class FooProperties + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public FooProperties() + { + } + + internal FooProperties(Uri serviceUrl, string something, bool? boolValue, float? floatValue, double? doubleValue, IDictionary additionalBinaryDataProperties) + { + ServiceUrl = serviceUrl; + Something = something; + BoolValue = boolValue; + FloatValue = floatValue; + DoubleValue = doubleValue; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// the service url. + public Uri ServiceUrl { get; set; } + + /// something. + public string Something { get; set; } + + /// boolean value. + public bool? BoolValue { get; set; } + + /// float value. + public float? FloatValue { get; set; } + + /// double value. + public double? DoubleValue { get; set; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.Serialization.cs new file mode 100644 index 0000000000000..3f7f459f876d8 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.Serialization.cs @@ -0,0 +1,210 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class ManagedServiceIdentity : IJsonModel + { + internal ManagedServiceIdentity() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(ManagedServiceIdentity)} does not support writing '{format}' format."); + } + if (options.Format != "W" && Optional.IsDefined(PrincipalId)) + { + writer.WritePropertyName("principalId"u8); + writer.WriteStringValue(PrincipalId.Value); + } + if (options.Format != "W" && Optional.IsDefined(TenantId)) + { + writer.WritePropertyName("tenantId"u8); + writer.WriteStringValue(TenantId.Value); + } + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + if (Optional.IsCollectionDefined(UserAssignedIdentities)) + { + writer.WritePropertyName("userAssignedIdentities"u8); + writer.WriteStartObject(); + foreach (var item in UserAssignedIdentities) + { + writer.WritePropertyName(item.Key); + writer.WriteObjectValue(item.Value, options); + } + writer.WriteEndObject(); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + ManagedServiceIdentity IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual ManagedServiceIdentity JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ManagedServiceIdentity)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeManagedServiceIdentity(document.RootElement, options); + } + + internal static ManagedServiceIdentity DeserializeManagedServiceIdentity(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Guid? principalId = default; + Guid? tenantId = default; + ManagedServiceIdentityType @type = default; + IDictionary userAssignedIdentities = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("principalId"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + principalId = prop.Value.GetGuid(); + continue; + } + if (prop.NameEquals("tenantId"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + tenantId = prop.Value.GetGuid(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = new ManagedServiceIdentityType(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("userAssignedIdentities"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var prop0 in prop.Value.EnumerateObject()) + { + dictionary.Add(prop0.Name, UserAssignedIdentity.DeserializeUserAssignedIdentity(prop0.Value, options)); + } + userAssignedIdentities = dictionary; + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new ManagedServiceIdentity(principalId, tenantId, @type, userAssignedIdentities ?? new ChangeTrackingDictionary(), additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ManagedServiceIdentity)} does not support writing '{options.Format}' format."); + } + } + + ManagedServiceIdentity IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual ManagedServiceIdentity PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeManagedServiceIdentity(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ManagedServiceIdentity)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(ManagedServiceIdentity managedServiceIdentity) + { + if (managedServiceIdentity == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(managedServiceIdentity, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator ManagedServiceIdentity(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeManagedServiceIdentity(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.cs new file mode 100644 index 0000000000000..2f77797a27e3c --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentity.cs @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// Managed service identity (system assigned and/or user assigned identities). + public partial class ManagedServiceIdentity + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal ManagedServiceIdentity(ManagedServiceIdentityType @type) + { + Type = @type; + UserAssignedIdentities = new ChangeTrackingDictionary(); + } + + internal ManagedServiceIdentity(Guid? principalId, Guid? tenantId, ManagedServiceIdentityType @type, IDictionary userAssignedIdentities, IDictionary additionalBinaryDataProperties) + { + PrincipalId = principalId; + TenantId = tenantId; + Type = @type; + UserAssignedIdentities = userAssignedIdentities; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The service principal ID of the system assigned identity. This property will only be provided for a system assigned identity. + public Guid? PrincipalId { get; } + + /// The tenant ID of the system assigned identity. This property will only be provided for a system assigned identity. + public Guid? TenantId { get; } + + /// The type of managed identity assigned to this resource. + public ManagedServiceIdentityType Type { get; } + + /// The identities assigned to this resource by the user. + public IDictionary UserAssignedIdentities { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentityType.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentityType.cs new file mode 100644 index 0000000000000..053f3ff5e0ecd --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ManagedServiceIdentityType.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// Type of managed service identity (where both SystemAssigned and UserAssigned types are allowed). + public readonly partial struct ManagedServiceIdentityType : IEquatable + { + private readonly string _value; + /// No managed identity. + private const string NoneValue = "None"; + /// System assigned managed identity. + private const string SystemAssignedValue = "SystemAssigned"; + /// User assigned managed identity. + private const string UserAssignedValue = "UserAssigned"; + /// System and user assigned managed identity. + private const string SystemAndUserAssignedValue = "SystemAssigned,UserAssigned"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public ManagedServiceIdentityType(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// No managed identity. + public static ManagedServiceIdentityType None { get; } = new ManagedServiceIdentityType(NoneValue); + + /// System assigned managed identity. + public static ManagedServiceIdentityType SystemAssigned { get; } = new ManagedServiceIdentityType(SystemAssignedValue); + + /// User assigned managed identity. + public static ManagedServiceIdentityType UserAssigned { get; } = new ManagedServiceIdentityType(UserAssignedValue); + + /// System and user assigned managed identity. + public static ManagedServiceIdentityType SystemAndUserAssigned { get; } = new ManagedServiceIdentityType(SystemAndUserAssignedValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(ManagedServiceIdentityType left, ManagedServiceIdentityType right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(ManagedServiceIdentityType left, ManagedServiceIdentityType right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator ManagedServiceIdentityType(string value) => new ManagedServiceIdentityType(value); + + /// The object to compare. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ManagedServiceIdentityType other && Equals(other); + + /// The instance to compare. + public bool Equals(ManagedServiceIdentityType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.Serialization.cs new file mode 100644 index 0000000000000..67aae76a3719c --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.Serialization.cs @@ -0,0 +1,219 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class Operation : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(Operation)} does not support writing '{format}' format."); + } + if (options.Format != "W" && Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (options.Format != "W" && Optional.IsDefined(IsDataAction)) + { + writer.WritePropertyName("isDataAction"u8); + writer.WriteBooleanValue(IsDataAction.Value); + } + if (options.Format != "W" && Optional.IsDefined(Display)) + { + writer.WritePropertyName("display"u8); + writer.WriteObjectValue(Display, options); + } + if (options.Format != "W" && Optional.IsDefined(Origin)) + { + writer.WritePropertyName("origin"u8); + writer.WriteStringValue(Origin.Value.ToString()); + } + if (Optional.IsDefined(ActionType)) + { + writer.WritePropertyName("actionType"u8); + writer.WriteStringValue(ActionType.Value.ToString()); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + Operation IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual Operation JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Operation)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOperation(document.RootElement, options); + } + + internal static Operation DeserializeOperation(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + bool? isDataAction = default; + OperationDisplay display = default; + Origin? origin = default; + ActionType? actionType = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("isDataAction"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + isDataAction = prop.Value.GetBoolean(); + continue; + } + if (prop.NameEquals("display"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + display = OperationDisplay.DeserializeOperationDisplay(prop.Value, options); + continue; + } + if (prop.NameEquals("origin"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + origin = new Origin(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("actionType"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + actionType = new ActionType(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new Operation( + name, + isDataAction, + display, + origin, + actionType, + additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Operation)} does not support writing '{options.Format}' format."); + } + } + + Operation IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual Operation PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeOperation(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Operation)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(Operation operation) + { + if (operation == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(operation, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator Operation(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeOperation(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.cs new file mode 100644 index 0000000000000..f13616979a44e --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Operation.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace MgmtTypeSpec.Models +{ + /// Details of a REST API operation, returned from the Resource Provider Operations API. + public partial class Operation + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal Operation() + { + } + + internal Operation(string name, bool? isDataAction, OperationDisplay display, Origin? origin, ActionType? actionType, IDictionary additionalBinaryDataProperties) + { + Name = name; + IsDataAction = isDataAction; + Display = display; + Origin = origin; + ActionType = actionType; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The name of the operation, as per Resource-Based Access Control (RBAC). Examples: "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + public string Name { get; } + + /// Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure Resource Manager/control-plane operations. + public bool? IsDataAction { get; } + + /// Localized display information for this particular operation. + public OperationDisplay Display { get; } + + /// The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system". + public Origin? Origin { get; } + + /// Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + public ActionType? ActionType { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.Serialization.cs new file mode 100644 index 0000000000000..7a83538cc351a --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.Serialization.cs @@ -0,0 +1,186 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class OperationDisplay : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(OperationDisplay)} does not support writing '{format}' format."); + } + if (options.Format != "W" && Optional.IsDefined(Provider)) + { + writer.WritePropertyName("provider"u8); + writer.WriteStringValue(Provider); + } + if (options.Format != "W" && Optional.IsDefined(Resource)) + { + writer.WritePropertyName("resource"u8); + writer.WriteStringValue(Resource); + } + if (options.Format != "W" && Optional.IsDefined(Operation)) + { + writer.WritePropertyName("operation"u8); + writer.WriteStringValue(Operation); + } + if (options.Format != "W" && Optional.IsDefined(Description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(Description); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + OperationDisplay IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual OperationDisplay JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OperationDisplay)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOperationDisplay(document.RootElement, options); + } + + internal static OperationDisplay DeserializeOperationDisplay(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string provider = default; + string resource = default; + string operation = default; + string description = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("provider"u8)) + { + provider = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("resource"u8)) + { + resource = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("operation"u8)) + { + operation = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("description"u8)) + { + description = prop.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new OperationDisplay(provider, resource, operation, description, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(OperationDisplay)} does not support writing '{options.Format}' format."); + } + } + + OperationDisplay IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual OperationDisplay PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeOperationDisplay(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OperationDisplay)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(OperationDisplay operationDisplay) + { + if (operationDisplay == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(operationDisplay, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator OperationDisplay(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeOperationDisplay(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.cs new file mode 100644 index 0000000000000..85ba0f3ac1be0 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationDisplay.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace MgmtTypeSpec.Models +{ + /// Localized display information for and operation. + public partial class OperationDisplay + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal OperationDisplay() + { + } + + internal OperationDisplay(string provider, string resource, string operation, string description, IDictionary additionalBinaryDataProperties) + { + Provider = provider; + Resource = resource; + Operation = operation; + Description = description; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or "Microsoft Compute". + public string Provider { get; } + + /// The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or "Job Schedule Collections". + public string Resource { get; } + + /// The concise, localized friendly name for the operation; suitable for dropdowns. E.g. "Create or Update Virtual Machine", "Restart Virtual Machine". + public string Operation { get; } + + /// The short, localized friendly description of the operation; suitable for tool tips and detailed views. + public string Description { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.Serialization.cs new file mode 100644 index 0000000000000..b5ba0b53122f6 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.Serialization.cs @@ -0,0 +1,179 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class OperationListResult : IJsonModel + { + internal OperationListResult() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(OperationListResult)} does not support writing '{format}' format."); + } + writer.WritePropertyName("value"u8); + writer.WriteStartArray(); + foreach (Operation item in Value) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (Optional.IsDefined(NextLink)) + { + writer.WritePropertyName("nextLink"u8); + writer.WriteStringValue(NextLink.AbsoluteUri); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + OperationListResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual OperationListResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(OperationListResult)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeOperationListResult(document.RootElement, options); + } + + internal static OperationListResult DeserializeOperationListResult(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList value = default; + Uri nextLink = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("value"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(Operation.DeserializeOperation(item, options)); + } + value = array; + continue; + } + if (prop.NameEquals("nextLink"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nextLink = new Uri(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new OperationListResult(value, nextLink, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(OperationListResult)} does not support writing '{options.Format}' format."); + } + } + + OperationListResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual OperationListResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeOperationListResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(OperationListResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(OperationListResult operationListResult) + { + if (operationListResult == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(operationListResult, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator OperationListResult(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeOperationListResult(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.cs new file mode 100644 index 0000000000000..d1cc40558c3c2 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/OperationListResult.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MgmtTypeSpec.Models +{ + /// A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results. + public partial class OperationListResult + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal OperationListResult(IEnumerable value) + { + Value = value.ToList(); + } + + internal OperationListResult(IList value, Uri nextLink, IDictionary additionalBinaryDataProperties) + { + Value = value; + NextLink = nextLink; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The Operation items on this page. + public IList Value { get; } + + /// The link to the next page of items. + public Uri NextLink { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Origin.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Origin.cs new file mode 100644 index 0000000000000..c960e3908a652 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Origin.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ComponentModel; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is "user,system". + public readonly partial struct Origin : IEquatable + { + private readonly string _value; + /// Indicates the operation is initiated by a user. + private const string UserValue = "user"; + /// Indicates the operation is initiated by a system. + private const string SystemValue = "system"; + /// Indicates the operation is initiated by a user or system. + private const string UserSystemValue = "user,system"; + + /// Initializes a new instance of . + /// The value. + /// is null. + public Origin(string value) + { + Argument.AssertNotNull(value, nameof(value)); + + _value = value; + } + + /// Indicates the operation is initiated by a user. + public static Origin User { get; } = new Origin(UserValue); + + /// Indicates the operation is initiated by a system. + public static Origin System { get; } = new Origin(SystemValue); + + /// Indicates the operation is initiated by a user or system. + public static Origin UserSystem { get; } = new Origin(UserSystemValue); + + /// Determines if two values are the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator ==(Origin left, Origin right) => left.Equals(right); + + /// Determines if two values are not the same. + /// The left value to compare. + /// The right value to compare. + public static bool operator !=(Origin left, Origin right) => !left.Equals(right); + + /// Converts a string to a . + /// The value. + public static implicit operator Origin(string value) => new Origin(value); + + /// The object to compare. + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is Origin other && Equals(other); + + /// The instance to compare. + public bool Equals(Origin other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + + /// + public override string ToString() => _value; + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.Serialization.cs new file mode 100644 index 0000000000000..6156918d9624c --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.Serialization.cs @@ -0,0 +1,197 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class PrivateLinkResource : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PrivateLinkResource)} does not support writing '{format}' format."); + } + base.JsonModelWriteCore(writer, options); + if (Optional.IsDefined(Properties)) + { + writer.WritePropertyName("properties"u8); + writer.WriteObjectValue(Properties, options); + } + if (Optional.IsDefined(Identity)) + { + writer.WritePropertyName("identity"u8); + writer.WriteObjectValue(Identity, options); + } + } + + PrivateLinkResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (PrivateLinkResource)JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected override Resource JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PrivateLinkResource)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePrivateLinkResource(document.RootElement, options); + } + + internal static PrivateLinkResource DeserializePrivateLinkResource(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + string @type = default; + SystemData systemData = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + PrivateLinkResourceProperties properties = default; + ManagedServiceIdentity identity = default; + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + id = new ResourceIdentifier(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("systemData"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = SystemData.DeserializeSystemData(prop.Value, options); + continue; + } + if (prop.NameEquals("properties"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + properties = PrivateLinkResourceProperties.DeserializePrivateLinkResourceProperties(prop.Value, options); + continue; + } + if (prop.NameEquals("identity"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + identity = ManagedServiceIdentity.DeserializeManagedServiceIdentity(prop.Value, options); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new PrivateLinkResource( + id, + name, + @type, + systemData, + additionalBinaryDataProperties, + properties, + identity); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + 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(PrivateLinkResource)} does not support writing '{options.Format}' format."); + } + } + + PrivateLinkResource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => (PrivateLinkResource)PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected override Resource PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializePrivateLinkResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(PrivateLinkResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(PrivateLinkResource privateLinkResource) + { + if (privateLinkResource == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(privateLinkResource, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator PrivateLinkResource(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializePrivateLinkResource(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.cs new file mode 100644 index 0000000000000..e2d344a7c99f7 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResource.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace MgmtTypeSpec.Models +{ + /// Concrete proxy resource types can be created by aliasing this type using a specific property type. + public partial class PrivateLinkResource : ProxyResource + { + internal PrivateLinkResource() + { + } + + internal PrivateLinkResource(ResourceIdentifier id, string name, string @type, SystemData systemData, IDictionary additionalBinaryDataProperties, PrivateLinkResourceProperties properties, ManagedServiceIdentity identity) : base(id, name, @type, systemData, additionalBinaryDataProperties) + { + Properties = properties; + Identity = identity; + } + + /// The resource-specific properties for this resource. + public PrivateLinkResourceProperties Properties { get; } + + /// The managed service identities assigned to this resource. + public ManagedServiceIdentity Identity { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.Serialization.cs new file mode 100644 index 0000000000000..872284b61629a --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.Serialization.cs @@ -0,0 +1,179 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class PrivateLinkResourceListResult : IJsonModel + { + internal PrivateLinkResourceListResult() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(PrivateLinkResourceListResult)} does not support writing '{format}' format."); + } + writer.WritePropertyName("value"u8); + writer.WriteStartArray(); + foreach (PrivateLinkResource item in Value) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + if (Optional.IsDefined(NextLink)) + { + writer.WritePropertyName("nextLink"u8); + writer.WriteStringValue(NextLink.AbsoluteUri); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + PrivateLinkResourceListResult IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual PrivateLinkResourceListResult JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PrivateLinkResourceListResult)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePrivateLinkResourceListResult(document.RootElement, options); + } + + internal static PrivateLinkResourceListResult DeserializePrivateLinkResourceListResult(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList value = default; + Uri nextLink = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("value"u8)) + { + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + array.Add(PrivateLinkResource.DeserializePrivateLinkResource(item, options)); + } + value = array; + continue; + } + if (prop.NameEquals("nextLink"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nextLink = new Uri(prop.Value.GetString()); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new PrivateLinkResourceListResult(value, nextLink, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(PrivateLinkResourceListResult)} does not support writing '{options.Format}' format."); + } + } + + PrivateLinkResourceListResult IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual PrivateLinkResourceListResult PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializePrivateLinkResourceListResult(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(PrivateLinkResourceListResult)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(PrivateLinkResourceListResult privateLinkResourceListResult) + { + if (privateLinkResourceListResult == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(privateLinkResourceListResult, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator PrivateLinkResourceListResult(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializePrivateLinkResourceListResult(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.cs new file mode 100644 index 0000000000000..ba71137ba6576 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceListResult.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MgmtTypeSpec.Models +{ + /// The response of a PrivateLinkResource list operation. + public partial class PrivateLinkResourceListResult + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal PrivateLinkResourceListResult(IEnumerable value) + { + Value = value.ToList(); + } + + internal PrivateLinkResourceListResult(IList value, Uri nextLink, IDictionary additionalBinaryDataProperties) + { + Value = value; + NextLink = nextLink; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The PrivateLinkResource items on this page. + public IList Value { get; } + + /// The link to the next page of items. + public Uri NextLink { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.Serialization.cs new file mode 100644 index 0000000000000..ec06410c7c2a2 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.Serialization.cs @@ -0,0 +1,227 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class PrivateLinkResourceProperties : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(PrivateLinkResourceProperties)} does not support writing '{format}' format."); + } + if (options.Format != "W" && Optional.IsDefined(GroupId)) + { + writer.WritePropertyName("groupId"u8); + writer.WriteStringValue(GroupId); + } + if (options.Format != "W" && Optional.IsCollectionDefined(RequiredMembers)) + { + writer.WritePropertyName("requiredMembers"u8); + writer.WriteStartArray(); + foreach (string item in RequiredMembers) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(RequiredZoneNames)) + { + writer.WritePropertyName("requiredZoneNames"u8); + writer.WriteStartArray(); + foreach (string item in RequiredZoneNames) + { + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + PrivateLinkResourceProperties IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual PrivateLinkResourceProperties JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(PrivateLinkResourceProperties)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializePrivateLinkResourceProperties(document.RootElement, options); + } + + internal static PrivateLinkResourceProperties DeserializePrivateLinkResourceProperties(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string groupId = default; + IReadOnlyList requiredMembers = default; + IList requiredZoneNames = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("groupId"u8)) + { + groupId = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("requiredMembers"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetString()); + } + } + requiredMembers = array; + continue; + } + if (prop.NameEquals("requiredZoneNames"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in prop.Value.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetString()); + } + } + requiredZoneNames = array; + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new PrivateLinkResourceProperties(groupId, requiredMembers ?? new ChangeTrackingList(), requiredZoneNames ?? new ChangeTrackingList(), additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(PrivateLinkResourceProperties)} does not support writing '{options.Format}' format."); + } + } + + PrivateLinkResourceProperties IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual PrivateLinkResourceProperties PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializePrivateLinkResourceProperties(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(PrivateLinkResourceProperties)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(PrivateLinkResourceProperties privateLinkResourceProperties) + { + if (privateLinkResourceProperties == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(privateLinkResourceProperties, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator PrivateLinkResourceProperties(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializePrivateLinkResourceProperties(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.cs new file mode 100644 index 0000000000000..b4e49f1d64a8d --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/PrivateLinkResourceProperties.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// Properties of a private link resource. + public partial class PrivateLinkResourceProperties + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal PrivateLinkResourceProperties() + { + RequiredMembers = new ChangeTrackingList(); + RequiredZoneNames = new ChangeTrackingList(); + } + + internal PrivateLinkResourceProperties(string groupId, IReadOnlyList requiredMembers, IList requiredZoneNames, IDictionary additionalBinaryDataProperties) + { + GroupId = groupId; + RequiredMembers = requiredMembers; + RequiredZoneNames = requiredZoneNames; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The private link resource group id. + public string GroupId { get; } + + /// The private link resource required member names. + public IReadOnlyList RequiredMembers { get; } + + /// The private link resource private link DNS zone name. + public IList RequiredZoneNames { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.Serialization.cs new file mode 100644 index 0000000000000..7d0ec68a7434c --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.Serialization.cs @@ -0,0 +1,160 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class ProxyResource : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ProxyResource)} does not support writing '{format}' format."); + } + base.JsonModelWriteCore(writer, options); + } + + ProxyResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (ProxyResource)JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected override Resource JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ProxyResource)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeProxyResource(document.RootElement, options); + } + + internal static ProxyResource DeserializeProxyResource(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + string @type = default; + SystemData systemData = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + id = new ResourceIdentifier(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("systemData"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = SystemData.DeserializeSystemData(prop.Value, options); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new ProxyResource(id, name, @type, systemData, additionalBinaryDataProperties); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + 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(ProxyResource)} does not support writing '{options.Format}' format."); + } + } + + ProxyResource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => (ProxyResource)PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected override Resource PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeProxyResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ProxyResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(ProxyResource proxyResource) + { + if (proxyResource == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(proxyResource, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator ProxyResource(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeProxyResource(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.cs new file mode 100644 index 0000000000000..f5dcbae09d2f8 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/ProxyResource.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace MgmtTypeSpec.Models +{ + /// The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location. + public partial class ProxyResource : Resource + { + internal ProxyResource() + { + } + + internal ProxyResource(ResourceIdentifier id, string name, string @type, SystemData systemData, IDictionary additionalBinaryDataProperties) : base(id, name, @type, systemData, additionalBinaryDataProperties) + { + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.Serialization.cs new file mode 100644 index 0000000000000..187c79a43e0a6 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.Serialization.cs @@ -0,0 +1,194 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class Resource : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(Resource)} does not support writing '{format}' format."); + } + if (options.Format != "W" && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id.Name); + } + if (options.Format != "W" && Optional.IsDefined(Name)) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (options.Format != "W" && Optional.IsDefined(Type)) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (options.Format != "W" && Optional.IsDefined(SystemData)) + { + writer.WritePropertyName("systemData"u8); + writer.WriteObjectValue(SystemData, options); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + Resource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual Resource JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(Resource)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeResource(document.RootElement, options); + } + + internal static Resource DeserializeResource(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + string @type = default; + SystemData systemData = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + id = new ResourceIdentifier(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("systemData"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = SystemData.DeserializeSystemData(prop.Value, options); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new Resource(id, name, @type, systemData, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(Resource)} does not support writing '{options.Format}' format."); + } + } + + Resource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual Resource PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(Resource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(Resource resource) + { + if (resource == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(resource, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator Resource(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeResource(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.cs new file mode 100644 index 0000000000000..b612693d78543 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/Resource.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; + +namespace MgmtTypeSpec.Models +{ + /// Common fields that are returned in the response for all Azure Resource Manager resources. + public partial class Resource + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public Resource() + { + } + + internal Resource(ResourceIdentifier id, string name, string @type, SystemData systemData, IDictionary additionalBinaryDataProperties) + { + Id = id; + Name = name; + Type = @type; + SystemData = systemData; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}. + public ResourceIdentifier Id { get; } + + /// The name of the resource. + public string Name { get; } + + /// The type of the resource. E.g. "Microsoft.Compute/virtualMachines" or "Microsoft.Storage/storageAccounts". + public string Type { get; } + + /// Azure Resource Manager metadata containing createdBy and modifiedBy information. + public SystemData SystemData { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.Serialization.cs new file mode 100644 index 0000000000000..e25548dc6e6b4 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.Serialization.cs @@ -0,0 +1,157 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class StartRequest : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(StartRequest)} does not support writing '{format}' format."); + } + if (Optional.IsDefined(StartVm)) + { + writer.WritePropertyName("startVm"u8); + writer.WriteBooleanValue(StartVm.Value); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + StartRequest IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual StartRequest JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(StartRequest)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeStartRequest(document.RootElement, options); + } + + internal static StartRequest DeserializeStartRequest(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool? startVm = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("startVm"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + startVm = prop.Value.GetBoolean(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new StartRequest(startVm, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(StartRequest)} does not support writing '{options.Format}' format."); + } + } + + StartRequest IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual StartRequest PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeStartRequest(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(StartRequest)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(StartRequest startRequest) + { + if (startRequest == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(startRequest, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator StartRequest(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeStartRequest(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.cs new file mode 100644 index 0000000000000..17631d3b56a21 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/StartRequest.cs @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace MgmtTypeSpec.Models +{ + /// Start SAP instance(s) request body. + public partial class StartRequest + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + /// Initializes a new instance of . + public StartRequest() + { + } + + internal StartRequest(bool? startVm, IDictionary additionalBinaryDataProperties) + { + StartVm = startVm; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The boolean value indicates whether to start the virtual machines before starting the SAP instances. + public bool? StartVm { get; set; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.Serialization.cs new file mode 100644 index 0000000000000..28cfdce835aa0 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.Serialization.cs @@ -0,0 +1,231 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class SystemData : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(SystemData)} does not support writing '{format}' format."); + } + if (Optional.IsDefined(CreatedBy)) + { + writer.WritePropertyName("createdBy"u8); + writer.WriteStringValue(CreatedBy); + } + if (Optional.IsDefined(CreatedByType)) + { + writer.WritePropertyName("createdByType"u8); + writer.WriteStringValue(CreatedByType.Value.ToString()); + } + if (Optional.IsDefined(CreatedAt)) + { + writer.WritePropertyName("createdAt"u8); + writer.WriteStringValue(CreatedAt.Value, "O"); + } + if (Optional.IsDefined(LastModifiedBy)) + { + writer.WritePropertyName("lastModifiedBy"u8); + writer.WriteStringValue(LastModifiedBy); + } + if (Optional.IsDefined(LastModifiedByType)) + { + writer.WritePropertyName("lastModifiedByType"u8); + writer.WriteStringValue(LastModifiedByType.Value.ToString()); + } + if (Optional.IsDefined(LastModifiedAt)) + { + writer.WritePropertyName("lastModifiedAt"u8); + writer.WriteStringValue(LastModifiedAt.Value, "O"); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + SystemData IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual SystemData JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(SystemData)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeSystemData(document.RootElement, options); + } + + internal static SystemData DeserializeSystemData(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string createdBy = default; + CreatedByType? createdByType = default; + DateTimeOffset? createdAt = default; + string lastModifiedBy = default; + CreatedByType? lastModifiedByType = default; + DateTimeOffset? lastModifiedAt = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("createdBy"u8)) + { + createdBy = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("createdByType"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + createdByType = new CreatedByType(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("createdAt"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + createdAt = prop.Value.GetDateTimeOffset("O"); + continue; + } + if (prop.NameEquals("lastModifiedBy"u8)) + { + lastModifiedBy = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("lastModifiedByType"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + lastModifiedByType = new CreatedByType(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("lastModifiedAt"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + lastModifiedAt = prop.Value.GetDateTimeOffset("O"); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new SystemData( + createdBy, + createdByType, + createdAt, + lastModifiedBy, + lastModifiedByType, + lastModifiedAt, + additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(SystemData)} does not support writing '{options.Format}' format."); + } + } + + SystemData IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual SystemData PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeSystemData(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(SystemData)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(SystemData systemData) + { + if (systemData == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(systemData, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator SystemData(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeSystemData(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.cs new file mode 100644 index 0000000000000..10637015298ee --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/SystemData.cs @@ -0,0 +1,52 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace MgmtTypeSpec.Models +{ + /// Metadata pertaining to creation and last modification of the resource. + public partial class SystemData + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal SystemData() + { + } + + internal SystemData(string createdBy, CreatedByType? createdByType, DateTimeOffset? createdAt, string lastModifiedBy, CreatedByType? lastModifiedByType, DateTimeOffset? lastModifiedAt, IDictionary additionalBinaryDataProperties) + { + CreatedBy = createdBy; + CreatedByType = createdByType; + CreatedAt = createdAt; + LastModifiedBy = lastModifiedBy; + LastModifiedByType = lastModifiedByType; + LastModifiedAt = lastModifiedAt; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The identity that created the resource. + public string CreatedBy { get; } + + /// The type of identity that created the resource. + public CreatedByType? CreatedByType { get; } + + /// The timestamp of resource creation (UTC). + public DateTimeOffset? CreatedAt { get; } + + /// The identity that last modified the resource. + public string LastModifiedBy { get; } + + /// The type of identity that last modified the resource. + public CreatedByType? LastModifiedByType { get; } + + /// The timestamp of resource last modification (UTC). + public DateTimeOffset? LastModifiedAt { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.Serialization.cs new file mode 100644 index 0000000000000..2694b9fc6d2e3 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.Serialization.cs @@ -0,0 +1,217 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class TrackedResource : IJsonModel + { + internal TrackedResource() + { + } + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TrackedResource)} does not support writing '{format}' format."); + } + base.JsonModelWriteCore(writer, options); + if (Optional.IsCollectionDefined(Tags)) + { + writer.WritePropertyName("tags"u8); + writer.WriteStartObject(); + foreach (var item in Tags) + { + writer.WritePropertyName(item.Key); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WritePropertyName("location"u8); + writer.WriteStringValue(Location); + } + + TrackedResource IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (TrackedResource)JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected override Resource JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(TrackedResource)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeTrackedResource(document.RootElement, options); + } + + internal static TrackedResource DeserializeTrackedResource(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + string @type = default; + SystemData systemData = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + IDictionary tags = default; + string location = default; + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("id"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + id = new ResourceIdentifier(prop.Value.GetString()); + continue; + } + if (prop.NameEquals("name"u8)) + { + name = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("type"u8)) + { + @type = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("systemData"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = SystemData.DeserializeSystemData(prop.Value, options); + continue; + } + if (prop.NameEquals("tags"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var prop0 in prop.Value.EnumerateObject()) + { + if (prop0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(prop0.Name, null); + } + else + { + dictionary.Add(prop0.Name, prop0.Value.GetString()); + } + } + tags = dictionary; + continue; + } + if (prop.NameEquals("location"u8)) + { + location = prop.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new TrackedResource( + id, + name, + @type, + systemData, + additionalBinaryDataProperties, + tags ?? new ChangeTrackingDictionary(), + location); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options); + + /// The client options for reading and writing models. + protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options) + { + 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(TrackedResource)} does not support writing '{options.Format}' format."); + } + } + + TrackedResource IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => (TrackedResource)PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected override Resource PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeTrackedResource(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(TrackedResource)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(TrackedResource trackedResource) + { + if (trackedResource == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(trackedResource, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator TrackedResource(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeTrackedResource(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.cs new file mode 100644 index 0000000000000..a87e0e02271ba --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/TrackedResource.cs @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'. + public partial class TrackedResource : Resource + { + /// Initializes a new instance of . + /// The geo-location where the resource lives. + /// is null. + public TrackedResource(string location) + { + Argument.AssertNotNull(location, nameof(location)); + + Tags = new ChangeTrackingDictionary(); + Location = location; + } + + internal TrackedResource(ResourceIdentifier id, string name, string @type, SystemData systemData, IDictionary additionalBinaryDataProperties, IDictionary tags, string location) : base(id, name, @type, systemData, additionalBinaryDataProperties) + { + Tags = tags; + Location = location; + } + + /// Resource tags. + public IDictionary Tags { get; } + + /// The geo-location where the resource lives. + public string Location { get; set; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.Serialization.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.Serialization.cs new file mode 100644 index 0000000000000..221b434ab6fff --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.Serialization.cs @@ -0,0 +1,172 @@ +// 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.Text.Json; +using Azure; +using Azure.Core; +using MgmtTypeSpec; + +namespace MgmtTypeSpec.Models +{ + /// + public partial class UserAssignedIdentity : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// 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; + if (format != "J") + { + throw new FormatException($"The model {nameof(UserAssignedIdentity)} does not support writing '{format}' format."); + } + if (options.Format != "W" && Optional.IsDefined(PrincipalId)) + { + writer.WritePropertyName("principalId"u8); + writer.WriteStringValue(PrincipalId.Value); + } + if (options.Format != "W" && Optional.IsDefined(ClientId)) + { + writer.WritePropertyName("clientId"u8); + writer.WriteStringValue(ClientId.Value); + } + if (options.Format != "W" && _additionalBinaryDataProperties != null) + { + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + UserAssignedIdentity IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options); + + /// The JSON reader. + /// The client options for reading and writing models. + protected virtual UserAssignedIdentity JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(UserAssignedIdentity)} does not support reading '{format}' format."); + } + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeUserAssignedIdentity(document.RootElement, options); + } + + internal static UserAssignedIdentity DeserializeUserAssignedIdentity(JsonElement element, ModelReaderWriterOptions options) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + Guid? principalId = default; + Guid? clientId = default; + IDictionary additionalBinaryDataProperties = new ChangeTrackingDictionary(); + foreach (var prop in element.EnumerateObject()) + { + if (prop.NameEquals("principalId"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + principalId = prop.Value.GetGuid(); + continue; + } + if (prop.NameEquals("clientId"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + clientId = prop.Value.GetGuid(); + continue; + } + if (options.Format != "W") + { + additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText())); + } + } + return new UserAssignedIdentity(principalId, clientId, additionalBinaryDataProperties); + } + + 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; + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(UserAssignedIdentity)} does not support writing '{options.Format}' format."); + } + } + + UserAssignedIdentity IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options); + + /// The data to parse. + /// The client options for reading and writing models. + protected virtual UserAssignedIdentity PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options) + { + string format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + switch (format) + { + case "J": + using (JsonDocument document = JsonDocument.Parse(data)) + { + return DeserializeUserAssignedIdentity(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(UserAssignedIdentity)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// The to serialize into . + public static implicit operator RequestContent(UserAssignedIdentity userAssignedIdentity) + { + if (userAssignedIdentity == null) + { + return null; + } + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(userAssignedIdentity, ModelSerializationExtensions.WireOptions); + return content; + } + + /// The to deserialize the from. + public static explicit operator UserAssignedIdentity(Response result) + { + using Response response = result; + using JsonDocument document = JsonDocument.Parse(response.Content); + return DeserializeUserAssignedIdentity(document.RootElement, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.cs new file mode 100644 index 0000000000000..d691011214a2f --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Models/UserAssignedIdentity.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace MgmtTypeSpec.Models +{ + /// User assigned identity properties. + public partial class UserAssignedIdentity + { + /// Keeps track of any properties unknown to the library. + private protected readonly IDictionary _additionalBinaryDataProperties; + + internal UserAssignedIdentity() + { + } + + internal UserAssignedIdentity(Guid? principalId, Guid? clientId, IDictionary additionalBinaryDataProperties) + { + PrincipalId = principalId; + ClientId = clientId; + _additionalBinaryDataProperties = additionalBinaryDataProperties; + } + + /// The principal ID of the assigned identity. + public Guid? PrincipalId { get; } + + /// The client ID of the assigned identity. + public Guid? ClientId { get; } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.RestClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.RestClient.cs new file mode 100644 index 0000000000000..efc8aa419b585 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.RestClient.cs @@ -0,0 +1,50 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace MgmtTypeSpec +{ + /// + public partial class Operations + { + private static ResponseClassifier _pipelineMessageClassifier200; + private static ResponseClassifier _pipelineMessageClassifier201; + private static ResponseClassifier _pipelineMessageClassifier202; + private static ResponseClassifier _pipelineMessageClassifier204; + private static Classifier2xxAnd4xx _pipelineMessageClassifier2xxAnd4xx; + + private static ResponseClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 = new StatusCodeClassifier(stackalloc ushort[] { 200 }); + + private static ResponseClassifier PipelineMessageClassifier201 => _pipelineMessageClassifier201 = new StatusCodeClassifier(stackalloc ushort[] { 201 }); + + private static ResponseClassifier PipelineMessageClassifier202 => _pipelineMessageClassifier202 = new StatusCodeClassifier(stackalloc ushort[] { 202 }); + + private static ResponseClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 = new StatusCodeClassifier(stackalloc ushort[] { 204 }); + + private static Classifier2xxAnd4xx PipelineMessageClassifier2xxAnd4xx => _pipelineMessageClassifier2xxAnd4xx ??= new Classifier2xxAnd4xx(); + + internal HttpMessage CreateListRequest(RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Method = RequestMethod.Get; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/providers/MgmtTypeSpec/operations", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + private class Classifier2xxAnd4xx : ResponseClassifier + { + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.cs new file mode 100644 index 0000000000000..99c5f9204fa38 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Operations.cs @@ -0,0 +1,90 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using MgmtTypeSpec.Models; + +namespace MgmtTypeSpec +{ + /// + public partial class Operations + { + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// Initializes a new instance of Operations for mocking. + protected Operations() + { + } + + internal Operations(HttpPipeline pipeline, Uri endpoint, string apiVersion) + { + _endpoint = endpoint; + Pipeline = pipeline; + _apiVersion = apiVersion; + } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public HttpPipeline Pipeline { get; } + + /// + /// [Protocol Method] List the operations for the provider + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response List(RequestContext context) + { + using HttpMessage message = CreateListRequest(context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] List the operations for the provider + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task ListAsync(RequestContext context) + { + using HttpMessage message = CreateListRequest(context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// List the operations for the provider. + /// Service returned a non-success status code. + public virtual Response List() + { + Response result = List(context: null); + return Response.FromValue((OperationListResult)result, result); + } + + /// List the operations for the provider. + /// The cancellation token that can be used to cancel the operation. + /// Service returned a non-success status code. + public virtual async Task> ListAsync(CancellationToken cancellationToken = default) + { + Response result = await ListAsync(cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return Response.FromValue((OperationListResult)result, result); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.RestClient.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.RestClient.cs new file mode 100644 index 0000000000000..a22b2dc8b973f --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.RestClient.cs @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure; +using Azure.Core; + +namespace MgmtTypeSpec +{ + /// + public partial class PrivateLinks + { + private static ResponseClassifier _pipelineMessageClassifier200; + private static ResponseClassifier _pipelineMessageClassifier201; + private static ResponseClassifier _pipelineMessageClassifier202; + private static ResponseClassifier _pipelineMessageClassifier204; + private static Classifier2xxAnd4xx _pipelineMessageClassifier2xxAnd4xx; + + private static ResponseClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 = new StatusCodeClassifier(stackalloc ushort[] { 200 }); + + private static ResponseClassifier PipelineMessageClassifier201 => _pipelineMessageClassifier201 = new StatusCodeClassifier(stackalloc ushort[] { 201 }); + + private static ResponseClassifier PipelineMessageClassifier202 => _pipelineMessageClassifier202 = new StatusCodeClassifier(stackalloc ushort[] { 202 }); + + private static ResponseClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 = new StatusCodeClassifier(stackalloc ushort[] { 204 }); + + private static Classifier2xxAnd4xx PipelineMessageClassifier2xxAnd4xx => _pipelineMessageClassifier2xxAnd4xx ??= new Classifier2xxAnd4xx(); + + internal HttpMessage CreateGetAllPrivateLinkResourcesRequest(string resourceGroupName, RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier200); + Request request = message.Request; + request.Method = RequestMethod.Get; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(_subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/MgmtTypeSpec/privateLinkResources", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Accept", "application/json"); + return message; + } + + internal HttpMessage CreateStartRequest(string resourceGroupName, string privateLinkResourcenName, RequestContent content, RequestContext context) + { + HttpMessage message = Pipeline.CreateMessage(context, PipelineMessageClassifier202); + Request request = message.Request; + request.Method = RequestMethod.Post; + RawRequestUriBuilder uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(_subscriptionId.ToString(), true); + uri.AppendPath("/resourceGroups/", false); + uri.AppendPath(resourceGroupName, true); + uri.AppendPath("/providers/MgmtTypeSpec/privateLinkResources/", false); + uri.AppendPath(privateLinkResourcenName, true); + uri.AppendPath("/start", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.SetValue("Content-Type", "application/json"); + request.Headers.SetValue("Accept", "application/json"); + request.Content = content; + return message; + } + + private class Classifier2xxAnd4xx : ResponseClassifier + { + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.cs b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.cs new file mode 100644 index 0000000000000..95673da42de3c --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/PrivateLinks.cs @@ -0,0 +1,185 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using MgmtTypeSpec.Models; + +namespace MgmtTypeSpec +{ + /// + public partial class PrivateLinks + { + private readonly Uri _endpoint; + private readonly string _apiVersion; + private readonly Guid _subscriptionId; + + /// Initializes a new instance of PrivateLinks for mocking. + protected PrivateLinks() + { + } + + internal PrivateLinks(HttpPipeline pipeline, Uri endpoint, string apiVersion, Guid subscriptionId) + { + _endpoint = endpoint; + Pipeline = pipeline; + _apiVersion = apiVersion; + _subscriptionId = subscriptionId; + } + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public HttpPipeline Pipeline { get; } + + /// + /// [Protocol Method] list private links on the given resource + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response GetAllPrivateLinkResources(string resourceGroupName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + using HttpMessage message = CreateGetAllPrivateLinkResourcesRequest(resourceGroupName, context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] list private links on the given resource + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetAllPrivateLinkResourcesAsync(string resourceGroupName, RequestContext context) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + using HttpMessage message = CreateGetAllPrivateLinkResourcesRequest(resourceGroupName, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// list private links on the given resource. + /// The name of the resource group. The name is case insensitive. + /// is null. + /// Service returned a non-success status code. + public virtual Response GetAllPrivateLinkResources(string resourceGroupName) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + Response result = GetAllPrivateLinkResources(resourceGroupName, context: null); + return Response.FromValue((PrivateLinkResourceListResult)result, result); + } + + /// list private links on the given resource. + /// The name of the resource group. The name is case insensitive. + /// The cancellation token that can be used to cancel the operation. + /// is null. + /// Service returned a non-success status code. + public virtual async Task> GetAllPrivateLinkResourcesAsync(string resourceGroupName, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + + Response result = await GetAllPrivateLinkResourcesAsync(resourceGroupName, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + return Response.FromValue((PrivateLinkResourceListResult)result, result); + } + + /// + /// [Protocol Method] Starts the SAP Application Server Instance. + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the private link associated with the Azure resource. + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual Response Start(string resourceGroupName, string privateLinkResourcenName, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(privateLinkResourcenName, nameof(privateLinkResourcenName)); + + using HttpMessage message = CreateStartRequest(resourceGroupName, privateLinkResourcenName, content, context); + return Pipeline.ProcessMessage(message, context); + } + + /// + /// [Protocol Method] Starts the SAP Application Server Instance. + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// The name of the resource group. The name is case insensitive. + /// The name of the private link associated with the Azure resource. + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// or is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task StartAsync(string resourceGroupName, string privateLinkResourcenName, RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(privateLinkResourcenName, nameof(privateLinkResourcenName)); + + using HttpMessage message = CreateStartRequest(resourceGroupName, privateLinkResourcenName, content, context); + return await Pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + + /// Starts the SAP Application Server Instance. + /// The name of the resource group. The name is case insensitive. + /// The name of the private link associated with the Azure resource. + /// SAP Application server instance start request body. + /// or is null. + /// Service returned a non-success status code. + public virtual Response Start(string resourceGroupName, string privateLinkResourcenName, StartRequest body = null) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(privateLinkResourcenName, nameof(privateLinkResourcenName)); + + return Start(resourceGroupName, privateLinkResourcenName, body, context: null); + } + + /// Starts the SAP Application Server Instance. + /// The name of the resource group. The name is case insensitive. + /// The name of the private link associated with the Azure resource. + /// SAP Application server instance start request body. + /// 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 StartAsync(string resourceGroupName, string privateLinkResourcenName, StartRequest body = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(resourceGroupName, nameof(resourceGroupName)); + Argument.AssertNotNull(privateLinkResourcenName, nameof(privateLinkResourcenName)); + + return await StartAsync(resourceGroupName, privateLinkResourcenName, body, cancellationToken.CanBeCanceled ? new RequestContext { CancellationToken = cancellationToken } : null).ConfigureAwait(false); + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/MgmtTypeSpec.csproj b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/MgmtTypeSpec.csproj new file mode 100644 index 0000000000000..1408010b44f1c --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/MgmtTypeSpec.csproj @@ -0,0 +1,23 @@ + + + This is the MgmtTypeSpec client library for developing .NET applications with rich experience. + SDK Code Generation MgmtTypeSpec + 1.0.0-beta.1 + MgmtTypeSpec + netstandard2.0 + latest + true + + + + + + + + + + + + + + diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json new file mode 100644 index 0000000000000..75448f699efc4 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspCodeModel.json @@ -0,0 +1,3528 @@ +{ + "$id": "1", + "Name": "MgmtTypeSpec", + "ApiVersions": [ + "2024-05-01" + ], + "Enums": [ + { + "$id": "2", + "kind": "enum", + "name": "ExtendedLocationType", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ExtendedLocationType", + "valueType": { + "$id": "3", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "4", + "kind": "enumvalue", + "name": "EdgeZone", + "value": "EdgeZone", + "valueType": { + "$id": "5", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "2" + }, + "description": "Azure Edge Zones location type", + "decorators": [] + }, + { + "$id": "6", + "kind": "enumvalue", + "name": "CustomLocation", + "value": "CustomLocation", + "valueType": { + "$id": "7", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "2" + }, + "description": "Azure Custom Locations type", + "decorators": [] + } + ], + "description": "The supported ExtendedLocation types.", + "isFixed": false, + "isFlags": false, + "usage": "Input,Output,Json", + "decorators": [] + }, + { + "$id": "8", + "kind": "enum", + "name": "createdByType", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.createdByType", + "valueType": { + "$id": "9", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "10", + "kind": "enumvalue", + "name": "User", + "value": "User", + "valueType": { + "$id": "11", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "8" + }, + "description": "The entity was created by a user.", + "decorators": [] + }, + { + "$id": "12", + "kind": "enumvalue", + "name": "Application", + "value": "Application", + "valueType": { + "$id": "13", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "8" + }, + "description": "The entity was created by an application.", + "decorators": [] + }, + { + "$id": "14", + "kind": "enumvalue", + "name": "ManagedIdentity", + "value": "ManagedIdentity", + "valueType": { + "$id": "15", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "8" + }, + "description": "The entity was created by a managed identity.", + "decorators": [] + }, + { + "$id": "16", + "kind": "enumvalue", + "name": "Key", + "value": "Key", + "valueType": { + "$id": "17", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "8" + }, + "description": "The entity was created by a key.", + "decorators": [] + } + ], + "description": "The kind of entity that created the resource.", + "isFixed": false, + "isFlags": false, + "usage": "Output,Json", + "decorators": [] + }, + { + "$id": "18", + "kind": "enum", + "name": "ManagedServiceIdentityType", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ManagedServiceIdentityType", + "valueType": { + "$id": "19", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "20", + "kind": "enumvalue", + "name": "None", + "value": "None", + "valueType": { + "$id": "21", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "18" + }, + "description": "No managed identity.", + "decorators": [] + }, + { + "$id": "22", + "kind": "enumvalue", + "name": "SystemAssigned", + "value": "SystemAssigned", + "valueType": { + "$id": "23", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "18" + }, + "description": "System assigned managed identity.", + "decorators": [] + }, + { + "$id": "24", + "kind": "enumvalue", + "name": "UserAssigned", + "value": "UserAssigned", + "valueType": { + "$id": "25", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "18" + }, + "description": "User assigned managed identity.", + "decorators": [] + }, + { + "$id": "26", + "kind": "enumvalue", + "name": "SystemAndUserAssigned", + "value": "SystemAssigned,UserAssigned", + "valueType": { + "$id": "27", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "18" + }, + "description": "System and user assigned managed identity.", + "decorators": [] + } + ], + "description": "Type of managed service identity (where both SystemAssigned and UserAssigned types are allowed).", + "isFixed": false, + "isFlags": false, + "usage": "Output,Json", + "decorators": [] + }, + { + "$id": "28", + "kind": "enum", + "name": "Origin", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Origin", + "valueType": { + "$id": "29", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "30", + "kind": "enumvalue", + "name": "user", + "value": "user", + "valueType": { + "$id": "31", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "28" + }, + "description": "Indicates the operation is initiated by a user.", + "decorators": [] + }, + { + "$id": "32", + "kind": "enumvalue", + "name": "system", + "value": "system", + "valueType": { + "$id": "33", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "28" + }, + "description": "Indicates the operation is initiated by a system.", + "decorators": [] + }, + { + "$id": "34", + "kind": "enumvalue", + "name": "user,system", + "value": "user,system", + "valueType": { + "$id": "35", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "28" + }, + "description": "Indicates the operation is initiated by a user or system.", + "decorators": [] + } + ], + "description": "The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is \"user,system\"", + "isFixed": false, + "isFlags": false, + "usage": "Output,Json", + "decorators": [] + }, + { + "$id": "36", + "kind": "enum", + "name": "ActionType", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ActionType", + "valueType": { + "$id": "37", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "38", + "kind": "enumvalue", + "name": "Internal", + "value": "Internal", + "valueType": { + "$id": "39", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "36" + }, + "description": "Actions are for internal-only APIs.", + "decorators": [] + } + ], + "description": "Extensible enum. Indicates the action type. \"Internal\" refers to actions that are for internal only APIs.", + "isFixed": false, + "isFlags": false, + "usage": "Output,Json", + "decorators": [] + }, + { + "$id": "40", + "kind": "enum", + "name": "Versions", + "crossLanguageDefinitionId": "MgmtTypeSpec.Versions", + "valueType": { + "$id": "41", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "values": [ + { + "$id": "42", + "kind": "enumvalue", + "name": "v2024_05_01", + "value": "2024-05-01", + "valueType": { + "$id": "43", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "enumType": { + "$ref": "40" + }, + "description": "Azure Cosmos DB for Mongo vCore clusters api version 2024-03-01-preview.", + "decorators": [] + } + ], + "description": "The available API versions.", + "isFixed": true, + "isFlags": false, + "usage": "ApiVersionEnum", + "decorators": [] + } + ], + "Models": [ + { + "$id": "44", + "kind": "model", + "name": "Foo", + "crossLanguageDefinitionId": "MgmtTypeSpec.Foo", + "usage": "Input,Output,Json", + "description": "Concrete tracked resource types can be created by aliasing this type using a specific property type.", + "decorators": [], + "baseModel": { + "$id": "45", + "kind": "model", + "name": "TrackedResource", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.TrackedResource", + "usage": "Input,Output,Json", + "description": "The resource model definition for an Azure Resource Manager tracked top level resource which has 'tags' and a 'location'", + "decorators": [], + "baseModel": { + "$id": "46", + "kind": "model", + "name": "Resource", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Resource", + "usage": "Input,Output,Json", + "description": "Common fields that are returned in the response for all Azure Resource Manager resources", + "decorators": [], + "properties": [ + { + "$id": "47", + "kind": "property", + "name": "id", + "serializedName": "id", + "description": "Fully qualified resource ID for the resource. Ex - /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}", + "type": { + "$id": "48", + "kind": "string", + "name": "armResourceIdentifier", + "crossLanguageDefinitionId": "Azure.Core.armResourceIdentifier", + "baseType": { + "$id": "49", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Resource.id" + }, + { + "$id": "50", + "kind": "property", + "name": "name", + "serializedName": "name", + "description": "The name of the resource", + "type": { + "$id": "51", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Resource.name" + }, + { + "$id": "52", + "kind": "property", + "name": "type", + "serializedName": "type", + "description": "The type of the resource. E.g. \"Microsoft.Compute/virtualMachines\" or \"Microsoft.Storage/storageAccounts\"", + "type": { + "$id": "53", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Resource.type" + }, + { + "$id": "54", + "kind": "property", + "name": "systemData", + "serializedName": "systemData", + "description": "Azure Resource Manager metadata containing createdBy and modifiedBy information.", + "type": { + "$id": "55", + "kind": "model", + "name": "SystemData", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData", + "usage": "Output,Json", + "description": "Metadata pertaining to creation and last modification of the resource.", + "decorators": [], + "properties": [ + { + "$id": "56", + "kind": "property", + "name": "createdBy", + "serializedName": "createdBy", + "description": "The identity that created the resource.", + "type": { + "$id": "57", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData.createdBy" + }, + { + "$id": "58", + "kind": "property", + "name": "createdByType", + "serializedName": "createdByType", + "description": "The type of identity that created the resource.", + "type": { + "$ref": "8" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData.createdByType" + }, + { + "$id": "59", + "kind": "property", + "name": "createdAt", + "serializedName": "createdAt", + "description": "The timestamp of resource creation (UTC).", + "type": { + "$id": "60", + "kind": "utcDateTime", + "name": "utcDateTime", + "encode": "rfc3339", + "wireType": { + "$id": "61", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.utcDateTime", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData.createdAt" + }, + { + "$id": "62", + "kind": "property", + "name": "lastModifiedBy", + "serializedName": "lastModifiedBy", + "description": "The identity that last modified the resource.", + "type": { + "$id": "63", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData.lastModifiedBy" + }, + { + "$id": "64", + "kind": "property", + "name": "lastModifiedByType", + "serializedName": "lastModifiedByType", + "description": "The type of identity that last modified the resource.", + "type": { + "$ref": "8" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData.lastModifiedByType" + }, + { + "$id": "65", + "kind": "property", + "name": "lastModifiedAt", + "serializedName": "lastModifiedAt", + "description": "The timestamp of resource last modification (UTC)", + "type": { + "$id": "66", + "kind": "utcDateTime", + "name": "utcDateTime", + "encode": "rfc3339", + "wireType": { + "$id": "67", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.utcDateTime", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.SystemData.lastModifiedAt" + } + ] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Resource.systemData" + } + ] + }, + "properties": [ + { + "$id": "68", + "kind": "property", + "name": "tags", + "serializedName": "tags", + "description": "Resource tags.", + "type": { + "$id": "69", + "kind": "dict", + "keyType": { + "$id": "70", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "valueType": { + "$id": "71", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.TrackedResource.tags" + }, + { + "$id": "72", + "kind": "property", + "name": "location", + "serializedName": "location", + "description": "The geo-location where the resource lives", + "type": { + "$id": "73", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.TrackedResource.location" + } + ] + }, + "properties": [ + { + "$id": "74", + "kind": "property", + "name": "properties", + "serializedName": "properties", + "description": "The resource-specific properties for this resource.", + "type": { + "$id": "75", + "kind": "model", + "name": "FooProperties", + "crossLanguageDefinitionId": "MgmtTypeSpec.FooProperties", + "usage": "Input,Output,Json", + "decorators": [], + "properties": [ + { + "$id": "76", + "kind": "property", + "name": "serviceUrl", + "serializedName": "serviceUrl", + "description": "the service url", + "type": { + "$id": "77", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.FooProperties.serviceUrl" + }, + { + "$id": "78", + "kind": "property", + "name": "something", + "serializedName": "something", + "description": "something", + "type": { + "$id": "79", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.FooProperties.something" + }, + { + "$id": "80", + "kind": "property", + "name": "boolValue", + "serializedName": "boolValue", + "description": "boolean value", + "type": { + "$id": "81", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.FooProperties.boolValue" + }, + { + "$id": "82", + "kind": "property", + "name": "floatValue", + "serializedName": "floatValue", + "description": "float value", + "type": { + "$id": "83", + "kind": "float32", + "name": "float32", + "crossLanguageDefinitionId": "TypeSpec.float32", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.FooProperties.floatValue" + }, + { + "$id": "84", + "kind": "property", + "name": "doubleValue", + "serializedName": "doubleValue", + "description": "double value", + "type": { + "$id": "85", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.FooProperties.doubleValue" + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.Foo.properties" + }, + { + "$id": "86", + "kind": "property", + "name": "extendedLocation", + "serializedName": "extendedLocation", + "type": { + "$id": "87", + "kind": "model", + "name": "ExtendedLocation", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ExtendedLocation", + "usage": "Input,Output,Json", + "description": "The complex type of the extended location.", + "decorators": [], + "properties": [ + { + "$id": "88", + "kind": "property", + "name": "name", + "serializedName": "name", + "description": "The name of the extended location.", + "type": { + "$id": "89", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ExtendedLocation.name" + }, + { + "$id": "90", + "kind": "property", + "name": "type", + "serializedName": "type", + "description": "The type of the extended location.", + "type": { + "$ref": "2" + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ExtendedLocation.type" + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.Foo.extendedLocation" + } + ] + }, + { + "$ref": "75" + }, + { + "$ref": "87" + }, + { + "$ref": "45" + }, + { + "$ref": "46" + }, + { + "$ref": "55" + }, + { + "$id": "91", + "kind": "model", + "name": "ErrorResponse", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorResponse", + "usage": "Output,Error,Json", + "description": "Common error response for all Azure Resource Manager APIs to return error details for failed operations.", + "decorators": [], + "properties": [ + { + "$id": "92", + "kind": "property", + "name": "error", + "serializedName": "error", + "description": "The error object.", + "type": { + "$id": "93", + "kind": "model", + "name": "ErrorDetail", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorDetail", + "usage": "Output,Json", + "description": "The error detail.", + "decorators": [], + "properties": [ + { + "$id": "94", + "kind": "property", + "name": "code", + "serializedName": "code", + "description": "The error code.", + "type": { + "$id": "95", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorDetail.code" + }, + { + "$id": "96", + "kind": "property", + "name": "message", + "serializedName": "message", + "description": "The error message.", + "type": { + "$id": "97", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorDetail.message" + }, + { + "$id": "98", + "kind": "property", + "name": "target", + "serializedName": "target", + "description": "The error target.", + "type": { + "$id": "99", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorDetail.target" + }, + { + "$id": "100", + "kind": "property", + "name": "details", + "serializedName": "details", + "description": "The error details.", + "type": { + "$id": "101", + "kind": "array", + "name": "ArrayErrorDetail", + "valueType": { + "$ref": "93" + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorDetail.details" + }, + { + "$id": "102", + "kind": "property", + "name": "additionalInfo", + "serializedName": "additionalInfo", + "description": "The error additional info.", + "type": { + "$id": "103", + "kind": "array", + "name": "ArrayErrorAdditionalInfo", + "valueType": { + "$id": "104", + "kind": "model", + "name": "ErrorAdditionalInfo", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorAdditionalInfo", + "usage": "Output,Json", + "description": "The resource management error additional info.", + "decorators": [], + "properties": [ + { + "$id": "105", + "kind": "property", + "name": "type", + "serializedName": "type", + "description": "The additional info type.", + "type": { + "$id": "106", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorAdditionalInfo.type" + }, + { + "$id": "107", + "kind": "property", + "name": "info", + "serializedName": "info", + "description": "The additional info.", + "type": { + "$id": "108", + "kind": "model", + "name": "ErrorAdditionalInfoInfo", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorAdditionalInfo.info.anonymous", + "usage": "Output,Json", + "decorators": [], + "properties": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorAdditionalInfo.info" + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorDetail.additionalInfo" + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ErrorResponse.error" + } + ] + }, + { + "$ref": "93" + }, + { + "$ref": "104" + }, + { + "$ref": "108" + }, + { + "$id": "109", + "kind": "model", + "name": "FooListResult", + "crossLanguageDefinitionId": "Azure.ResourceManager.ResourceListResult", + "usage": "Output,Json", + "description": "The response of a Foo list operation.", + "decorators": [], + "properties": [ + { + "$id": "110", + "kind": "property", + "name": "value", + "serializedName": "value", + "description": "The Foo items on this page", + "type": { + "$id": "111", + "kind": "array", + "name": "ArrayFoo", + "valueType": { + "$ref": "44" + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.ResourceListResult.value" + }, + { + "$id": "112", + "kind": "property", + "name": "nextLink", + "serializedName": "nextLink", + "description": "The link to the next page of items", + "type": { + "$id": "113", + "kind": "url", + "name": "ResourceLocation", + "crossLanguageDefinitionId": "TypeSpec.Rest.ResourceLocation", + "baseType": { + "$id": "114", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.ResourceListResult.nextLink" + } + ] + }, + { + "$id": "115", + "kind": "model", + "name": "PrivateLinkResourceListResult", + "crossLanguageDefinitionId": "Azure.ResourceManager.ResourceListResult", + "usage": "Output,Json", + "description": "The response of a PrivateLinkResource list operation.", + "decorators": [], + "properties": [ + { + "$id": "116", + "kind": "property", + "name": "value", + "serializedName": "value", + "description": "The PrivateLinkResource items on this page", + "type": { + "$id": "117", + "kind": "array", + "name": "ArrayPrivateLinkResource", + "valueType": { + "$id": "118", + "kind": "model", + "name": "PrivateLinkResource", + "crossLanguageDefinitionId": "MgmtTypeSpec.PrivateLinkResource", + "usage": "Output,Json", + "description": "Concrete proxy resource types can be created by aliasing this type using a specific property type.", + "decorators": [], + "baseModel": { + "$id": "119", + "kind": "model", + "name": "ProxyResource", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ProxyResource", + "usage": "Output,Json", + "description": "The resource model definition for a Azure Resource Manager proxy resource. It will not have tags and a location", + "decorators": [], + "baseModel": { + "$ref": "46" + }, + "properties": [] + }, + "properties": [ + { + "$id": "120", + "kind": "property", + "name": "properties", + "serializedName": "properties", + "description": "The resource-specific properties for this resource.", + "type": { + "$id": "121", + "kind": "model", + "name": "PrivateLinkResourceProperties", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.PrivateLinkResourceProperties", + "usage": "Output,Json", + "description": "Properties of a private link resource.", + "decorators": [], + "properties": [ + { + "$id": "122", + "kind": "property", + "name": "groupId", + "serializedName": "groupId", + "description": "The private link resource group id.", + "type": { + "$id": "123", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.PrivateLinkResourceProperties.groupId" + }, + { + "$id": "124", + "kind": "property", + "name": "requiredMembers", + "serializedName": "requiredMembers", + "description": "The private link resource required member names.", + "type": { + "$id": "125", + "kind": "array", + "name": "Array", + "valueType": { + "$id": "126", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.PrivateLinkResourceProperties.requiredMembers" + }, + { + "$id": "127", + "kind": "property", + "name": "requiredZoneNames", + "serializedName": "requiredZoneNames", + "description": "The private link resource private link DNS zone name.", + "type": { + "$id": "128", + "kind": "array", + "name": "Array", + "valueType": { + "$id": "129", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.PrivateLinkResourceProperties.requiredZoneNames" + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.PrivateLinkResource.properties" + }, + { + "$id": "130", + "kind": "property", + "name": "identity", + "serializedName": "identity", + "description": "The managed service identities assigned to this resource.", + "type": { + "$id": "131", + "kind": "model", + "name": "ManagedServiceIdentity", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ManagedServiceIdentity", + "usage": "Output,Json", + "description": "Managed service identity (system assigned and/or user assigned identities)", + "decorators": [], + "properties": [ + { + "$id": "132", + "kind": "property", + "name": "principalId", + "serializedName": "principalId", + "description": "The service principal ID of the system assigned identity. This property will only be provided for a system assigned identity.", + "type": { + "$id": "133", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "134", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ManagedServiceIdentity.principalId" + }, + { + "$id": "135", + "kind": "property", + "name": "tenantId", + "serializedName": "tenantId", + "description": "The tenant ID of the system assigned identity. This property will only be provided for a system assigned identity.", + "type": { + "$id": "136", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "137", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ManagedServiceIdentity.tenantId" + }, + { + "$id": "138", + "kind": "property", + "name": "type", + "serializedName": "type", + "description": "The type of managed identity assigned to this resource.", + "type": { + "$ref": "18" + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ManagedServiceIdentity.type" + }, + { + "$id": "139", + "kind": "property", + "name": "userAssignedIdentities", + "serializedName": "userAssignedIdentities", + "description": "The identities assigned to this resource by the user.", + "type": { + "$id": "140", + "kind": "dict", + "keyType": { + "$id": "141", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "valueType": { + "$id": "142", + "kind": "nullable", + "type": { + "$id": "143", + "kind": "model", + "name": "UserAssignedIdentity", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.UserAssignedIdentity", + "usage": "Output,Json", + "description": "User assigned identity properties", + "decorators": [], + "properties": [ + { + "$id": "144", + "kind": "property", + "name": "principalId", + "serializedName": "principalId", + "description": "The principal ID of the assigned identity.", + "type": { + "$id": "145", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "146", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.UserAssignedIdentity.principalId" + }, + { + "$id": "147", + "kind": "property", + "name": "clientId", + "serializedName": "clientId", + "description": "The client ID of the assigned identity.", + "type": { + "$id": "148", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "149", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.UserAssignedIdentity.clientId" + } + ] + } + }, + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.ManagedServiceIdentity.userAssignedIdentities" + } + ] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.PrivateLinkResource.identity" + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.ResourceListResult.value" + }, + { + "$id": "150", + "kind": "property", + "name": "nextLink", + "serializedName": "nextLink", + "description": "The link to the next page of items", + "type": { + "$id": "151", + "kind": "url", + "name": "ResourceLocation", + "crossLanguageDefinitionId": "TypeSpec.Rest.ResourceLocation", + "baseType": { + "$id": "152", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.ResourceListResult.nextLink" + } + ] + }, + { + "$ref": "118" + }, + { + "$ref": "121" + }, + { + "$ref": "131" + }, + { + "$ref": "143" + }, + { + "$ref": "119" + }, + { + "$id": "153", + "kind": "model", + "name": "StartRequest", + "crossLanguageDefinitionId": "MgmtTypeSpec.StartRequest", + "usage": "Input,Json", + "description": "Start SAP instance(s) request body.", + "decorators": [], + "properties": [ + { + "$id": "154", + "kind": "property", + "name": "startVm", + "serializedName": "startVm", + "description": "The boolean value indicates whether to start the virtual machines before starting the SAP instances.", + "type": { + "$id": "155", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "MgmtTypeSpec.StartRequest.startVm" + } + ] + }, + { + "$id": "156", + "kind": "model", + "name": "OperationStatusResult", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult", + "usage": "Output,Json", + "description": "The current status of an async operation.", + "decorators": [], + "properties": [ + { + "$id": "157", + "kind": "property", + "name": "id", + "serializedName": "id", + "description": "Fully qualified ID for the async operation.", + "type": { + "$id": "158", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.id" + }, + { + "$id": "159", + "kind": "property", + "name": "name", + "serializedName": "name", + "description": "Name of the async operation.", + "type": { + "$id": "160", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.name" + }, + { + "$id": "161", + "kind": "property", + "name": "status", + "serializedName": "status", + "description": "Operation status.", + "type": { + "$id": "162", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.status" + }, + { + "$id": "163", + "kind": "property", + "name": "percentComplete", + "serializedName": "percentComplete", + "description": "Percent of the operation that is complete.", + "type": { + "$id": "164", + "kind": "float64", + "name": "float64", + "crossLanguageDefinitionId": "TypeSpec.float64", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.percentComplete" + }, + { + "$id": "165", + "kind": "property", + "name": "startTime", + "serializedName": "startTime", + "description": "The start time of the operation.", + "type": { + "$id": "166", + "kind": "utcDateTime", + "name": "utcDateTime", + "encode": "rfc3339", + "wireType": { + "$id": "167", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.utcDateTime", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.startTime" + }, + { + "$id": "168", + "kind": "property", + "name": "endTime", + "serializedName": "endTime", + "description": "The end time of the operation.", + "type": { + "$id": "169", + "kind": "utcDateTime", + "name": "utcDateTime", + "encode": "rfc3339", + "wireType": { + "$id": "170", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "crossLanguageDefinitionId": "TypeSpec.utcDateTime", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.endTime" + }, + { + "$id": "171", + "kind": "property", + "name": "operations", + "serializedName": "operations", + "description": "The operations list.", + "type": { + "$id": "172", + "kind": "array", + "name": "ArrayOperationStatusResult", + "valueType": { + "$ref": "156" + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.operations" + }, + { + "$id": "173", + "kind": "property", + "name": "error", + "serializedName": "error", + "description": "If present, details of the operation error.", + "type": { + "$ref": "93" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationStatusResult.error" + } + ] + }, + { + "$id": "174", + "kind": "model", + "name": "OperationListResult", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationListResult", + "usage": "Output,Json", + "description": "A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of results.", + "decorators": [], + "properties": [ + { + "$id": "175", + "kind": "property", + "name": "value", + "serializedName": "value", + "description": "The Operation items on this page", + "type": { + "$id": "176", + "kind": "array", + "name": "ArrayOperation", + "valueType": { + "$id": "177", + "kind": "model", + "name": "Operation", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Operation", + "usage": "Output,Json", + "description": "Details of a REST API operation, returned from the Resource Provider Operations API", + "decorators": [], + "properties": [ + { + "$id": "178", + "kind": "property", + "name": "name", + "serializedName": "name", + "description": "The name of the operation, as per Resource-Based Access Control (RBAC). Examples: \"Microsoft.Compute/virtualMachines/write\", \"Microsoft.Compute/virtualMachines/capture/action\"", + "type": { + "$id": "179", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Operation.name" + }, + { + "$id": "180", + "kind": "property", + "name": "isDataAction", + "serializedName": "isDataAction", + "description": "Whether the operation applies to data-plane. This is \"true\" for data-plane operations and \"false\" for Azure Resource Manager/control-plane operations.", + "type": { + "$id": "181", + "kind": "boolean", + "name": "boolean", + "crossLanguageDefinitionId": "TypeSpec.boolean", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Operation.isDataAction" + }, + { + "$id": "182", + "kind": "property", + "name": "display", + "serializedName": "display", + "description": "Localized display information for this particular operation.", + "type": { + "$id": "183", + "kind": "model", + "name": "OperationDisplay", + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationDisplay", + "usage": "Output,Json", + "description": "Localized display information for and operation.", + "decorators": [], + "properties": [ + { + "$id": "184", + "kind": "property", + "name": "provider", + "serializedName": "provider", + "description": "The localized friendly form of the resource provider name, e.g. \"Microsoft Monitoring Insights\" or \"Microsoft Compute\".", + "type": { + "$id": "185", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationDisplay.provider" + }, + { + "$id": "186", + "kind": "property", + "name": "resource", + "serializedName": "resource", + "description": "The localized friendly name of the resource type related to this operation. E.g. \"Virtual Machines\" or \"Job Schedule Collections\".", + "type": { + "$id": "187", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationDisplay.resource" + }, + { + "$id": "188", + "kind": "property", + "name": "operation", + "serializedName": "operation", + "description": "The concise, localized friendly name for the operation; suitable for dropdowns. E.g. \"Create or Update Virtual Machine\", \"Restart Virtual Machine\".", + "type": { + "$id": "189", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationDisplay.operation" + }, + { + "$id": "190", + "kind": "property", + "name": "description", + "serializedName": "description", + "description": "The short, localized friendly description of the operation; suitable for tool tips and detailed views.", + "type": { + "$id": "191", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationDisplay.description" + } + ] + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Operation.display" + }, + { + "$id": "192", + "kind": "property", + "name": "origin", + "serializedName": "origin", + "description": "The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value is \"user,system\"", + "type": { + "$ref": "28" + }, + "optional": true, + "readOnly": true, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Operation.origin" + }, + { + "$id": "193", + "kind": "property", + "name": "actionType", + "serializedName": "actionType", + "description": "Extensible enum. Indicates the action type. \"Internal\" refers to actions that are for internal only APIs.", + "type": { + "$ref": "36" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.Operation.actionType" + } + ] + }, + "crossLanguageDefinitionId": "TypeSpec.Array", + "decorators": [] + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationListResult.value" + }, + { + "$id": "194", + "kind": "property", + "name": "nextLink", + "serializedName": "nextLink", + "description": "The link to the next page of items", + "type": { + "$id": "195", + "kind": "url", + "name": "ResourceLocation", + "crossLanguageDefinitionId": "TypeSpec.Rest.ResourceLocation", + "baseType": { + "$id": "196", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url", + "decorators": [] + }, + "decorators": [] + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "Azure.ResourceManager.CommonTypes.OperationListResult.nextLink" + } + ] + }, + { + "$ref": "177" + }, + { + "$ref": "183" + } + ], + "Clients": [ + { + "$id": "197", + "Name": "MgmtTypeSpecClient", + "Operations": [], + "Protocol": { + "$id": "198" + }, + "Parameters": [ + { + "$id": "199", + "Name": "endpoint", + "NameInRequest": "endpoint", + "Type": { + "$id": "200", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url" + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "201", + "Type": { + "$id": "202", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "https://management.azure.com" + } + } + ], + "Decorators": [] + }, + { + "$id": "203", + "Name": "Operations", + "Operations": [ + { + "$id": "204", + "Name": "list", + "ResourceName": "Operations", + "Description": "List the operations for the provider", + "Accessibility": "public", + "Parameters": [ + { + "$id": "205", + "Name": "endpoint", + "NameInRequest": "endpoint", + "Type": { + "$id": "206", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url" + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "207", + "Type": { + "$id": "208", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "https://management.azure.com" + } + }, + { + "$id": "209", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "210", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "211", + "Type": { + "$id": "212", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "213", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "214", + "kind": "constant", + "valueType": { + "$id": "215", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "216", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "174" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/providers/MgmtTypeSpec/operations", + "BufferResponse": true, + "Paging": { + "$id": "217", + "ItemName": "value", + "NextLinkName": "nextLink" + }, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "Azure.ResourceManager.Operations.list", + "Decorators": [] + } + ], + "Protocol": { + "$id": "218" + }, + "Parent": "MgmtTypeSpecClient", + "Parameters": [ + { + "$ref": "205" + } + ], + "Decorators": [] + }, + { + "$id": "219", + "Name": "PrivateLinks", + "Operations": [ + { + "$id": "220", + "Name": "GetAllPrivateLinkResources", + "ResourceName": "PrivateLinkResource", + "Description": "list private links on the given resource", + "Accessibility": "public", + "Parameters": [ + { + "$id": "221", + "Name": "endpoint", + "NameInRequest": "endpoint", + "Type": { + "$id": "222", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url" + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "223", + "Type": { + "$id": "224", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "https://management.azure.com" + } + }, + { + "$id": "225", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "226", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "227", + "Type": { + "$id": "228", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "229", + "Name": "subscriptionId", + "NameInRequest": "subscriptionId", + "Description": "The ID of the target subscription. The value must be an UUID.", + "Type": { + "$id": "230", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "231", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "232", + "Name": "resourceGroupName", + "NameInRequest": "resourceGroupName", + "Description": "The name of the resource group. The name is case insensitive.", + "Type": { + "$id": "233", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "234", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "235", + "kind": "constant", + "valueType": { + "$id": "236", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "237", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "115" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/MgmtTypeSpec/privateLinkResources", + "BufferResponse": true, + "Paging": { + "$id": "238", + "ItemName": "value", + "NextLinkName": "nextLink" + }, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "MgmtTypeSpec.PrivateLinks.listByMongoCluster", + "Decorators": [] + }, + { + "$id": "239", + "Name": "start", + "ResourceName": "PrivateLinks", + "Description": "Starts the SAP Application Server Instance.", + "Accessibility": "public", + "Parameters": [ + { + "$ref": "221" + }, + { + "$id": "240", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "241", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "242", + "Type": { + "$id": "243", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "244", + "Name": "subscriptionId", + "NameInRequest": "subscriptionId", + "Description": "The ID of the target subscription. The value must be an UUID.", + "Type": { + "$id": "245", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "246", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "247", + "Name": "resourceGroupName", + "NameInRequest": "resourceGroupName", + "Description": "The name of the resource group. The name is case insensitive.", + "Type": { + "$id": "248", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "249", + "Name": "privateLinkResourcenName", + "NameInRequest": "privateLinkResourcenName", + "Description": "The name of the private link associated with the Azure resource.", + "Type": { + "$id": "250", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "251", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Description": "Body parameter's content type. Known values are application/json", + "Type": { + "$id": "252", + "kind": "constant", + "valueType": { + "$id": "253", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": true, + "IsEndpoint": false, + "Explode": false, + "IsRequired": false, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "254", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "255", + "kind": "constant", + "valueType": { + "$id": "256", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "257", + "Name": "body", + "NameInRequest": "body", + "Description": "SAP Application server instance start request body.", + "Type": { + "$ref": "153" + }, + "Location": "Body", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": false, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "258", + "StatusCodes": [ + 202 + ], + "BodyMediaType": "Json", + "Headers": [ + { + "$id": "259", + "Name": "location", + "NameInResponse": "Location", + "Description": "The Location header contains the URL where the status of the long running operation can be checked.", + "Type": { + "$id": "260", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + } + }, + { + "$id": "261", + "Name": "retryAfter", + "NameInResponse": "Retry-After", + "Description": "The Retry-After header can indicate how long the client should wait before polling the operation status.", + "Type": { + "$id": "262", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + } + } + ], + "IsErrorResponse": false + }, + { + "$id": "263", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "156" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "POST", + "RequestBodyMediaType": "Json", + "Uri": "{endpoint}", + "Path": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/MgmtTypeSpec/privateLinkResources/{privateLinkResourcenName}/start", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "LongRunning": { + "$id": "264", + "FinalStateVia": 1, + "FinalResponse": { + "$id": "265", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "156" + }, + "BodyMediaType": "Json" + } + }, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "MgmtTypeSpec.PrivateLinks.start", + "Decorators": [] + } + ], + "Protocol": { + "$id": "266" + }, + "Parent": "MgmtTypeSpecClient", + "Parameters": [ + { + "$ref": "221" + } + ], + "Decorators": [] + }, + { + "$id": "267", + "Name": "Foos", + "Operations": [ + { + "$id": "268", + "Name": "createOrUpdate", + "ResourceName": "Foos", + "Description": "Create a Foo", + "Accessibility": "public", + "Parameters": [ + { + "$id": "269", + "Name": "endpoint", + "NameInRequest": "endpoint", + "Type": { + "$id": "270", + "kind": "url", + "name": "url", + "crossLanguageDefinitionId": "TypeSpec.url" + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "271", + "Type": { + "$id": "272", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "https://management.azure.com" + } + }, + { + "$id": "273", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "274", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "275", + "Type": { + "$id": "276", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "277", + "Name": "subscriptionId", + "NameInRequest": "subscriptionId", + "Description": "The ID of the target subscription. The value must be an UUID.", + "Type": { + "$id": "278", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "279", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "280", + "Name": "resourceGroupName", + "NameInRequest": "resourceGroupName", + "Description": "The name of the resource group. The name is case insensitive.", + "Type": { + "$id": "281", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "282", + "Name": "fooName", + "NameInRequest": "fooName", + "Description": "The name of the Foo", + "Type": { + "$id": "283", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "284", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Description": "Body parameter's content type. Known values are application/json", + "Type": { + "$id": "285", + "kind": "constant", + "valueType": { + "$id": "286", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": true, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "287", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "288", + "kind": "constant", + "valueType": { + "$id": "289", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "290", + "Name": "resource", + "NameInRequest": "resource", + "Description": "Resource create parameters.", + "Type": { + "$ref": "44" + }, + "Location": "Body", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "291", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "44" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + }, + { + "$id": "292", + "StatusCodes": [ + 201 + ], + "BodyType": { + "$ref": "44" + }, + "BodyMediaType": "Json", + "Headers": [ + { + "$id": "293", + "Name": "azureAsyncOperation", + "NameInResponse": "Azure-AsyncOperation", + "Description": "A link to the status monitor", + "Type": { + "$id": "294", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + } + }, + { + "$id": "295", + "Name": "retryAfter", + "NameInResponse": "Retry-After", + "Description": "The Retry-After header can indicate how long the client should wait before polling the operation status.", + "Type": { + "$id": "296", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + } + } + ], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{endpoint}", + "Path": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/MgmtTypeSpec/foos/{fooName}", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "LongRunning": { + "$id": "297", + "FinalStateVia": 0, + "FinalResponse": { + "$id": "298", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "44" + }, + "BodyMediaType": "Json" + } + }, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "MgmtTypeSpec.Foos.createOrUpdate", + "Decorators": [] + }, + { + "$id": "299", + "Name": "get", + "ResourceName": "Foos", + "Description": "Get a Foo", + "Accessibility": "public", + "Parameters": [ + { + "$ref": "269" + }, + { + "$id": "300", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "301", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "302", + "Type": { + "$id": "303", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "304", + "Name": "subscriptionId", + "NameInRequest": "subscriptionId", + "Description": "The ID of the target subscription. The value must be an UUID.", + "Type": { + "$id": "305", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "306", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "307", + "Name": "resourceGroupName", + "NameInRequest": "resourceGroupName", + "Description": "The name of the resource group. The name is case insensitive.", + "Type": { + "$id": "308", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "309", + "Name": "fooName", + "NameInRequest": "fooName", + "Description": "The name of the Foo", + "Type": { + "$id": "310", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "311", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "312", + "kind": "constant", + "valueType": { + "$id": "313", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "314", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "44" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/MgmtTypeSpec/foos/{fooName}", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "MgmtTypeSpec.Foos.get", + "Decorators": [] + }, + { + "$id": "315", + "Name": "delete", + "ResourceName": "Foos", + "Description": "Delete a Foo", + "Accessibility": "public", + "Parameters": [ + { + "$ref": "269" + }, + { + "$id": "316", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "317", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "318", + "Type": { + "$id": "319", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "320", + "Name": "subscriptionId", + "NameInRequest": "subscriptionId", + "Description": "The ID of the target subscription. The value must be an UUID.", + "Type": { + "$id": "321", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "322", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "323", + "Name": "resourceGroupName", + "NameInRequest": "resourceGroupName", + "Description": "The name of the resource group. The name is case insensitive.", + "Type": { + "$id": "324", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "325", + "Name": "fooName", + "NameInRequest": "fooName", + "Description": "The name of the Foo", + "Type": { + "$id": "326", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "327", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "328", + "kind": "constant", + "valueType": { + "$id": "329", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "330", + "StatusCodes": [ + 202 + ], + "BodyMediaType": "Json", + "Headers": [ + { + "$id": "331", + "Name": "location", + "NameInResponse": "Location", + "Description": "The Location header contains the URL where the status of the long running operation can be checked.", + "Type": { + "$id": "332", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + } + }, + { + "$id": "333", + "Name": "retryAfter", + "NameInResponse": "Retry-After", + "Description": "The Retry-After header can indicate how long the client should wait before polling the operation status.", + "Type": { + "$id": "334", + "kind": "int32", + "name": "int32", + "crossLanguageDefinitionId": "TypeSpec.int32", + "decorators": [] + } + } + ], + "IsErrorResponse": false + }, + { + "$id": "335", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "DELETE", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/MgmtTypeSpec/foos/{fooName}", + "BufferResponse": true, + "LongRunning": { + "$id": "336", + "FinalStateVia": 1, + "FinalResponse": { + "$id": "337", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json" + } + }, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "MgmtTypeSpec.Foos.delete", + "Decorators": [] + }, + { + "$id": "338", + "Name": "list", + "ResourceName": "Foo", + "Description": "List Foo resources by resource group", + "Accessibility": "public", + "Parameters": [ + { + "$ref": "269" + }, + { + "$id": "339", + "Name": "apiVersion", + "NameInRequest": "api-version", + "Description": "The API version to use for this operation.", + "Type": { + "$id": "340", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Query", + "IsApiVersion": true, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "DefaultValue": { + "$id": "341", + "Type": { + "$id": "342", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string" + }, + "Value": "2024-05-01" + }, + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "343", + "Name": "subscriptionId", + "NameInRequest": "subscriptionId", + "Description": "The ID of the target subscription. The value must be an UUID.", + "Type": { + "$id": "344", + "kind": "string", + "name": "uuid", + "crossLanguageDefinitionId": "Azure.Core.uuid", + "baseType": { + "$id": "345", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Client", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "346", + "Name": "resourceGroupName", + "NameInRequest": "resourceGroupName", + "Description": "The name of the resource group. The name is case insensitive.", + "Type": { + "$id": "347", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "Location": "Path", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Method", + "Decorators": [], + "SkipUrlEncoding": false + }, + { + "$id": "348", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "349", + "kind": "constant", + "valueType": { + "$id": "350", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "value": "application/json", + "decorators": [] + }, + "Location": "Header", + "IsApiVersion": false, + "IsContentType": false, + "IsEndpoint": false, + "Explode": false, + "IsRequired": true, + "Kind": "Constant", + "Decorators": [], + "SkipUrlEncoding": false + } + ], + "Responses": [ + { + "$id": "351", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$ref": "109" + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{endpoint}", + "Path": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/MgmtTypeSpec/foos", + "BufferResponse": true, + "Paging": { + "$id": "352", + "ItemName": "value", + "NextLinkName": "nextLink" + }, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true, + "CrossLanguageDefinitionId": "MgmtTypeSpec.Foos.list", + "Decorators": [] + } + ], + "Protocol": { + "$id": "353" + }, + "Parent": "MgmtTypeSpecClient", + "Parameters": [ + { + "$ref": "269" + } + ], + "Decorators": [] + } + ], + "Auth": { + "$id": "354", + "OAuth2": { + "$id": "355", + "Scopes": [ + "user_impersonation" + ] + } + } +} diff --git a/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspconfig.yaml b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspconfig.yaml new file mode 100644 index 0000000000000..31632a2b5d922 --- /dev/null +++ b/eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/tspconfig.yaml @@ -0,0 +1,6 @@ +options: + "@azure-tools/typespec-csharp": + flavor: "azure" + namespace: "MgmtTypeSpec" + clear-output-folder: true + examples-dir: "{project-root}/examples" diff --git a/eng/scripts/typespec/Generate-Code.ps1 b/eng/scripts/typespec/Generate-Code.ps1 index b71faf54942a2..5bbe62575f789 100644 --- a/eng/scripts/typespec/Generate-Code.ps1 +++ b/eng/scripts/typespec/Generate-Code.ps1 @@ -35,6 +35,7 @@ function Refresh-Build { $testProjectsLocalDir = Join-Path $packageRoot 'generator' 'TestProjects' 'Local' $basicTypespecTestProject = Join-Path $testProjectsLocalDir "Basic-TypeSpec" +$mgmtTypespecTestProject = Join-Path $testProjectsLocalDir "Mgmt-TypeSpec" Push-Location $packageRoot @@ -47,6 +48,13 @@ Invoke-LoggedCommand (Get-TspCommand "$basicTypespecTestProject/Basic-TypeSpec.t Write-Host "Building BasicTypeSpec" -ForegroundColor Cyan Invoke-LoggedCommand "dotnet build $packageRoot/generator/TestProjects/Local/Basic-TypeSpec/src/BasicTypeSpec.csproj" +Write-Host "Generating MgmtTypeSpec" -ForegroundColor Cyan +Invoke-LoggedCommand (Get-TspCommand "$mgmtTypespecTestProject/main.tsp" $mgmtTypespecTestProject) + +# skip the build for now, we know it won't build +# Write-Host "Building MgmtTypeSpec" -ForegroundColor Cyan +# Invoke-LoggedCommand "dotnet build $packageRoot/generator/TestProjects/Local/Mgmt-TypeSpec/src/MgmtTypeSpec.csproj" + Pop-Location Write-Host 'Code generation is completed.' From b083aa4aea01ba4cc029c6c2d0acf8b5ae0cbb87 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Tue, 26 Nov 2024 14:07:59 +0800 Subject: [PATCH 2/5] update MGC --- eng/Packages.Data.props | 2 +- .../http-client-csharp/generator/Azure.Generator.sln | 12 ------------ .../Azure.Generator/src/Azure.Generator.csproj | 4 +--- 3 files changed, 2 insertions(+), 16 deletions(-) diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index 9be57baffdefa..80d489ecbd6cc 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -254,7 +254,7 @@ - + @@ -30,8 +31,5 @@ Always - - - From d9cfec4aca8f02490deb47ef3fbeb8bafeb55e69 Mon Sep 17 00:00:00 2001 From: Wei Hu Date: Wed, 27 Nov 2024 16:52:21 +0800 Subject: [PATCH 3/5] rename --- eng/Packages.Data.props | 2 +- .../generator/Azure.Generator/src/AzureTypeFactory.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/eng/Packages.Data.props b/eng/Packages.Data.props index 80d489ecbd6cc..82f259bd23c3f 100644 --- a/eng/Packages.Data.props +++ b/eng/Packages.Data.props @@ -254,7 +254,7 @@ - +