Skip to content

Commit ba575c4

Browse files
authored
Merge pull request #163 from Microsoft/dm/validation
Alternative Validation implementation
2 parents db4c009 + 0a4c3ee commit ba575c4

36 files changed

+2219
-119
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using Microsoft.OpenApi.Interfaces;
7+
using Microsoft.OpenApi.Models;
8+
using Microsoft.OpenApi.Services;
9+
using Microsoft.OpenApi.Validations;
10+
11+
namespace Microsoft.OpenApi.Extensions
12+
{
13+
/// <summary>
14+
/// Extension methods that apply across all OpenAPIElements
15+
/// </summary>
16+
public static class OpenApiElementExtensions
17+
{
18+
/// <summary>
19+
/// Validate element and all child elements
20+
/// </summary>
21+
/// <typeparam name="T"></typeparam>
22+
/// <param name="element"></param>
23+
/// <returns></returns>
24+
public static IEnumerable<ValidationError> Validate(this IOpenApiElement element) {
25+
var validator = new OpenApiValidator();
26+
var walker = new OpenApiWalker(validator);
27+
walker.Walk(element);
28+
return validator.Errors;
29+
}
30+
}
31+
}

Diff for: src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

+72
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/Microsoft.OpenApi/Properties/SRResource.resx

+24
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@
129129
<data name="IndentationLevelInvalid" xml:space="preserve">
130130
<value>Indentation level cannot be lower than 0.</value>
131131
</data>
132+
<data name="InputItemShouldBeType" xml:space="preserve">
133+
<value>The input item should be in type of '{0}'.</value>
134+
</data>
132135
<data name="ObjectScopeNeededForPropertyNameWriting" xml:space="preserve">
133136
<value>The active scope must be an object scope for property name '{0}' to be written.</value>
134137
</data>
@@ -177,4 +180,25 @@
177180
<data name="SourceExpressionHasInvalidFormat" xml:space="preserve">
178181
<value>The source expression '{0}' has invalid format.</value>
179182
</data>
183+
<data name="UnknownVisitorType" xml:space="preserve">
184+
<value>Can not find visitor type registered for type '{0}'.</value>
185+
</data>
186+
<data name="Validation_ComponentsKeyMustMatchRegularExpr" xml:space="preserve">
187+
<value>The key '{0}' in '{1}' of components MUST match the regular expression '{2}'.</value>
188+
</data>
189+
<data name="Validation_ExtensionNameMustBeginWithXDash" xml:space="preserve">
190+
<value>The extension name '{0}' in '{1}' object MUST begin with 'x-'.</value>
191+
</data>
192+
<data name="Validation_FieldIsRequired" xml:space="preserve">
193+
<value>The field '{0}' in '{1}' object is REQUIRED.</value>
194+
</data>
195+
<data name="Validation_PathItemMustBeginWithSlash" xml:space="preserve">
196+
<value>The path item name '{0}' MUST begin with a slash.</value>
197+
</data>
198+
<data name="Validation_RuleAddTwice" xml:space="preserve">
199+
<value>The same rule cannot be in the same rule set twice.</value>
200+
</data>
201+
<data name="Validation_StringMustBeEmailAddress" xml:space="preserve">
202+
<value>The string '{0}' MUST be in the format of an email address.</value>
203+
</data>
180204
</root>

Diff for: src/Microsoft.OpenApi/Services/OpenApiValidator.cs

-32
This file was deleted.

0 commit comments

Comments
 (0)