-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Validate OpenAPI documents create valid C# clients #3686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
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.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
|
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. |
There was a problem hiding this 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.
Apply code review suggestions from #3686.
Apply code review suggestions from #3686.
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 foundWhere relevant, generate OpenAPI documents dynamically for different OpenAPI versions and then use relevant tool(s) to generate clients from themRemove validation ofpetstore3.swagger.ioOpenAPI documents