Skip to content

Commit

Permalink
Merge pull request #828 from microsoft/release/1.3.0
Browse files Browse the repository at this point in the history
Release/1.3.0
  • Loading branch information
darrelmiller authored Apr 12, 2022
2 parents 13e2d06 + 274acb5 commit 5eb1481
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 76 deletions.
8 changes: 5 additions & 3 deletions .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,13 @@ stages:
inputs:
source: current
- pwsh: |
$artifactName = Get-ChildItem -Path $(Pipeline.Workspace) -Filter Microsoft.OpenApi.Hidi-* -recurse | select -First 1
$artifactVersion= $artifactName -replace "Microsoft.OpenApi.Hidi-", ""
$artifactName = Get-ChildItem -Path $(Pipeline.Workspace)\Nugets -Filter Microsoft.OpenApi.*.nupkg -recurse | select -First 1
$artifactVersion= $artifactName.Name -replace "Microsoft.OpenApi.", "" -replace ".nupkg", ""
#Set Variable $artifactName and $artifactVersion
Write-Host "##vso[task.setvariable variable=artifactVersion; isSecret=false; isOutput=true]$artifactVersion"
Write-Host "##vso[task.setvariable variable=artifactName; isSecret=false; isOutput=true]$artifactName.FullName"
echo "$artifactName"
echo "$artifactVersion"
displayName: 'Fetch Artifact Name'
- task: NuGetCommand@2
Expand All @@ -290,7 +292,7 @@ stages:
gitHubConnection: 'Github-MaggieKimani1'
tagSource: userSpecifiedTag
tag: '$(artifactVersion)'
title: '$(artifactName)'
title: '$(artifactVersion)'
releaseNotesSource: inline
assets: '$(Pipeline.Workspace)\**\*.exe'
changeLogType: issueBased
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>0.5.0-preview6</Version>
<Version>1.0.0-preview1</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
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.3.1-preview6</Version>
<Version>1.3.1</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ public class OpenApiDiagnostic : IDiagnostic
/// </summary>
public IList<OpenApiError> Errors { get; set; } = new List<OpenApiError>();

/// <summary>
/// List of all warnings
/// </summary>
public IList<OpenApiError> Warnings { get; set; } = new List<OpenApiError>();

/// <summary>
/// Open API specification version of the document parsed.
/// </summary>
Expand Down
11 changes: 9 additions & 2 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Extensions;
Expand All @@ -12,6 +13,7 @@
using Microsoft.OpenApi.Readers.Interface;
using Microsoft.OpenApi.Readers.Services;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Validations;
using SharpYaml.Serialization;

namespace Microsoft.OpenApi.Readers
Expand Down Expand Up @@ -68,11 +70,16 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic
// Validate the document
if (_settings.RuleSet != null && _settings.RuleSet.Rules.Count > 0)
{
var errors = document.Validate(_settings.RuleSet);
foreach (var item in errors)
var openApiErrors = document.Validate(_settings.RuleSet);
foreach (var item in openApiErrors.Where(e => e is OpenApiValidatorError))
{
diagnostic.Errors.Add(item);
}
foreach (var item in openApiErrors.Where(e => e is OpenApiValidatorWarning))
{
diagnostic.Warnings.Add(item);
}

}

return document;
Expand Down
3 changes: 2 additions & 1 deletion src/Microsoft.OpenApi/Extensions/OpenApiElementExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

using System.Collections.Generic;
using System.Linq;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Services;
Expand All @@ -25,7 +26,7 @@ public static IEnumerable<OpenApiError> Validate(this IOpenApiElement element, V
var validator = new OpenApiValidator(ruleSet);
var walker = new OpenApiWalker(validator);
walker.Walk(element);
return validator.Errors;
return validator.Errors.Cast<OpenApiError>().Union(validator.Warnings);
}
}
}
3 changes: 1 addition & 2 deletions 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.3.1-preview6</Version>
<Version>1.3.1</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 All @@ -38,7 +38,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="System.Text.Json" Version="6.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 8 additions & 0 deletions src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ internal T ResolveReferenceTo<T>(OpenApiReference reference) where T : class, IO
}
}

/// <summary>
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
/// </summary>
public IOpenApiReferenceable ResolveReference(OpenApiReference reference)
{
return ResolveReference(reference, false);
}

/// <summary>
/// Load the referenced <see cref="IOpenApiReferenceable"/> object from a <see cref="OpenApiReference"/> object
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions src/Microsoft.OpenApi/Validations/IValidationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public interface IValidationContext
/// <param name="error">Error to register.</param>
void AddError(OpenApiValidatorError error);

/// <summary>
/// Register a warning with the validation context.
/// </summary>
/// <param name="warning">Warning to register.</param>
void AddWarning(OpenApiValidatorWarning warning);

