Skip to content

Commit

Permalink
Merge pull request #1097 from microsoft/bugfix/validate-open-api-path…
Browse files Browse the repository at this point in the history
…-item

- adds missing validation methods
  • Loading branch information
baywet authored Dec 6, 2022
2 parents 460d267 + 2d9a007 commit b530580
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.4.4</Version>
<Version>1.4.5</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.4.4</Version>
<Version>1.4.5</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
96 changes: 95 additions & 1 deletion src/Microsoft.OpenApi/Validations/OpenApiValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class OpenApiValidator : OpenApiVisitorBase, IValidationContext
private readonly IList<OpenApiValidatorWarning> _warnings = new List<OpenApiValidatorWarning>();

/// <summary>
/// Create a vistor that will validate an OpenAPIDocument
/// Create a visitor that will validate an OpenAPIDocument
/// </summary>
/// <param name="ruleSet"></param>
public OpenApiValidator(ValidationRuleSet ruleSet)
Expand Down Expand Up @@ -198,6 +198,100 @@ public void AddWarning(OpenApiValidatorWarning warning)
/// <param name="items">The object to be validated</param>
public override void Visit(IList<OpenApiExample> items) => Validate(items, items.GetType());

/// <summary>
/// Execute validation rules against a <see cref="OpenApiPathItem"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiPathItem item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiServerVariable"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiServerVariable item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiSecurityScheme"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiSecurityScheme item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiSecurityRequirement"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiSecurityRequirement item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiRequestBody"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiRequestBody item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiPaths"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiPaths item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiLink"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiLink item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiExample"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiExample item) => Validate(item);

/// <summary>
/// Execute validation rules against a <see cref="OpenApiOperation"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(OpenApiOperation item) => Validate(item);
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{OperationType, OpenApiOperation}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<OperationType, OpenApiOperation> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiHeader}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiHeader> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiCallback}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiCallback> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiMediaType}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiMediaType> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiExample}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiExample> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiLink}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiLink> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiServerVariable}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiServerVariable> item) => Validate(item, item.GetType());
/// <summary>
/// Execute validation rules against a <see cref="IDictionary{String, OpenApiEncoding}"/>
/// </summary>
/// <param name="item">The object to be validated</param>
public override void Visit(IDictionary<string, OpenApiEncoding> item) => Validate(item, item.GetType());

private void Validate<T>(T item)
{
var type = typeof(T);
Expand Down
17 changes: 17 additions & 0 deletions test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1212,18 +1212,35 @@ namespace Microsoft.OpenApi.Validations
public override void Visit(Microsoft.OpenApi.Models.OpenApiContact item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiDocument item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiEncoding item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiExample item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiExternalDocs item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiHeader item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiInfo item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiLicense item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiLink item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiMediaType item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiOAuthFlow item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiOperation item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiParameter item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiPathItem item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiPaths item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiRequestBody item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiResponse item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiResponses item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiSchema item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiSecurityRequirement item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiSecurityScheme item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiServer item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiServerVariable item) { }
public override void Visit(Microsoft.OpenApi.Models.OpenApiTag item) { }
public override void Visit(System.Collections.Generic.IDictionary<Microsoft.OpenApi.Models.OperationType, Microsoft.OpenApi.Models.OpenApiOperation> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiCallback> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiEncoding> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiExample> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiHeader> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiLink> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiMediaType> item) { }
public override void Visit(System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Models.OpenApiServerVariable> item) { }
public override void Visit(System.Collections.Generic.IList<Microsoft.OpenApi.Models.OpenApiExample> items) { }
}
public class OpenApiValidatorError : Microsoft.OpenApi.Models.OpenApiError
Expand Down

0 comments on commit b530580

Please sign in to comment.