Skip to content

Commit b7c37fc

Browse files
Referencable elements can resolve a reference with an empty JSON pointer to themselves
1 parent ccbef09 commit b7c37fc

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/Microsoft.OpenApi/Extensions/OpenApiReferencableExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static class OpenApiReferencableExtensions
2323
/// <returns>An IEnumerable of errors. This function will never return null.</returns>
2424
public static IOpenApiReferenceable ResolveReference(this IOpenApiReferenceable element, string jsonPointer)
2525
{
26-
throw new NotImplementedException();
26+
return element;
2727
}
2828
}
2929
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System.Collections.Generic;
5+
using Microsoft.OpenApi.Extensions;
6+
using Microsoft.OpenApi.Interfaces;
7+
using Microsoft.OpenApi.Models;
8+
using Xunit;
9+
10+
namespace Microsoft.OpenApi.Tests.Workspaces
11+
{
12+
13+
public class OpenApiReferencableTests
14+
{
15+
public static IEnumerable<object[]> ReferencableElementResolvesEmptyJsonPointerToItselfTestData =>
16+
new List<object[]>
17+
{
18+
new object[] { new OpenApiCallback() },
19+
new object[] { new OpenApiExample() },
20+
new object[] { new OpenApiHeader() },
21+
new object[] { new OpenApiLink() },
22+
new object[] { new OpenApiParameter() },
23+
new object[] { new OpenApiRequestBody() },
24+
new object[] { new OpenApiResponse() },
25+
new object[] { new OpenApiSchema() },
26+
new object[] { new OpenApiSecurityScheme() },
27+
new object[] { new OpenApiTag() }
28+
29+
};
30+
31+
[Theory]
32+
[MemberData(nameof(ReferencableElementResolvesEmptyJsonPointerToItselfTestData))]
33+
public void ReferencableElementResolvesEmptyJsonPointerToItself(IOpenApiReferenceable referencableElement)
34+
{
35+
// Arrange - above
36+
37+
// Act
38+
var resolvedReference = referencableElement.ResolveReference(string.Empty);
39+
40+
// Assert
41+
Assert.Same(referencableElement, resolvedReference);
42+
}
43+
}
44+
}

0 commit comments

Comments
 (0)