Skip to content

Commit

Permalink
Merge pull request #1009 from microsoft/vnext
Browse files Browse the repository at this point in the history
Merges `vnext` into `master`
  • Loading branch information
irvinesunday authored Sep 12, 2022
2 parents 512c795 + 307d569 commit 103ea84
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 10 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.0</Version>
<Version>1.4.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
12 changes: 8 additions & 4 deletions src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public OpenApiDocument Read(YamlDocument input, out OpenApiDiagnostic diagnostic
if (_settings.RuleSet != null && _settings.RuleSet.Rules.Count > 0)
{
var openApiErrors = document.Validate(_settings.RuleSet);
foreach (var item in openApiErrors.Where(e => e is OpenApiValidatorError))
foreach (var item in openApiErrors.OfType<OpenApiValidatorError>())
{
diagnostic.Errors.Add(item);
}
foreach (var item in openApiErrors.Where(e => e is OpenApiValidatorWarning))
foreach (var item in openApiErrors.OfType<OpenApiValidatorWarning>())
{
diagnostic.Warnings.Add(item);
}
Expand Down Expand Up @@ -114,11 +114,15 @@ public async Task<ReadResult> ReadAsync(YamlDocument input)
// 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.OfType<OpenApiValidatorError>())
{
diagnostic.Errors.Add(item);
}
foreach (var item in openApiErrors.OfType<OpenApiValidatorWarning>())
{
diagnostic.Warnings.Add(item);
}
}

return new ReadResult()
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.1</Version>
<Version>1.4.2</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
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Models/OpenApiDocument.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down
18 changes: 17 additions & 1 deletion src/Microsoft.OpenApi/Models/OpenApiExtensibleDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT license.

using System.Collections.Generic;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

Expand All @@ -17,6 +16,23 @@ public abstract class OpenApiExtensibleDictionary<T> : Dictionary<string, T>,
IOpenApiExtensible
where T : IOpenApiSerializable
{
/// <summary>
/// Parameterless constructor
/// </summary>
protected OpenApiExtensibleDictionary() { }

/// <summary>
/// Initializes a copy of <see cref="OpenApiExtensibleDictionary{T}"/> class.
/// </summary>
/// <param name="dictionary">The generic dictionary.</param>
/// <param name="extensions">The dictionary of <see cref="IOpenApiExtension"/>.</param>
protected OpenApiExtensibleDictionary(
Dictionary<string, T> dictionary = null,
IDictionary<string, IOpenApiExtension> extensions = null) : base (dictionary)
{
Extensions = extensions != null ? new Dictionary<string, IOpenApiExtension>(extensions) : null;
}

/// <summary>
/// This object MAY be extended with Specification Extensions.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Models/OpenApiPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public OpenApiPaths() {}
/// <summary>
/// Initializes a copy of <see cref="OpenApiPaths"/> object
/// </summary>
public OpenApiPaths(OpenApiPaths paths) {}

/// <param name="paths">The <see cref="OpenApiPaths"/>.</param>
public OpenApiPaths(OpenApiPaths paths) : base(dictionary: paths) {}
}
}
14 changes: 14 additions & 0 deletions test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,5 +1342,19 @@ private static OpenApiDocument ParseInputFile(string filePath)

return openApiDoc;
}

[Fact]
public void CopyConstructorForAdvancedDocumentWorks()
{
// Arrange & Act
var doc = new OpenApiDocument(AdvancedDocument);

// Assert
Assert.NotNull(doc.Info);
Assert.NotNull(doc.Servers);
Assert.NotNull(doc.Paths);
Assert.Equal(2, doc.Paths.Count);
Assert.NotNull(doc.Components);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ namespace Microsoft.OpenApi.Models
where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable
{
protected OpenApiExtensibleDictionary() { }
protected OpenApiExtensibleDictionary(System.Collections.Generic.Dictionary<string, T> dictionary = null, System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension> extensions = null) { }
public System.Collections.Generic.IDictionary<string, Microsoft.OpenApi.Interfaces.IOpenApiExtension> Extensions { get; set; }
public void SerializeAsV2(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
public void SerializeAsV3(Microsoft.OpenApi.Writers.IOpenApiWriter writer) { }
Expand Down

0 comments on commit 103ea84

Please sign in to comment.