Skip to content

Commit

Permalink
Merge pull request #892 from matt9ucci/contact-fragment
Browse files Browse the repository at this point in the history
Add OpenApiContact for ReadFragment
  • Loading branch information
baywet authored Jun 23, 2022
2 parents 5fa5c65 + a955bb1 commit 4c8ab29
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public OpenApiV2VersionService(OpenApiDiagnostic diagnostic)
private IDictionary<Type, Func<ParseNode, object>> _loaders = new Dictionary<Type, Func<ParseNode, object>>
{
[typeof(IOpenApiAny)] = OpenApiV2Deserializer.LoadAny,
[typeof(OpenApiContact)] = OpenApiV2Deserializer.LoadContact,
[typeof(OpenApiExternalDocs)] = OpenApiV2Deserializer.LoadExternalDocs,
[typeof(OpenApiHeader)] = OpenApiV2Deserializer.LoadHeader,
[typeof(OpenApiInfo)] = OpenApiV2Deserializer.LoadInfo,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public OpenApiV3VersionService(OpenApiDiagnostic diagnostic)
[typeof(IOpenApiAny)] = OpenApiV3Deserializer.LoadAny,
[typeof(OpenApiCallback)] = OpenApiV3Deserializer.LoadCallback,
[typeof(OpenApiComponents)] = OpenApiV3Deserializer.LoadComponents,
[typeof(OpenApiContact)] = OpenApiV3Deserializer.LoadContact,
[typeof(OpenApiEncoding)] = OpenApiV3Deserializer.LoadEncoding,
[typeof(OpenApiExample)] = OpenApiV3Deserializer.LoadExample,
[typeof(OpenApiExternalDocs)] = OpenApiV3Deserializer.LoadExternalDocs,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FluentAssertions;
using Microsoft.OpenApi.Models;
using System;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V2Tests
{
public class OpenApiContactTests
{
[Fact]
public void ParseStringContactFragmentShouldSucceed()
{
var input = @"
{
""name"": ""API Support"",
""url"": ""http://www.swagger.io/support"",
""email"": ""[email protected]""
}
";
var reader = new OpenApiStringReader();
var diagnostic = new OpenApiDiagnostic();

// Act
var contact = reader.ReadFragment<OpenApiContact>(input, OpenApiSpecVersion.OpenApi2_0, out diagnostic);

// Assert
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());

contact.Should().BeEquivalentTo(
new OpenApiContact
{
Email = "[email protected]",
Name = "API Support",
Url = new Uri("http://www.swagger.io/support")
});
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using FluentAssertions;
using Microsoft.OpenApi.Models;
using System;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V3Tests
{
public class OpenApiContactTests
{
[Fact]
public void ParseStringContactFragmentShouldSucceed()
{
var input = @"
{
""name"": ""API Support"",
""url"": ""http://www.swagger.io/support"",
""email"": ""[email protected]""
}
";
var reader = new OpenApiStringReader();
var diagnostic = new OpenApiDiagnostic();

// Act
var contact = reader.ReadFragment<OpenApiContact>(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic);

// Assert
diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());

contact.Should().BeEquivalentTo(
new OpenApiContact
{
Email = "[email protected]",
Name = "API Support",
Url = new Uri("http://www.swagger.io/support")
});
}
}
}

0 comments on commit 4c8ab29

Please sign in to comment.