Skip to content

Commit f47a4ea

Browse files
Adopt core model scenarios (Azure#50250)
* Adopt core model scenarios * regen * Update class name * package lock * install
1 parent afb2dd2 commit f47a4ea

File tree

20 files changed

+1173
-180
lines changed

20 files changed

+1173
-180
lines changed

eng/Packages.Data.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@
438438

439439
<PropertyGroup>
440440
<TestProxyVersion>1.0.0-dev.20250501.1</TestProxyVersion>
441-
<UnbrandedGeneratorVersion>1.0.0-alpha.20250522.3</UnbrandedGeneratorVersion>
442-
<AzureGeneratorVersion>1.0.0-alpha.20250522.1</AzureGeneratorVersion>
441+
<UnbrandedGeneratorVersion>1.0.0-alpha.20250523.1</UnbrandedGeneratorVersion>
442+
<AzureGeneratorVersion>1.0.0-alpha.20250515.2</AzureGeneratorVersion>
443443
</PropertyGroup>
444444
</Project>

eng/packages/http-client-csharp/eng/scripts/Generate.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ $failingSpecs = @(
7777
Join-Path 'http' 'azure' 'client-generator-core' 'api-version' 'path'
7878
Join-Path 'http' 'azure' 'client-generator-core' 'api-version' 'query'
7979
Join-Path 'http' 'azure' 'core' 'basic'
80-
Join-Path 'http' 'azure' 'core' 'model'
8180
Join-Path 'http' 'azure' 'core' 'page'
8281
Join-Path 'http' 'azure' 'core' 'scalar'
8382
Join-Path 'http' 'azure' 'core' 'traits'

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ public class AzureTypeFactory : ScmTypeFactory
7373
return knownType;
7474
}
7575
}
76+
else if (inputType is InputArrayType inputArrayType)
77+
{
78+
// Handle special collection types
79+
if (KnownAzureTypes.TryGetKnownType(inputArrayType.CrossLanguageDefinitionId, out var knownType))
80+
{
81+
var elementType = CreateCSharpType(inputArrayType.ValueType);
82+
return new CSharpType(knownType, elementType!);
83+
}
84+
}
7685

7786
return base.CreateCSharpTypeCore(inputType);
7887
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal static class KnownAzureTypes
3030
private const string AzureLocationId = "Azure.Core.azureLocation";
3131
private const string ArmIdId = "Azure.Core.armResourceIdentifier";
3232
private const string AzureError = "Azure.Core.Foundations.Error";
33+
private const string EmbeddingVector = "Azure.Core.EmbeddingVector";
3334

3435
private static MethodBodyStatement SerializeTypeWithImplicitOperatorToString(ValueExpression value, ScopedApi<Utf8JsonWriter> writer, ScopedApi<ModelReaderWriterOptions> options, SerializationFormat format)
3536
=> writer.WriteStringValue(value);
@@ -51,7 +52,7 @@ private static ValueExpression DeserializeResponseError(CSharpType valueType,
5152
SerializationFormat format)
5253
=> Static(typeof(JsonSerializer)).Invoke(nameof(JsonSerializer.Deserialize), arguments: [element.GetRawText()], typeArguments: [valueType], callAsAsync: false);
5354

