Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7316184
Init implementation for the Open API validation
xuzhg Dec 12, 2017
0988b1b
add the whole visitor classes for validation
xuzhg Dec 15, 2017
620b0f2
add the rules and modify the header copyright
xuzhg Dec 15, 2017
31a3cd9
Add test cases for external docs and response
xuzhg Dec 15, 2017
401072c
add a validation rule for the OAuthFlow object
xuzhg Dec 15, 2017
bd39460
modify to give more meaningful comments
xuzhg Dec 16, 2017
da5f90a
add the OpenApiRuleAttribute for each rule classes
xuzhg Dec 18, 2017
4a6ca43
change to lazy loading for the validation visitors
xuzhg Dec 18, 2017
2e7e2dd
Change the namespace for the Validation test files
xuzhg Dec 18, 2017
aebee6f
Add the test cases for ValidationRuleSet
xuzhg Dec 18, 2017
df86936
resolve the comments, typos and some test codes
xuzhg Dec 19, 2017
bc530c3
Validation using walker and single visitor class
darrelmiller Dec 20, 2017
b29d532
Change debug.assert to throw arugment null and use the resource from …
xuzhg Dec 20, 2017
5eccf02
Merge branch 'sam/validation3' into dm/validation
darrelmiller Dec 20, 2017
0188565
Remove visitor classes
darrelmiller Dec 20, 2017
43ae516
Enhancements to walker
darrelmiller Dec 20, 2017
fc4c334
Removed unused test
darrelmiller Dec 20, 2017
26561e3
Merge remote-tracking branch 'origin/master' into dm/validation
darrelmiller Dec 23, 2017
2fd11fa
Updated Walker to use separate methods for each element
darrelmiller Jan 2, 2018
d6dba10
Updated walkers and added validate method
darrelmiller Jan 3, 2018
9f7c7f6
Merge branch 'master' into dm/validation
darrelmiller Jan 3, 2018
6c47d49
Merge branch 'master' into dm/validation
darrelmiller Jan 11, 2018
0a4c3ee
Merge branch 'master' into dm/validation
darrelmiller Jan 11, 2018
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, for the customer/developer, he will check:

  1. The return is not null
  2. The return has elements.
OpenApiDocument doc = new OpenApiDocument();
var errors = doc.Validate();

if (errors == null || !errors.Any())
{
    // validation passed.
}
else
{
   // validation failed.
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking errors.Any() should be sufficient because returning IEnumerable as null is just evil. I will add documentation to convey the fact that the function will never return null.

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