Visitar URL original
Add Validation Rule for path operations to not have a request body by martincostello · Pull Request #2472 · microsoft/OpenAPI.NET · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address feedback
Address Copilot feedback.
  • Loading branch information
martincostello committed Aug 22, 2025
commit bbdaa02308f946dbfa6f0b257a55adc825bb6718
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static partial class OpenApiResponsesRules
new(nameof(ResponsesMustContainAtLeastOneResponse),
(context, responses) =>
{
if (responses.Keys.Count == 0)
if (responses.Count == 0)
{
context.CreateError(nameof(ResponsesMustContainAtLeastOneResponse),
"Responses must contain at least one response");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ public static void GetOperationWithoutRequestBodyIsValid()
ruleSet.Add(typeof(OpenApiPaths), OpenApiRecommendedRules.GetOperationShouldNotHaveRequestBody);

// Act

var errors = document.Validate(ruleSet);
var result = !errors.Any();

Expand Down Expand Up @@ -193,15 +192,14 @@ public static void GetOperationWithRequestBodyIsInvalid()
ruleSet.Add(typeof(OpenApiPaths), OpenApiRecommendedRules.GetOperationShouldNotHaveRequestBody);

// Act

var errors = document.Validate(ruleSet);
var result = !errors.Any();
var warnings = document.Validate(ruleSet);
var result = !warnings.Any();

// Assert
Assert.False(result);
Assert.NotNull(errors);
var error = Assert.Single(errors);
Assert.Equal("GET operations should not have a request body.", error.Message);
Assert.Equal("#/paths/people/get/requestbody", error.Pointer);
Assert.NotNull(warnings);
var warning = Assert.Single(warnings);
Assert.Equal("GET operations should not have a request body.", warning.Message);
Assert.Equal("#/paths/people/get/requestbody", warning.Pointer);
}
}