Skip to content

Conversation

@martincostello
Copy link
Collaborator

@martincostello martincostello commented Nov 28, 2025

To try and avoid issues such as #3683 in the future, these changes extend the integration tests to validate that the OpenAPI documents produced by the test assets generate valid clients using Kiota and NSwag.

Note that this validation is restricted to compile-time validation only - runtime errors from any generated client code are not detected by these changes.

TODO

  • Iterate over the snapshot files and generate OpenAPI documents that are found
  • Where relevant, generate OpenAPI documents dynamically for different OpenAPI versions and then use relevant tool(s) to generate clients from them
  • Remove validation of petstore3.swagger.io OpenAPI documents
  • Detect the breakage from [Bug]: Broken allOf/nullable handling #3683

Initial infrastructure for integration tests that validate OpenAPI documents can generate valid C# clients using Kiota and NSwag.
Move to its own class to slim down the test.
@martincostello martincostello added dependencies Pull requests that update a dependency file .NET Pull requests that update .NET code labels Nov 28, 2025
@codecov
Copy link

codecov bot commented Nov 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.64%. Comparing base (0e042af) to head (457b5e2).
⚠️ Report is 1 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3686   +/-   ##
=======================================
  Coverage   94.64%   94.64%           
=======================================
  Files         111      111           
  Lines        3865     3865           
  Branches      780      780           
=======================================
  Hits         3658     3658           
  Misses        207      207           
Flag Coverage Δ
Linux 94.64% <ø> (ø)
Windows 94.64% <ø> (ø)
macOS 94.64% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Add test cases for Swagger 2.0 and YAML, where relevant.
Generate client code from snapshot files and running applications instead of Pet Store.
Enable nullable annotations in the generated client code.
Just validate the snapshots, not the applications as well (which are used to generate the snapshots).
Refactor to make the lines less long.
@martincostello martincostello marked this pull request as ready for review November 29, 2025 08:04
Copilot AI review requested due to automatic review settings November 29, 2025 08:04
@martincostello
Copy link
Collaborator Author

Going to merge this now without the validation for the instigating issue present, and tackle that with a separate PR once there's a concrete repro for the specific compilation breakage.

@martincostello martincostello merged commit ed88a1b into master Nov 29, 2025
18 checks passed
@martincostello martincostello deleted the openapi-code-generation-validation branch November 29, 2025 08:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends integration tests to validate that OpenAPI documents generated by test assets can be successfully used to create compilable C# clients using Kiota and NSwag code generation tools. The validation focuses on compile-time errors only, helping prevent issues like #3683.

Key changes:

  • Added code generation validation tests using Kiota and NSwag
  • Configured CI to install required .NET tools (Kiota)
  • Added necessary NuGet package dependencies for code generation

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/Swashbuckle.AspNetCore.IntegrationTests/CodeGenerationTests.cs New test class that validates OpenAPI snapshots generate valid C# client code
test/Swashbuckle.AspNetCore.IntegrationTests/ClientGenerator.cs Helper class that orchestrates client code generation and compilation using Kiota and NSwag
test/Swashbuckle.AspNetCore.IntegrationTests/ClientGeneratorTool.cs Enum defining supported code generation tools
test/Swashbuckle.AspNetCore.IntegrationTests/Swashbuckle.AspNetCore.IntegrationTests.csproj Added conditional package references for .NET 10.0 including code generation dependencies
Directory.Packages.props Added package version entries for Microsoft.Build, Microsoft.Kiota.Bundle, MSBuild.ProjectCreation, and NSwag.CodeGeneration.CSharp
.github/workflows/build.yml Added step to restore .NET tools before build
.config/dotnet-tools.json Added Kiota tool configuration for code generation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

This was referenced Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file .NET Pull requests that update .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants