Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 10 additions & 1 deletion src/Microsoft.OpenApi/Validations/Rules/OpenApiMediaTypeRules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@ namespace Microsoft.OpenApi.Validations.Rules
/// <summary>
/// The validation rules for <see cref="OpenApiMediaType"/>.
/// </summary>
[OpenApiRule]
/// <remarks>
/// Removed this in v1.3 as a default rule as the OpenAPI specification does not require that example
/// values validate against the schema. Validating examples against the schema is particularly difficult
/// as it requires parsing of the example using the schema as a guide. This is not possible when the schema
/// is ref'd. Even if we fix this issue, this rule should be treated as a warning, not an error
/// Future versions of the validator should make that distinction.
/// Future versions of the example parsers should not try an infer types.
/// Example validation should be done as a separate post reading step so all schemas can be fully available.
/// </remarks>
//[OpenApiRule]
public static class OpenApiMediaTypeRules
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1154,7 +1154,6 @@ namespace Microsoft.OpenApi.Validations.Rules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiLicense> LicenseRequiredFields { get; }
}
[Microsoft.OpenApi.Validations.Rules.OpenApiRule]
public static class OpenApiMediaTypeRules
{
public static Microsoft.OpenApi.Validations.ValidationRule<Microsoft.OpenApi.Models.OpenApiMediaType> MediaTypeMismatchedDataType { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public void ValidateExampleShouldNotHaveDataTypeMismatchForSimpleSchema()
};

// Act
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
var ruleset = ValidationRuleSet.GetDefaultRuleSet();
ruleset.Add(OpenApiMediaTypeRules.MediaTypeMismatchedDataType);
var validator = new OpenApiValidator(ruleset);
var walker = new OpenApiWalker(validator);
walker.Walk(mediaType);

Expand Down Expand Up @@ -102,7 +104,9 @@ public void ValidateExamplesShouldNotHaveDataTypeMismatchForSimpleSchema()
};

// Act
var validator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet());
var ruleset = ValidationRuleSet.GetDefaultRuleSet();
ruleset.Add(OpenApiMediaTypeRules.MediaTypeMismatchedDataType);
var validator = new OpenApiValidator(ruleset);
var walker = new OpenApiWalker(validator);
walker.Walk(mediaType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void DefaultRuleSetPropertyReturnsTheCorrectRules()
Assert.NotEmpty(rules);

// Update the number if you add new default rule(s).
Assert.Equal(21, rules.Count);
Assert.Equal(20, rules.Count);
}
}
}