Skip to content

Commit 7abf172

Browse files
committed
test(v3): add unit test for component property schema reference in OpenAPI 3.0
1 parent d23bbf4 commit 7abf172

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using Microsoft.OpenApi;
5+
using Microsoft.OpenApi.Reader;
6+
using Microsoft.OpenApi.Tests;
7+
using Xunit;
8+
9+
namespace Microsoft.OpenApi.Readers.Tests.V3Tests
10+
{
11+
[Collection("DefaultSettings")]
12+
public class OpenApiSubschemaReferenceTests
13+
{
14+
private const string Document = @"
15+
openapi: 3.0.3
16+
info:
17+
title: Subschema references
18+
version: 1.0.0
19+
paths: {}
20+
components:
21+
schemas:
22+
User:
23+
type: object
24+
properties:
25+
name:
26+
type: string
27+
address:
28+
type: object
29+
properties:
30+
city:
31+
type: string
32+
name:
33+
type: integer
34+
UserName:
35+
$ref: '#/components/schemas/User/properties/name'
36+
UserCity:
37+
$ref: '#/components/schemas/User/properties/address/properties/city'
38+
";
39+
40+
[Fact]
41+
public void ReferenceToComponentPropertyResolvesToThatProperty()
42+
{
43+
var document = OpenApiDocument.Parse(Document, "yaml", SettingsFixture.ReaderSettings).Document;
44+
45+
var userName = Assert.IsType<OpenApiSchemaReference>(document.Components.Schemas["UserName"]);
46+
47+
Assert.NotNull(userName.Target);
48+
Assert.Equal(JsonSchemaType.String, userName.Target.Type);
49+
Assert.Equal("#/components/schemas/User/properties/name", userName.Reference.ReferenceV3);
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)