Skip to content

Commit 36c19ab

Browse files
authored
Initialize generation test for mgmt (Azure#47328)
1 parent d454341 commit 36c19ab

File tree

68 files changed

+10505
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+10505
-0
lines changed

eng/packages/http-client-csharp/generator/Azure.Generator/src/AzureTypeFactory.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using Azure.Core;
45
using Azure.Generator.Primitives;
56
using Azure.Generator.Providers;
67
using Azure.Generator.Providers.Abstraction;
78
using Microsoft.Generator.CSharp.ClientModel;
89
using Microsoft.Generator.CSharp.ClientModel.Providers;
10+
using Microsoft.Generator.CSharp.ClientModel.Snippets;
11+
using Microsoft.Generator.CSharp.Expressions;
912
using Microsoft.Generator.CSharp.Input;
1013
using Microsoft.Generator.CSharp.Primitives;
14+
using Microsoft.Generator.CSharp.Snippets;
15+
using Microsoft.Generator.CSharp.Statements;
16+
using System;
17+
using System.ClientModel.Primitives;
18+
using System.Text.Json;
19+
using static Microsoft.Generator.CSharp.Snippets.Snippet;
1120

1221
namespace Azure.Generator
1322
{
@@ -70,5 +79,42 @@ public class AzureTypeFactory : ScmTypeFactory
7079

7180
return null;
7281
}
82+
83+
/// <inheritdoc/>
84+
public override ValueExpression GetValueTypeDeserializationExpression(Type valueType, ScopedApi<JsonElement> element, SerializationFormat format)
85+
{
86+
var expression = GetValueTypeDeserializationExpressionCore(valueType, element, format);
87+
return expression ?? base.GetValueTypeDeserializationExpression(valueType, element, format);
88+
}
89+
90+
private ValueExpression? GetValueTypeDeserializationExpressionCore(
91+
Type valueType,
92+
ScopedApi<JsonElement> element,
93+
SerializationFormat format)
94+
{
95+
return valueType switch
96+
{
97+
Type t when t == typeof(ResourceIdentifier) =>
98+
New.Instance(valueType, element.GetString()),
99+
_ => null,
100+
};
101+
}
102+
103+
/// <inheritdoc/>
104+
public override MethodBodyStatement SerializeValueType(CSharpType type, SerializationFormat serializationFormat, ValueExpression value, Type valueType, ScopedApi<Utf8JsonWriter> utf8JsonWriter, ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter)
105+
{
106+
var statement = SerializeValueTypeCore(type, serializationFormat, value, valueType, utf8JsonWriter, mrwOptionsParameter);
107+
return statement ?? base.SerializeValueType(type, serializationFormat, value, valueType, utf8JsonWriter, mrwOptionsParameter);
108+
}
109+
110+
private MethodBodyStatement? SerializeValueTypeCore(CSharpType type, SerializationFormat serializationFormat, ValueExpression value, Type valueType, ScopedApi<Utf8JsonWriter> utf8JsonWriter, ScopedApi<ModelReaderWriterOptions> mrwOptionsParameter)
111+
{
112+
return valueType switch
113+
{
114+
Type t when t == typeof(ResourceIdentifier) =>
115+
utf8JsonWriter.WriteStringValue(value.Property(nameof(ResourceIdentifier.Name))),
116+
_ => null,
117+
};
118+
}
73119
}
74120
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"output-folder": ".",
3+
"namespace": "MgmtTypeSpec",
4+
"library-name": "MgmtTypeSpec",
5+
"use-model-reader-writer": true
6+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29709.97
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MgmtTypeSpec", "src\MgmtTypeSpec.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU
17+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU
19+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU
20+
{8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU
21+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
22+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU
23+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU
24+
{A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU
25+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
26+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU
27+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU
28+
{FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU
29+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
30+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU
32+
{85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU
33+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
34+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU
35+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU
36+
{28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU
41+
EndGlobalSection
42+
GlobalSection(SolutionProperties) = preSolution
43+
HideSolutionNode = FALSE
44+
EndGlobalSection
45+
GlobalSection(ExtensibilityGlobals) = postSolution
46+
SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE}
47+
EndGlobalSection
48+
EndGlobal
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "@azure-tools/typespec-client-generator-core";
2+
3+
using TypeSpec.Http;
4+
using TypeSpec.Rest;
5+
using Azure.ResourceManager;
6+
using Azure.ClientGenerator.Core;
7+
8+
namespace MgmtTypeSpec;
9+
10+
#suppress "@azure-tools/typespec-providerhub-controller/no-resource-operations" "Expected for private links"
11+
model PrivateLinkResource is ProxyResource<PrivateLinkResourceProperties> {
12+
...PrivateLinkResourceParameter;
13+
...ManagedServiceIdentityProperty;
14+
}
15+
16+
@armResourceOperations(PrivateLinkResource)
17+
interface PrivateLinks {
18+
/** list private links on the given resource */
19+
@clientName("GetAllPrivateLinkResources")
20+
listByMongoCluster is ArmResourceListByParent<PrivateLinkResource>;
21+
22+
/**
23+
* Starts the SAP Application Server Instance.
24+
*/
25+
start is ArmResourceActionAsync<
26+
PrivateLinkResource,
27+
{
28+
@doc("SAP Application server instance start request body.")
29+
@body
30+
body?: StartRequest;
31+
},
32+
Foundations.OperationStatusResult
33+
>;
34+
}
35+
36+
/**
37+
* Start SAP instance(s) request body.
38+
*/
39+
model StartRequest {
40+
/**
41+
* The boolean value indicates whether to start the virtual machines before starting the SAP instances.
42+
*/
43+
startVm?: boolean;
44+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import "@azure-tools/typespec-client-generator-core";
2+
3+
using TypeSpec.Http;
4+
using TypeSpec.Rest;
5+
using Azure.ResourceManager;
6+
using Azure.ClientGenerator.Core;
7+
8+
namespace MgmtTypeSpec;
9+
10+
@resource("foos")
11+
model Foo is TrackedResource<FooProperties> {
12+
...ResourceNameParameter<Foo, SegmentName = "foos">;
13+
14+
...ExtendedLocationProperty;
15+
}
16+
17+
@useSystemTextJsonConverter("csharp")
18+
model FooProperties {
19+
/** the service url */
20+
serviceUrl?: url;
21+
22+
/** something */
23+
something?: string;
24+
25+
/** boolean value */
26+
boolValue?: boolean;
27+
28+
/** float value */
29+
floatValue?: float32;
30+
31+
/** double value */
32+
doubleValue?: float64;
33+
}
34+
35+
@armResourceOperations
36+
interface Foos {
37+
createOrUpdate is ArmResourceCreateOrUpdateAsync<Foo>;
38+
39+
get is ArmResourceRead<Foo>;
40+
41+
delete is ArmResourceDeleteWithoutOkAsync<Foo>;
42+
43+
list is ArmResourceListByParent<Foo>;
44+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
import "@azure-tools/typespec-azure-resource-manager";
3+
import "./PrivateEndpointConnection.tsp";
4+
import "./foo.tsp";
5+
6+
using TypeSpec.Versioning;
7+
using Azure.ResourceManager;
8+
9+
@armProviderNamespace
10+
@service({
11+
title: "MgmtTestClient",
12+
})
13+
@versioned(Versions)
14+
@armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5)
15+
namespace MgmtTypeSpec;
16+
17+
interface Operations extends Azure.ResourceManager.Operations {}
18+
19+
/** The available API versions. */
20+
enum Versions {
21+
/** Azure Cosmos DB for Mongo vCore clusters api version 2024-03-01-preview. */
22+
@useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1)
23+
@useDependency(Azure.Core.Versions.v1_0_Preview_1)
24+
v2024_05_01: "2024-05-01",
25+
}

eng/packages/http-client-csharp/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Foos.RestClient.cs

Lines changed: 113 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)