Skip to content

Commit afe0675

Browse files
authored
Merge pull request #588 from /issues/407
Removed DataTypeMismatch as default rule
2 parents d4a0b8e + 429c6e4 commit afe0675

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,16 @@ namespace Microsoft.OpenApi.Validations.Rules
88
/// <summary>
99
/// The validation rules for <see cref="OpenApiMediaType"/>.
1010
/// </summary>
11-
[OpenApiRule]
11+
/// <remarks>
12+
/// Removed this in v1.3 as a default rule as the OpenAPI specification does not require that example
13+
/// values validate against the schema. Validating examples against the schema is particularly difficult
14+
/// as it requires parsing of the example using the schema as a guide. This is not possible when the schema
15+
/// is ref'd. Even if we fix this issue, this rule should be treated as a warning, not an error
16+
/// Future versions of the validator should make that distinction.
17+
/// Future versions of the example parsers should not try an infer types.
18+
/// Example validation should be done as a separate post reading step so all schemas can be fully available.
19+
/// </remarks>
20+
//[OpenApiRule]
1221
public static class OpenApiMediaTypeRules
1322
{
1423
/// <summary>

test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,6 @@ namespace Microsoft.OpenApi.Validations.Rules
11541154
{
11551155
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiLicense> LicenseRequiredFields { get; }
11561156
}
1157-
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
11581157
public static class OpenApiMediaTypeRules
11591158
{
11601159
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiMediaType> MediaTypeMismatchedDataType { get; }

test/Microsoft.OpenApi.Tests/Validations/OpenApiMediaTypeValidationTests.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
3232
};
3333

3434
// Act
35-
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
35+
var ruleset = ValidationRuleSet.GetDefaultRuleSet();
36+
ruleset.Add(OpenApiMediaTypeRules.MediaTypeMismatchedDataType);
37+
var validator = new OpenApiValidator(ruleset);
3638
var walker = new OpenApiWalker(validator);
3739
walker.Walk(mediaType);
3840

@@ -102,7 +104,9 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
102104
};
103105

104106
// Act
105-
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
107+
var ruleset = ValidationRuleSet.GetDefaultRuleSet();
108+
ruleset.Add(OpenApiMediaTypeRules.MediaTypeMismatchedDataType);
109+
var validator = new OpenApiValidator(ruleset);
106110
var walker = new OpenApiWalker(validator);
107111
walker.Walk(mediaType);
108112

test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void DefaultRuleSetPropertyReturnsTheCorrectRules()
4343
Assert.NotEmpty(rules);
4444

4545
// Update the number if you add new default rule(s).
46-
Assert.Equal(21, rules.Count);
46+
Assert.Equal(20, rules.Count);
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)