-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2133 from dldl-cmd/fix_referenceWithFolderLoading
Fix: reference with folder loading
- Loading branch information
Showing
5 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/Microsoft.OpenApi.Readers.Tests/V31Tests/OpenApiCompoentsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...crosoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiSchema/externalReferencesSchema.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#schemaObject | ||
openapi: 3.0.0 | ||
info: | ||
title: Simple Document | ||
version: 0.9.1 | ||
paths: { } | ||
components: | ||
schemas: | ||
RelativePathModel: | ||
allOf: | ||
- $ref: './FirstLevel/SecondLevel/ThridLevel/File.json#/components/schemas/ExternalRelativePathModel' | ||
SimpleRelativePathModel: | ||
allOf: | ||
- $ref: 'File.json#/components/schemas/ExternalSimpleRelativePathModel' | ||
AbsoluteWindowsPathModel: | ||
allOf: | ||
- $ref: 'A:\Dir\File.json#/components/schemas/ExternalAbsWindowsPathModel' | ||
AbsoluteUnixPathModel: | ||
allOf: | ||
- $ref: '/Dir/File.json#/components/schemas/ExternalAbsUnixPathModel' | ||
HttpsUrlModel: | ||
allOf: | ||
- $ref: 'https://host.lan:1234/path/to/file/resource.json#/components/schemas/ExternalHttpsModel' |