Skip to content

Commit

Permalink
Merge branch 'main' into bump-tcgc-version
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang authored Dec 9, 2024
2 parents b016f17 + b654807 commit 09be9b2
Show file tree
Hide file tree
Showing 56 changed files with 732 additions and 499 deletions.
8 changes: 8 additions & 0 deletions .chronus/changes/ReleaseDashboardsStep1-2024-11-5-14-40-39.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
changeKind: internal
packages:
- "@typespec/http-specs"
- "@typespec/spector"
---

Adding scripts to package.json
8 changes: 8 additions & 0 deletions .chronus/changes/nullable-2024-11-6-1-23-27.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking
changeKind: fix
packages:
- "@typespec/http-server-csharp"
---

Fix nullable types, anonymous types, and safeInt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@typespec/http-specs"
---

update code in versioning/removed and removed type/model/templated.
4 changes: 4 additions & 0 deletions eng/common/config/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ export default defineConfig({
misc: {
description: "Misc labels",
labels: {
"1_0_E2E": {
color: "5319E7",
description: "",
},
"Client Emitter Migration": {
color: "FD92F0",
description: "",
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
"test:e2e": "pnpm -r run test:e2e",
"update-latest-docs": "pnpm -r run update-latest-docs",
"watch": "tsc --build ./tsconfig.ws.json --watch",
"sync-labels": "tsx ./eng/common/scripts/labels/sync-labels.ts --config ./eng/common/config/labels.ts"
"sync-labels": "tsx ./eng/common/scripts/labels/sync-labels.ts --config ./eng/common/config/labels.ts",
"validate-scenarios": "pnpm -r --filter=@typespec/http-specs run validate-scenarios",
"validate-mock-apis": "pnpm -r --filter=@typespec/http-specs run validate-mock-apis",
"generate-scenarios-summary": "pnpm -r --filter=@typespec/http-specs run generate-scenarios-summary",
"upload-manifest": "pnpm -r --filter=@typespec/http-specs run upload-manifest"
},
"devDependencies": {
"@chronus/chronus": "^0.13.0",
Expand Down
13 changes: 8 additions & 5 deletions packages/http-client-csharp/eng/scripts/Generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ foreach ($directory in $directories) {
continue
}

# srv-driven contains two separate specs, for two separate clients. We need to generate both.
if ($folders.Contains("srv-driven")) {
Generate-Srv-Driven $directory.FullName $generationDir -generateStub $stubbed
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v1", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v1")
$cadlRanchLaunchProjects.Add($($folders -join "-") + "-v2", $("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))") + "/v2")
continue
}

$cadlRanchLaunchProjects.Add(($folders -join "-"), ("TestProjects/CadlRanch/$($subPath.Replace([System.IO.Path]::DirectorySeparatorChar, '/'))"))
if ($LaunchOnly) {
continue
Expand All @@ -114,11 +122,6 @@ foreach ($directory in $directories) {
exit $LASTEXITCODE
}

# srv-driven contains two separate specs, for two separate clients. We need to generate both.
if ($folders.Contains("srv-driven")) {
Generate-Srv-Driven $directory.FullName $generationDir -generateStub $stubbed
}

# TODO need to build but depends on https://github.com/Azure/autorest.csharp/issues/4463
}

Expand Down
25 changes: 19 additions & 6 deletions packages/http-client-csharp/eng/scripts/Generation.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,27 @@ function Generate-Srv-Driven {
[bool]$createOutputDirIfNotExist = $true
)

$specFilePath = $(Join-Path $specFilePath "old.tsp")
$outputDir = $(Join-Path $outputDir "v1")
if ($createOutputDirIfNotExist -and -not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir | Out-Null
$v1Dir = $(Join-Path $outputDir "v1")
if ($createOutputDirIfNotExist -and -not (Test-Path $v1Dir)) {
New-Item -ItemType Directory -Path $v1Dir | Out-Null
}

Write-Host "Generating http\resiliency\srv-driven\v1" -ForegroundColor Cyan
Invoke (Get-TspCommand $specFilePath $outputDir -generateStub $generateStub -namespaceOverride "Resiliency.ServiceDriven.V1")
$v2Dir = $(Join-Path $outputDir "v2")
if ($createOutputDirIfNotExist -and -not (Test-Path $v2Dir)) {
New-Item -ItemType Directory -Path $v2Dir | Out-Null
}

## get the last two directories of the output directory and add V1/V2 to disambiguate the namespaces
$namespaceRoot = $(($outputDir.Split([System.IO.Path]::DirectorySeparatorChar)[-2..-1] | `
ForEach-Object { $_.Substring(0,1).ToUpper() + $_.Substring(1) }) -replace '-(\p{L})', { $_.Groups[1].Value.ToUpper() } -replace '\W', '' -join ".")
$v1NamespaceOverride = $namespaceRoot + ".V1"
$v2NamespaceOverride = $namespaceRoot + ".V2"

$v1SpecFilePath = $(Join-Path $specFilePath "old.tsp")
$v2SpecFilePath = $(Join-Path $specFilePath "main.tsp")

Invoke (Get-TspCommand $v1SpecFilePath $v1Dir -generateStub $generateStub -namespaceOverride $v1NamespaceOverride)
Invoke (Get-TspCommand $v2SpecFilePath $v2Dir -generateStub $generateStub -namespaceOverride $v2NamespaceOverride)

# exit if the generation failed
if ($LASTEXITCODE -ne 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ foreach ($directory in $directories) {
continue
}

if ($subPath.Contains("srv-driven")) {
if ($subPath.Contains("v1")) {
# this will generate v1 and v2 so we only need to call it once for one of the versions
Generate-Srv-Driven ($(Join-Path $specsDirectory $subPath) | Split-Path) $($outputDir | Split-Path) -createOutputDirIfNotExist $false
}
continue
}

$command = Get-TspCommand $specFile $outputDir
Invoke $command
# exit if the generation failed
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

# srv-driven contains two separate specs, for two separate clients. We need to generate both.
if ($subPath.Contains('srv-driven')) {
Generate-Srv-Driven $(Join-Path $specsDirectory $subPath) $outputDir -createOutputDirIfNotExist $false
}
}

# test all
Expand Down
16 changes: 6 additions & 10 deletions packages/http-client-csharp/eng/scripts/Test-CadlRanch.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ foreach ($directory in $directories) {
if (-not (Compare-Paths $subPath $filter)) {
continue
}

if ($subPath.Contains($(Join-Path 'srv-driven' 'v1'))) {
continue
}

$testPath = "$cadlRanchRoot.Tests"
$testFilter = "TestProjects.CadlRanch.Tests"
Expand Down Expand Up @@ -67,21 +63,21 @@ foreach ($directory in $directories) {
Generate-Versioning ($(Join-Path $specsDirectory $subPath) | Split-Path) $($outputDir | Split-Path) -createOutputDirIfNotExist $false
}
}
elseif ($subPath.Contains("srv-driven")) {
if ($subPath.Contains("v1")) {
Generate-Srv-Driven ($(Join-Path $specsDirectory $subPath) | Split-Path) $($outputDir | Split-Path) -createOutputDirIfNotExist $false
}
}
else {
$command = Get-TspCommand $specFile $outputDir
Invoke $command
}

# exit if the generation failed
if ($LASTEXITCODE -ne 0) {
exit $LASTEXITCODE
}

# srv-driven contains two separate specs, for two separate clients. We need to generate both.
if ($subPath.Contains("srv-driven")) {
Generate-Srv-Driven $(Join-Path $specsDirectory $subPath) $outputDir -createOutputDirIfNotExist $false
}

Write-Host "Testing $subPath" -ForegroundColor Cyan
$command = "dotnet test $cadlRanchCsproj --filter `"FullyQualifiedName~$testFilter`""
Invoke $command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,13 @@
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-resiliency-srv-driven": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/resiliency/srv-driven -p StubLibraryPlugin",
"http-resiliency-srv-driven-v1": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/resiliency/srv-driven/v1 -p StubLibraryPlugin",
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
"http-resiliency-srv-driven-v2": {
"commandLineArgs": "$(SolutionDir)/TestProjects/CadlRanch/http/resiliency/srv-driven/v2 -p StubLibraryPlugin",
"commandName": "Executable",
"executablePath": "$(SolutionDir)/../dist/generator/Microsoft.Generator.CSharp.exe"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@
// Licensed under the MIT License.

using NUnit.Framework;
using Resiliency.ServiceDriven.V1;
using Resiliency.SrvDriven.V1;
using System.Threading.Tasks;

namespace TestProjects.CadlRanch.Tests.Http.Resiliency.SrvDriven
namespace TestProjects.CadlRanch.Tests.Http.Resiliency.SrvDriven.V1
{
/// <summary>
/// Contains tests for the service-driven resiliency V1 client.
/// </summary>
public partial class SrvDrivenTests : CadlRanchTestBase
public partial class SrvDrivenV2Tests : CadlRanchTestBase
{
private const string ServiceDeploymentV1 = "v1";
private const string ServiceDeploymentV2 = "v2";

// This test validates the v1 client behavior when both the service deployment and api version are set to V1.
[CadlRanchTest]
public Task AddOptionalParamFromNone_V1Client_V1Service_WithApiVersionV1() => Test(async (host) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

using NUnit.Framework;
using System.Threading.Tasks;
using Resiliency.ServiceDriven;
using Resiliency.SrvDriven.V2;

namespace TestProjects.CadlRanch.Tests.Http.Resiliency.SrvDriven
namespace TestProjects.CadlRanch.Tests.Http.Resiliency.SrvDriven.V2
{
public partial class SrvDrivenTests : CadlRanchTestBase
public partial class SrvDrivenV2Tests : CadlRanchTestBase
{
private const string ServiceDeploymentV1 = "v1";
private const string ServiceDeploymentV2 = "v2";

[CadlRanchTest]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

using System;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using Versioning.Removed.V1;
using Versioning.Removed.V1.Models;

namespace TestProjects.CadlRanch.Tests.Http.Versioning.Removed.V1
{
Expand Down Expand Up @@ -39,5 +41,15 @@ public void TestRemovedMembers()
var enumType = typeof(RemovedClientOptions.ServiceVersion);
Assert.AreEqual(new string[] { "V1" }, enumType.GetEnumNames());
}

[CadlRanchTest]
public Task Versioning_Removed_V3Model() => Test(async (host) =>
{
var model = new ModelV3("123", EnumV3.EnumMemberV1);
var response = await new RemovedClient(host).ModelV3Async(model);
Assert.AreEqual(200, response.GetRawResponse().Status);
Assert.AreEqual("123", response.Value.Id);
Assert.AreEqual(EnumV3.EnumMemberV1, response.Value.EnumProp);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ internal partial class CadlRanchTestAttribute : TestAttribute, IApplyToTest
{
string clientCodeDirectory = GetGeneratedDirectory(test);

if (!Directory.Exists(clientCodeDirectory))
{
// Not all cadl-ranch scenarios use kebab-case directories, so try again without kebab-case.
clientCodeDirectory = GetGeneratedDirectory(test, false);
}

var clientCsFile = GetClientCsFile(clientCodeDirectory);

TestContext.Progress.WriteLine($"Checking if '{clientCsFile}' is a stubbed implementation.");
Expand Down Expand Up @@ -69,21 +75,26 @@ private static void SkipTest(Test test)
.FirstOrDefault();
}

private static string GetGeneratedDirectory(Test test)
private static string GetGeneratedDirectory(Test test, bool kebabCaseDirectories = true)
{
var namespaceParts = test.FullName.Split('.').Skip(3);
namespaceParts = namespaceParts.Take(namespaceParts.Count() - 2);
var clientCodeDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", "..", "..", "TestProjects", "CadlRanch");
foreach (var part in namespaceParts)
{
clientCodeDirectory = Path.Combine(clientCodeDirectory, FixName(part));
clientCodeDirectory = Path.Combine(clientCodeDirectory, FixName(part, kebabCaseDirectories));
}
return Path.Combine(clientCodeDirectory, "src", "Generated");
}

private static string FixName(string part)
private static string FixName(string part, bool kebabCaseDirectories)
{
return ToKebabCase().Replace(part.StartsWith("_", StringComparison.Ordinal) ? part.Substring(1) : part, "-$1").ToLower();
if (kebabCaseDirectories)
{
return ToKebabCase().Replace(part.StartsWith("_", StringComparison.Ordinal) ? part.Substring(1) : part, "-$1").ToLowerInvariant();
}
// Use camelCase
return char.ToLowerInvariant(part[0]) + part[1..];
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"output-folder": ".",
"namespace": "Resiliency.ServiceDriven.V1",
"library-name": "Resiliency.ServiceDriven.V1",
"namespace": "Resiliency.SrvDriven.V1",
"library-name": "Resiliency.SrvDriven.V1",
"use-model-reader-writer": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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}") = "Resiliency.ServiceDriven", "src\Resiliency.ServiceDriven.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resiliency.SrvDriven.V1", "src\Resiliency.SrvDriven.V1.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace Resiliency.ServiceDriven.V1
namespace Resiliency.SrvDriven.V1
{
public partial class ResiliencyServiceDrivenClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System.ClientModel.Primitives;

namespace Resiliency.ServiceDriven.V1
namespace Resiliency.SrvDriven.V1
{
public partial class ResiliencyServiceDrivenClientOptions : ClientPipelineOptions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>This is the Resiliency.ServiceDriven client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation Resiliency.ServiceDriven</AssemblyTitle>
<Description>This is the Resiliency.SrvDriven.V1 client library for developing .NET applications with rich experience.</Description>
<AssemblyTitle>SDK Code Generation Resiliency.SrvDriven.V1</AssemblyTitle>
<Version>1.0.0-beta.1</Version>
<PackageTags>Resiliency.ServiceDriven</PackageTags>
<PackageTags>Resiliency.SrvDriven.V1</PackageTags>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"output-folder": ".",
"namespace": "Resiliency.SrvDriven.V2",
"library-name": "Resiliency.SrvDriven.V2",
"use-model-reader-writer": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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}") = "Resiliency.ServiceDriven.V1", "src\Resiliency.ServiceDriven.V1.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resiliency.SrvDriven.V2", "src\Resiliency.SrvDriven.V2.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace Resiliency.ServiceDriven
namespace Resiliency.SrvDriven.V2
{
public partial class ResiliencyServiceDrivenClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

using System.ClientModel.Primitives;

namespace Resiliency.ServiceDriven
namespace Resiliency.SrvDriven.V2
{
public partial class ResiliencyServiceDrivenClientOptions : ClientPipelineOptions
{
Expand Down
Loading

0 comments on commit 09be9b2

Please sign in to comment.