Add Validation Rule for path operations to not have a request body#2472
Add Validation Rule for path operations to not have a request body#2472baywet merged 4 commits intomicrosoft:mainfrom
Conversation
- Avoid using `Enter()` and `Exit()` operations in validation rules where possible. - Use `string` not `String`. - Remove redundant comments. - Fix typo in comment.
Add new `OpenApiRecommendedRules` class and adds a new `GetOperationShouldNotHaveRequestBody` rule. Resolves microsoft#2454.
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new validation rule to check that GET operations should not have request bodies, along with several code quality improvements. The changes introduce the OpenApiRecommendedRules class with a specific validation rule for GET operations and refactor existing validation rules to optimize performance.
- Adds
GetOperationShouldNotHaveRequestBodyvalidation rule in newOpenApiRecommendedRulesclass - Optimizes validation rules by avoiding unnecessary
Enter()/Exit()calls when validation conditions aren't met - Standardizes string usage and fixes typos across validation rule files
Reviewed Changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.OpenApi/Validations/Rules/OpenApiRecommendedRules.cs |
New class containing the GET operation request body validation rule |
test/Microsoft.OpenApi.Tests/Validations/OpenApiRecommendedRulesTests.cs |
Comprehensive tests for the new validation rule |
test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt |
Updates public API surface to include new class |
| Multiple validation rule files | Performance optimizations and code quality improvements |
src/Microsoft.OpenApi/Services/OpenApiVisitorBase.cs |
Typo fix in comment |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/Microsoft.OpenApi/Validations/Rules/OpenApiResponsesRules.cs
Outdated
Show resolved
Hide resolved
Address Copilot feedback.
baywet
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
Can you please add a unit test to validate this rule IS NOT present in the default rules (prevent regressions)
Address feedback.
baywet
left a comment
There was a problem hiding this comment.
Thank you for making the changes!
OpenApiRecommendedRulesclass that adds a newGetOperationShouldNotHaveRequestBodyrule.Enter()andExit()operations in validation rules where possible to avoid stack push/pop calls these perform.stringnotString.Resolves #2454.