Repository navigation
Fix swagger generator & regenerate Helix client - #17372
Conversation
There was a problem hiding this comment.
Pull request overview
Updates Arcade’s SwaggerGenerator to be compatible with newer Handlebars behavior, and regenerates the Helix C# client from the latest Swagger/OpenAPI surface (including new queue stats shape and support for filtering jobs by properties).
Changes:
- Harden SwaggerGenerator modeling and update helper invocation implementation for newer Handlebars behavior.
- Regenerate Helix C# client: add
propertiesquery support, introduceQueueStatsSummary, remove Telemetry surface, and update related models. - Update Helix JobSender queue stats logging and adjust HelixService unit test mocks for the new client method signature.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.CodeGenerator/Modeler/ServiceClientModelFactory.cs | Adds null-safety when reading OpenAPI response content and extensions. |
| src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.CodeGenerator/Languages/csharp/ServiceClient.hb | Updates generated exception serialization members with explicit [Obsolete] messages. |
| src/Microsoft.DotNet.SwaggerGenerator/Microsoft.DotNet.SwaggerGenerator.CodeGenerator/HelperFactory.cs | Reworks helper/block-helper invocation for newer Handlebars APIs. |
| src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/HelixServiceTests.cs | Updates mocks for Job.ListAsync signature that now includes properties. |
| src/Microsoft.DotNet.Helix/JobSender/JobDefinition.cs | Updates queue stats logging to consume new QueueStatsSummary shape and string durations. |
| src/Microsoft.DotNet.Helix/Client/CSharp/RequestUriBuilderExtensions.cs | Adds dictionary query serialization helper for name[key]=value patterns. |
| src/Microsoft.DotNet.Helix/Client/CSharp/QueueStats.cs | Removes legacy QueueStats model (superseded by QueueStatsSummary). |
| src/Microsoft.DotNet.Helix/Client/CSharp/JobStatus.cs | Removes legacy JobStatus partial helper (superseded by regenerated models). |
| src/Microsoft.DotNet.Helix/Client/CSharp/JobCreationResult.cs | Removes legacy JobCreationResult partial (superseded by regenerated models). |
| src/Microsoft.DotNet.Helix/Client/CSharp/HelixApi.cs | Updates HelixApi implementation imports to support regenerated client code. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Telemetry.cs | Removes Telemetry client surface from generated code. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/QueueStatsSummary.cs | Adds new queue stats model produced by latest API. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/QueueInfo.cs | Extends queue info with protected-mode fields. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/JobStatus.cs | Removes generated legacy JobStatus model. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/JobInfo.cs | Removes generated legacy JobInfo model. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Models/JobCreationResult.cs | Updates validity checks and adds QueueStatsSummary to job creation result. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Job.cs | Adds properties parameter to job list API and query construction. |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/HelixApi.cs | Regenerated client core (removes Telemetry property, pipeline tweaks, Obsolete messages). |
| src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Aggregate.cs | Adds properties parameter to aggregate APIs and query construction. |
Suppressed comments (5)
src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Aggregate.cs:523
- Serializing the properties dictionary to a JSON string will produce a single query parameter value (e.g. Properties=%7B...%7D) which typically won’t bind to Helix’s dictionary query filters. Use the RequestUriBuilder dictionary overload (name[key]=value) consistently, as is done in Job.ListAsync.
if (properties != default(IImmutableDictionary<string, string>))
{
_url.AppendQuery("Properties", Client.Serialize(properties));
}
src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Aggregate.cs:639
- Serializing the properties dictionary to a JSON string will produce a single query parameter value (e.g. Properties=%7B...%7D) which typically won’t bind to Helix’s dictionary query filters. Use the RequestUriBuilder dictionary overload (name[key]=value) consistently, as is done in Job.ListAsync.
if (properties != default(IImmutableDictionary<string, string>))
{
_url.AppendQuery("Properties", Client.Serialize(properties));
}
src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Aggregate.cs:887
- Serializing the properties dictionary to a JSON string will produce a single query parameter value (e.g. Properties=%7B...%7D) which typically won’t bind to Helix’s dictionary query filters. Use the RequestUriBuilder dictionary overload (name[key]=value) consistently, as is done in Job.ListAsync.
if (properties != default(IImmutableDictionary<string, string>))
{
_url.AppendQuery("Properties", Client.Serialize(properties));
}
src/Microsoft.DotNet.Helix/Client/CSharp/generated-code/Aggregate.cs:1069
- Serializing the properties dictionary to a JSON string will produce a single query parameter value (e.g. Properties=%7B...%7D) which typically won’t bind to Helix’s dictionary query filters. Use the RequestUriBuilder dictionary overload (name[key]=value) consistently, as is done in Job.ListAsync.
if (properties != default(IImmutableDictionary<string, string>))
{
_url.AppendQuery("Properties", Client.Serialize(properties));
}
src/Microsoft.DotNet.Helix/Sdk.Tests/Microsoft.DotNet.Helix.Sdk.Tests/HelixServiceTests.cs:40
- PR description and linked issue imply job queries should be filterable by job properties, but HelixService.GetJobsForBuildAsync still calls Job.ListAsync(source: ..., count: 100_000) and filters BuildId client-side. Consider updating HelixService to pass a properties filter (e.g., { "BuildId": buildId }) and extend this test to assert the properties argument so the intended fix is exercised.
api.Job
.Setup(j => j.ListAsync(null, It.IsAny<int?>(), null, null, It.IsAny<IImmutableDictionary<string, string>>(), It.IsAny<string>(), null, It.IsAny<CancellationToken>()))
.Callback<string, int?, string, string, IImmutableDictionary<string, string>, string, string, CancellationToken>((_, count, _, _, _, source, _, _) =>
{
capturedCount = count;
capturedSource = source;
})
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| string avgRun = stats.AverageRunDuration; | ||
| string estWait = stats.EstimatedWait; | ||
| string snapshot = FormatSnapshotTime(stats.GeneratedAt); | ||
|
|
||
| bool overSla = stats.EstimatedWait is TimeSpan wait && wait > QueueWaitSlaThreshold; | ||
| bool overSla = TimeSpan.TryParse(stats.EstimatedWait, out TimeSpan wait) && wait > QueueWaitSlaThreshold; | ||
| TimeSpan? snapshotAge = stats.GeneratedAt is DateTimeOffset gen |
| if (properties != default(IImmutableDictionary<string, string>)) | ||
| { | ||
| _url.AppendQuery("Properties", Client.Serialize(properties)); | ||
| } |
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
|
@chcosta this PR changes a bit the Not sure who depends on this API where though. |
|
I think the two Copilot findings are worth addressing |
Summary
Running
dotnet build /t:GenerateSwaggerCodeinsrc/Microsoft.DotNet.Helix/Client/CSharpwas failing after the earlier bump ofHandlebars.Netfrom 1.11.5 to 2.4.1. The 2.x release changed the helper delegate model (TextWriter/object[]→EncodedTextWriter/Arguments), movedUndefinedBindingResult, and added anincludeZeroparameter toHandlebarsUtils.IsTruthyOrNonEmpty, which brokeHelperFactory's expression-tree adapter. This PR updates the code generator so it works against the new API, regenerates the Helix client, and cleans up handwritten shims that are no longer needed.Changes
Microsoft.DotNet.SwaggerGenerator.CodeGeneratorHelperFactoryto bind[HelperMethod]/[BlockHelperMethod]helpers via reflection instead of a compiledExpressiontree. This maps the newHandlebarsHelper/HandlebarsBlockHelpersignatures onto the existing(TextWriter output, object context, Action<TextWriter, object> template, ...)helper convention used across the templates.SafeTextWriterwrapper overEncodedTextWriterso helper output stays raw (no HTML entity encoding of<,>,=, etc. in generated C#).IsTruthyOrNonEmptycall to pass the newincludeZeroargument and fixed the lookup ofHandlebarsDotNet.UndefinedBindingResult(moved out ofCompiler).C# language template (
Languages/csharp/ServiceClient.hb)RestApiException/RestApiException<T>serialization ctor andGetObjectDataoverrides with[Obsolete("Formatter-based serialization is obsolete and should not be used.")]to satisfySYSLIB0051/CS0672on modern TFMs.Helix client (
src/Microsoft.DotNet.Helix/Client/CSharp)generated-code/against the currenthttps://helix.dot.net/api/openapi.json. This picks up new server-side models (e.g.QueueStatsSummary) and removes types no longer in the API (JobInfo,JobStatus,Telemetry).JobCreationResult.cs(partial that addedQueueStats)QueueStats.cs(replaced by generatedQueueStatsSummary)JobStatus.cs(IsCompletedextension on a type that no longer exists in the OpenAPI doc)Validation
dotnet build /t:GenerateSwaggerCodeinsrc/Microsoft.DotNet.Helix/Client/CSharp— succeeds (10 pre-existingcollectionFormatschema warnings from the OpenAPI doc, 0 errors).dotnet build Microsoft.DotNet.Helix.Client.csproj— succeeds, 0 warnings, 0 errors.git diff --check— clean.