forked from microsoft/OpenAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenApiCompoentsTests.cs
41 lines (37 loc) · 1.92 KB
/
OpenApiCompoentsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.Reader;
using Xunit;
namespace Microsoft.OpenApi.Readers.Tests.V31Tests
{
public class OpenApiCompoentsTests
{
[Theory]
[InlineData("./FirstLevel/SecondLevel/ThridLevel/File.json#/components/schemas/ExternalRelativePathModel", "ExternalRelativePathModel", "./FirstLevel/SecondLevel/ThridLevel/File.json")]
[InlineData("File.json#/components/schemas/ExternalSimpleRelativePathModel", "ExternalSimpleRelativePathModel", "File.json")]
[InlineData("A:\\Dir\\File.json#/components/schemas/ExternalAbsWindowsPathModel", "ExternalAbsWindowsPathModel", "A:\\Dir\\File.json")]
[InlineData("/Dir/File.json#/components/schemas/ExternalAbsUnixPathModel", "ExternalAbsUnixPathModel", "/Dir/File.json")]
[InlineData("https://host.lan:1234/path/to/file/resource.json#/components/schemas/ExternalHttpsModel", "ExternalHttpsModel", "https://host.lan:1234/path/to/file/resource.json")]
[InlineData("File.json", "File.json", null)]
public void ParseExternalSchemaReferenceShouldSucceed(string reference, string referenceId, string externalResource)
{
var input = $@"{{
""schemas"": {{
""Model"": {{
""$ref"": ""{reference.Replace("\\", "\\\\")}""
}}
}}
}}
";
var openApiDocument = new OpenApiDocument();
// Act
var components = OpenApiModelFactory.Parse<OpenApiComponents>(input, OpenApiSpecVersion.OpenApi3_1, openApiDocument, out _, "json");
// Assert
var schema = components.Schemas["Model"] as OpenApiSchemaReference;
var expected = new OpenApiSchemaReference(referenceId, openApiDocument, externalResource);
Assert.Equivalent(expected, schema);
}
}
}