54-
private static readonly IReadOnlyDictionary<string, CSharpType> _idToTypes = new Dictionary<string, CSharpType>
55+
private static readonly IReadOnlyDictionary<string, Type> _idToTypes = new Dictionary<string, Type>
5556
{
5657
[UuidId] = typeof(Guid),
5758
[IPv4AddressId] = typeof(IPAddress),
@@ -60,6 +61,7 @@ private static ValueExpression DeserializeResponseError(CSharpType valueType,
6061
[AzureLocationId] = typeof(AzureLocation),
6162
[ArmIdId] = typeof(ResourceIdentifier),
6263
[AzureError] = typeof(ResponseError),
64+
[EmbeddingVector] = typeof(ReadOnlyMemory<>)
6365
};
6466

6567
private static readonly IReadOnlyDictionary<Type, SerializationExpression> _typeToSerializationExpression = new Dictionary<Type, SerializationExpression>
@@ -82,7 +84,7 @@ private static ValueExpression DeserializeResponseError(CSharpType valueType,
8284
[typeof(ResponseError)] = DeserializeResponseError,
8385
};
8486

85-
public static bool TryGetKnownType(string id, [MaybeNullWhen(false)] out CSharpType type) => _idToTypes.TryGetValue(id, out type);
87+
public static bool TryGetKnownType(string id, [MaybeNullWhen(false)] out Type type) => _idToTypes.TryGetValue(id, out type);
8688

8789
public static bool TryGetJsonSerializationExpression(Type type, [MaybeNullWhen(false)] out SerializationExpression expression) => _typeToSerializationExpression.TryGetValue(type, out expression);
8890

eng/packages/http-client-csharp/generator/Azure.Generator/src/Properties/launchSettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
"commandName": "Executable",
4646
"executablePath": "dotnet"
4747
},
48+
"http-azure-core-model": {
49+
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/azure/core/model -g AzureStubGenerator",
50+
"commandName": "Executable",
51+
"executablePath": "dotnet"
52+
},
4853
"http-azure-special-headers-client-request-id": {
4954
"commandLineArgs": "$(SolutionDir)/../dist/generator/Microsoft.TypeSpec.Generator.dll $(SolutionDir)/TestProjects/Spector/http/azure/special-headers/client-request-id -g AzureStubGenerator",
5055
"commandName": "Executable",
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using _Specs_.Azure.Core.Model;
7+
using NUnit.Framework;
8+
9+
namespace TestProjects.Spector.Tests.Http.Azure.Core.Model
10+
{
11+
public class CoreModelTests : SpectorTestBase
12+
{
13+
[SpectorTest]
14+
public Task Azure_Core_Model_AzureCoreEmbeddingVector_get() => Test(async (host) =>
15+
{
16+
var response = await new ModelClient(host, null).GetAzureCoreEmbeddingVectorClient().GetAsync();
17+
var result = response.Value.ToArray();
18+
CollectionAssert.AreEqual(new[] { 0, 1, 2, 3, 4 }, result);
19+
});
20+
21+
[SpectorTest]
22+
public Task Azure_Core_Model_AzureCoreEmbeddingVector_put() => Test(async (host) =>
23+
{
24+
var response = await new ModelClient(host, null).GetAzureCoreEmbeddingVectorClient().PutAsync(new ReadOnlyMemory<int>(new[] { 0, 1, 2, 3, 4 }));
25+
Assert.AreEqual(204, response.Status);
26+
});
27+
28+
[SpectorTest]
29+
public Task Azure_Core_Model_AzureCoreEmbeddingVector_post() => Test(async (host) =>
30+
{
31+
var body = new AzureEmbeddingModel(new ReadOnlyMemory<int>(new[] { 0, 1, 2, 3, 4 }));
32+
var response = await new ModelClient(host, null).GetAzureCoreEmbeddingVectorClient().PostAsync(body);
33+
CollectionAssert.AreEqual(new[] { 5, 6, 7, 8, 9 }, response.Value.Embedding.ToArray());
34+
});
35+
}
36+
}

eng/packages/http-client-csharp/generator/TestProjects/Spector.Tests/TestProjects.Spector.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<ProjectReference Include="..\Spector\http\azure\special-headers\client-request-id\src\Azure.SpecialHeaders.XmsClientRequestId.csproj" />
2121
<ProjectReference Include="..\Spector\http\azure\core\lro\standard\src\_Specs_.Azure.Core.Lro.Standard.csproj" />
2222
<ProjectReference Include="..\Spector\http\azure\core\lro\rpc\src\_Specs_.Azure.Core.Lro.Rpc.csproj" />
23+
<ProjectReference Include="..\Spector\http\azure\core\model\src\_Specs_.Azure.Core.Model.csproj" />
2324
<ProjectReference Include="..\Spector\http\type\array\src\Type.Array.csproj" />
2425
<ProjectReference Include="..\Spector\http\type\enum\extensible\src\Type.Enum.Extensible.csproj" />
2526
<ProjectReference Include="..\Spector\http\type\enum\fixed\src\Type.Enum.Fixed.csproj" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"package-name": "_Specs_.Azure.Core.Model",
3+
"license": {
4+
"name": "MIT License",
5+
"company": "Microsoft Corporation",
6+
"link": "https://mit-license.org",
7+
"header": "Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT License.",
8+
"description": "Copyright (c) Microsoft Corporation\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the “Software”), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE."
9+
}
10+
}
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}") = "_Specs_.Azure.Core.Model", "src\_Specs_.Azure.Core.Model.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

eng/packages/http-client-csharp/generator/TestProjects/Spector/http/azure/core/model/src/Generated/AzureCoreEmbeddingVector.cs

Lines changed: 47 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)