Skip to content

Fix swagger generator & regenerate Helix client - #17372

Merged
premun merged 2 commits into
dotnet:mainfrom
premun:prvysoky/property-filtering
Aug 20, 2026
Merged

premun merged 2 commits into
dotnet:mainfrom
premun:prvysoky/property-filtering

Conversation

@premun

@premun premun commented Aug 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Running dotnet build /t:GenerateSwaggerCode in src/Microsoft.DotNet.Helix/Client/CSharp was failing after the earlier bump of Handlebars.Net from 1.11.5 to 2.4.1. The 2.x release changed the helper delegate model (TextWriter/object[] → EncodedTextWriter/Arguments), moved UndefinedBindingResult, and added an includeZero parameter to HandlebarsUtils.IsTruthyOrNonEmpty, which broke HelperFactory'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.CodeGenerator

  • Rewrote HelperFactory to bind [HelperMethod] / [BlockHelperMethod] helpers via reflection instead of a compiled Expression tree. This maps the new HandlebarsHelper / HandlebarsBlockHelper signatures onto the existing (TextWriter output, object context, Action<TextWriter, object> template, ...) helper convention used across the templates.
  • Introduced a small SafeTextWriter wrapper over EncodedTextWriter so helper output stays raw (no HTML entity encoding of <, >, =, etc. in generated C#).
  • Updated the IsTruthyOrNonEmpty call to pass the new includeZero argument and fixed the lookup of HandlebarsDotNet.UndefinedBindingResult (moved out of Compiler).

C# language template (Languages/csharp/ServiceClient.hb)

  • Annotated the generated RestApiException / RestApiException<T> serialization ctor and GetObjectData overrides with [Obsolete("Formatter-based serialization is obsolete and should not be used.")] to satisfy SYSLIB0051 / CS0672 on modern TFMs.
  • Removed a trailing-whitespace line that was flowing through into the generated output.

Helix client (src/Microsoft.DotNet.Helix/Client/CSharp)

  • Regenerated all files under generated-code/ against the current https://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).
  • Deleted the handwritten partial shims that were only there to bridge the old client to newer server responses, now that they're covered by the regenerated code:
    • JobCreationResult.cs (partial that added QueueStats)
    • QueueStats.cs (replaced by generated QueueStatsSummary)
    • JobStatus.cs (IsCompleted extension on a type that no longer exists in the OpenAPI doc)

Validation

  • dotnet build /t:GenerateSwaggerCode in src/Microsoft.DotNet.Helix/Client/CSharp — succeeds (10 pre-existing collectionFormat schema warnings from the OpenAPI doc, 0 errors).
  • dotnet build Microsoft.DotNet.Helix.Client.csproj — succeeds, 0 warnings, 0 errors.
  • git diff --check — clean.

Copilot AI lite review requested due to automatic review settings August 20, 2026 12:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 properties query support, introduce QueueStatsSummary, 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.

Comment on lines +275 to 280
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
Comment on lines +196 to +199
if (properties != default(IImmutableDictionary<string, string>))
{
_url.AppendQuery("Properties", Client.Serialize(properties));
}
akoeplinger
akoeplinger previously approved these changes Aug 20, 2026
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI review requested due to automatic review settings August 20, 2026 13:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@premun

premun commented Aug 20, 2026

Copy link
Copy Markdown
Member Author

@chcosta this PR changes a bit the QueueStats API that you have manually added into the auto-generated code some time ago. However, I think it's better to generate the client based on the OpenAPI spec of the real API than to manually edit it. Regardless, I think these might be just class renames.

Not sure who depends on this API where though.

@premun
premun enabled auto-merge (squash) August 20, 2026 13:49
@premun
premun merged commit a18c4ec into dotnet:main Aug 20, 2026
10 of 12 checks passed
@premun
premun deleted the prvysoky/property-filtering branch August 20, 2026 14:45
@akoeplinger

Copy link
Copy Markdown
Member

I think the two Copilot findings are worth addressing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants