public void ValidateExtensionNameStartsWithXDashInTag() { // Arrange IEnumerable <ValidationError> errors; OpenApiTag tag = new OpenApiTag { Name = "tag" }; tag.Extensions.Add("tagExt", new OpenApiString("value")); // Act var validator = new OpenApiValidator(); validator.Visit(tag as IOpenApiExtensible); errors = validator.Errors; bool result = !errors.Any(); // Assert Assert.False(result); Assert.NotNull(errors); ValidationError error = Assert.Single(errors); Assert.Equal(String.Format(SRResource.Validation_ExtensionNameMustBeginWithXDash, "tagExt", "#/extensions"), error.ErrorMessage); }
/// <summary> /// Runs the OpenApiValidator against the OpenApiDocument object. Returns true if the document is valid, false otherwise /// </summary> /// <param name="doc">The OpenApiDocument to test against</param> /// <param name="context"></param> /// <returns></returns> private void IsValidOpenAPIDocument(OpenApiDocument doc, CustomContext context) { var openApiValidator = new OpenApiValidator(ValidationRuleSet.GetDefaultRuleSet()); openApiValidator.Visit(doc); foreach (var error in openApiValidator.Errors) { context.AddFailure(error.Message); } }
public void ValidateFieldIsRequiredInServer() { // Arrange IEnumerable <ValidationError> errors; OpenApiServer server = new OpenApiServer(); // Act var validator = new OpenApiValidator(); validator.Visit(server); errors = validator.Errors; bool result = !errors.Any(); // Assert Assert.False(result); Assert.NotNull(errors); ValidationError error = Assert.Single(errors); Assert.Equal(String.Format(SRResource.Validation_FieldIsRequired, "url", "server"), error.ErrorMessage); }
public void ValidateNameIsRequiredInTag() { // Arrange IEnumerable <OpenApiError> errors; OpenApiTag tag = new OpenApiTag(); // Act var validator = new OpenApiValidator(); validator.Visit(tag); errors = validator.Errors; bool result = !errors.Any(); // Assert Assert.False(result); Assert.NotNull(errors); OpenApiError error = Assert.Single(errors); Assert.Equal(String.Format(SRResource.Validation_FieldIsRequired, "name", "tag"), error.Message); }