/// <summary>
/// Allow Rule to indicate validation error occured at a deeper context level.
/// </summary>
Expand Down
28 changes: 28 additions & 0 deletions src/Microsoft.OpenApi/Validations/OpenApiValidatiorWarning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Models;

namespace Microsoft.OpenApi.Validations
{
/// <summary>
/// Warnings detected when validating an OpenAPI Element
/// </summary>
public class OpenApiValidatorWarning : OpenApiError
{
/// <summary>
/// Initializes the <see cref="OpenApiError"/> class.
/// </summary>
public OpenApiValidatorWarning(string ruleName, string pointer, string message) : base(pointer, message)
{
RuleName = ruleName;
}

/// <summary>
/// Name of rule that detected the error.
/// </summary>
public string RuleName { get; set; }
}

}
25 changes: 25 additions & 0 deletions src/Microsoft.OpenApi/Validations/OpenApiValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class OpenApiValidator : OpenApiVisitorBase, IValidationContext
{
private readonly ValidationRuleSet _ruleSet;
private readonly IList<OpenApiValidatorError> _errors = new List<OpenApiValidatorError>();
private readonly IList<OpenApiValidatorWarning> _warnings = new List<OpenApiValidatorWarning>();

/// <summary>
/// Create a vistor that will validate an OpenAPIDocument
Expand All @@ -38,6 +39,17 @@ public IEnumerable<OpenApiValidatorError> Errors
}
}

/// <summary>
/// Gets the validation warnings.
/// </summary>
public IEnumerable<OpenApiValidatorWarning> Warnings
{
get
{
return _warnings;
}
}

/// <summary>
/// Register an error with the validation context.
/// </summary>
Expand All @@ -52,6 +64,19 @@ public void AddError(OpenApiValidatorError error)
_errors.Add(error);
}

/// <summary>
/// Register an error with the validation context.
/// </summary>
/// <param name="warning">Error to register.</param>
public void AddWarning(OpenApiValidatorWarning warning)
{
if (warning == null)
{
throw Error.ArgumentNull(nameof(warning));
}

_warnings.Add(warning);
}

/// <summary>
/// Execute validation rules against an <see cref="OpenApiDocument"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace Microsoft.OpenApi.Validations.Rules
/// <summary>
/// The validation rules for <see cref="OpenApiHeader"/>.
/// </summary>
//Removed from Default Rules as this is not a MUST in OpenAPI
[OpenApiRule]
public static class OpenApiHeaderRules
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.OpenApi.Validations.Rules
/// Future versions of the example parsers should not try an infer types.
/// Example validation should be done as a separate post reading step so all schemas can be fully available.
/// </remarks>
//[OpenApiRule]
[OpenApiRule]
public static class OpenApiMediaTypeRules
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.OpenApi.Validations.Rules
/// <summary>
/// The validation rules for <see cref="OpenApiSchema"/>.
/// </summary>

[OpenApiRule]
public static class OpenApiSchemaRules
{
Expand Down
28 changes: 14 additions & 14 deletions src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void ValidateDataTypeMismatch(
// If value is not a string and also not an object, there is a data mismatch.
if (!(value is OpenApiObject))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
return;
Expand Down Expand Up @@ -117,7 +117,7 @@ public static void ValidateDataTypeMismatch(
// If value is not a string and also not an array, there is a data mismatch.
if (!(value is OpenApiArray))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
return;
Expand All @@ -141,7 +141,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiInteger))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -153,7 +153,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiLong))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -165,7 +165,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiInteger))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -177,7 +177,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiFloat))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -189,7 +189,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiDouble))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -201,7 +201,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiDouble))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -213,7 +213,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiByte))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -225,7 +225,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiDate))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -237,7 +237,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiDateTime))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -249,7 +249,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiPassword))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -261,7 +261,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiString))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand All @@ -273,7 +273,7 @@ public static void ValidateDataTypeMismatch(
{
if (!(value is OpenApiBoolean))
{
context.CreateError(
context.CreateWarning(
ruleName,
DataTypeMismatchedErrorMessage);
}
Expand Down
10 changes: 10 additions & 0 deletions src/Microsoft.OpenApi/Validations/ValidationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ public static void CreateError(this IValidationContext context, string ruleName,
OpenApiValidatorError error = new OpenApiValidatorError(ruleName, context.PathString, message);
context.AddError(error);
}

/// <summary>
/// Helper method to simplify validation rules
/// </summary>
public static void CreateWarning(this IValidationContext context, string ruleName, string message)
{
OpenApiValidatorWarning warning = new OpenApiValidatorWarning(ruleName, context.PathString, message);
context.AddWarning(warning);
}

}
}
Loading

0 comments on commit 5eb1481

Please sign in to comment.