-
Notifications
You must be signed in to change notification settings - Fork 262
Fix validation to accept lowercase status code ranges (4xx, 5xx) in OpenAPI responses #2415
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
06dc719
Initial plan
Copilot bd225c1
Initialize plan to fix lowercase status code validation issue
Copilot 0525372
Fix regex to accept lowercase status code ranges (4xx, 5xx) and add G…
Copilot e1a7bc7
Complete the fix: update tests, fix compilation issues, and verify so…
Copilot 3a9779d
chore: reverts unrelated changes
baywet 5363e35
fix: makes default comparison case insensitive
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
test/Microsoft.OpenApi.Tests/Validations/OpenApiResponsesValidationTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Xunit; | ||
|
||
namespace Microsoft.OpenApi.Validations.Tests | ||
{ | ||
public class OpenApiResponsesValidationTests | ||
{ | ||
[Theory] | ||
[InlineData("200")] | ||
[InlineData("404")] | ||
[InlineData("500")] | ||
[InlineData("1XX")] | ||
[InlineData("2XX")] | ||
[InlineData("3XX")] | ||
[InlineData("4XX")] | ||
[InlineData("5XX")] | ||
[InlineData("1xx")] | ||
[InlineData("2xx")] | ||
[InlineData("3xx")] | ||
[InlineData("4xx")] | ||
[InlineData("5xx")] | ||
[InlineData("default")] | ||
public void ValidateResponseKeyIsValid(string responseKey) | ||
{ | ||
// Arrange | ||
var responses = new OpenApiResponses | ||
{ | ||
[responseKey] = new OpenApiResponse { Description = "Test response" } | ||
}; | ||
|
||
// Act | ||
var errors = responses.Validate(ValidationRuleSet.GetDefaultRuleSet()); | ||
|
||
// Assert | ||
Assert.Empty(errors); | ||
} | ||
|
||
[Fact] | ||
public void ValidateMixedCaseResponseKeysAreAllowed() | ||
{ | ||
// Arrange - Test the specific issue case mentioned in the bug report | ||
var responses = new OpenApiResponses | ||
{ | ||
["4xx"] = new OpenApiResponse { Description = "Client error" }, | ||
["5XX"] = new OpenApiResponse { Description = "Server error" }, | ||
["200"] = new OpenApiResponse { Description = "Success" }, | ||
["default"] = new OpenApiResponse { Description = "Default response" } | ||
}; | ||
|
||
// Act | ||
var errors = responses.Validate(ValidationRuleSet.GetDefaultRuleSet()); | ||
|
||
// Assert | ||
Assert.Empty(errors); | ||
} | ||
|
||
[Fact] | ||
public void ValidateLowercase4xxIsAccepted() | ||
{ | ||
// Arrange - Test the specific reported issue | ||
var responses = new OpenApiResponses | ||
{ | ||
["4xx"] = new OpenApiResponse { Description = "Client error" } | ||
}; | ||
|
||
// Act | ||
var errors = responses.Validate(ValidationRuleSet.GetDefaultRuleSet()); | ||
|
||
// Assert | ||
Assert.Empty(errors); | ||
} | ||
|
||
[Fact] | ||
public void ValidateLowercase5xxIsAccepted() | ||
{ | ||
// Arrange - Test the specific reported issue | ||
var responses = new OpenApiResponses | ||
{ | ||
["5xx"] = new OpenApiResponse { Description = "Server error" } | ||
}; | ||
|
||
// Act | ||
var errors = responses.Validate(ValidationRuleSet.GetDefaultRuleSet()); | ||
|
||
// Assert | ||
Assert.Empty(errors); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.