Skip to content

Commit

Permalink
Merge pull request #163 from Microsoft/dm/validation
Browse files Browse the repository at this point in the history
Alternative Validation implementation
  • Loading branch information
darrelmiller authored Jan 11, 2018
2 parents db4c009 + 0a4c3ee commit ba575c4
Show file tree
Hide file tree
Showing 36 changed files with 2,219 additions and 119 deletions.
31 changes: 31 additions & 0 deletions src/Microsoft.OpenApi/Extensions/OpenApiElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Validations;

namespace Microsoft.OpenApi.Extensions
{
/// <summary>
/// Extension methods that apply across all OpenAPIElements
/// </summary>
public static class OpenApiElementExtensions
{
/// <summary>
/// Validate element and all child elements
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="element"></param>
/// <returns></returns>
public static IEnumerable<ValidationError> Validate(this IOpenApiElement element) {
var validator = new OpenApiValidator();
var walker = new OpenApiWalker(validator);
walker.Walk(element);
return validator.Errors;
}
}
}
72 changes: 72 additions & 0 deletions src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/Microsoft.OpenApi/Properties/SRResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
<data name="IndentationLevelInvalid" xml:space="preserve">
<value>Indentation level cannot be lower than 0.</value>
</data>
<data name="InputItemShouldBeType" xml:space="preserve">
<value>The input item should be in type of '{0}'.</value>
</data>
<data name="ObjectScopeNeededForPropertyNameWriting" xml:space="preserve">
<value>The active scope must be an object scope for property name '{0}' to be written.</value>
</data>
Expand Down Expand Up @@ -177,4 +180,25 @@
<data name="SourceExpressionHasInvalidFormat" xml:space="preserve">
<value>The source expression '{0}' has invalid format.</value>
</data>
<data name="UnknownVisitorType" xml:space="preserve">
<value>Can not find visitor type registered for type '{0}'.</value>
</data>
<data name="Validation_ComponentsKeyMustMatchRegularExpr" xml:space="preserve">
<value>The key '{0}' in '{1}' of components MUST match the regular expression '{2}'.</value>
</data>
<data name="Validation_ExtensionNameMustBeginWithXDash" xml:space="preserve">
<value>The extension name '{0}' in '{1}' object MUST begin with 'x-'.</value>
</data>
<data name="Validation_FieldIsRequired" xml:space="preserve">
<value>The field '{0}' in '{1}' object is REQUIRED.</value>
</data>
<data name="Validation_PathItemMustBeginWithSlash" xml:space="preserve">
<value>The path item name '{0}' MUST begin with a slash.</value>
</data>
<data name="Validation_RuleAddTwice" xml:space="preserve">
<value>The same rule cannot be in the same rule set twice.</value>
</data>
<data name="Validation_StringMustBeEmailAddress" xml:space="preserve">
<value>The string '{0}' MUST be in the format of an email address.</value>
</data>
</root>
32 changes: 0 additions & 32 deletions src/Microsoft.OpenApi/Services/OpenApiValidator.cs

This file was deleted.

Loading

0 comments on commit ba575c4

Please sign in to comment.