Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root element of external schema ref files cannot be same name as any property of JsonSchema #1336

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/NJsonSchema.Yaml.Tests/NJsonSchema.Yaml.Tests.csproj
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>bin\Debug\$(TargetFramework)\NJsonSchema.Yaml.Tests.xml</DocumentationFile>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="NSwag.Core.Yaml" Version="13.10.2" />
Expand Down Expand Up @@ -35,6 +35,9 @@
</Content>
<Content Include="References\YamlReferencesTest\json_schema_with_json_reference.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="References\YamlReferencesTest\schema_with_indirect_subreference_to_title.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="References\YamlReferencesTest\yaml_schema_with_json_reference.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand All @@ -56,6 +59,9 @@
<None Update="References\YamlReferencesTest\common-items\schemas.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="References\YamlReferencesTest\schema_named_title.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="References\YamlReferencesTest\yaml_spec_with_yaml_schema_refs.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
@@ -0,0 +1,3 @@
---
Title:
type: object
@@ -0,0 +1,4 @@
type: object
properties:
titleProperty:
$ref: 'schema_named_title.yaml#/Title'
16 changes: 16 additions & 0 deletions src/NJsonSchema.Yaml.Tests/References/YamlReferencesTests.cs
Expand Up @@ -5,6 +5,7 @@
using NSwag;
using System.Threading.Tasks;
using Xunit;
using Newtonsoft.Json;

namespace NJsonSchema.Yaml.Tests.References
{
Expand Down Expand Up @@ -62,6 +63,21 @@ public async Task When_yaml_OpenAPI_spec_has_external_schema_refs_they_are_resol
Assert.NotNull(Unauthorized.Schema);
}

[Fact]
public async Task When_document_has_indirect_external_ref_to_a_schema_named_title_then_it_is_loaded()
{
//// Arrange
var path = GetTestDirectory() + "/References/YamlReferencesTest/schema_with_indirect_subreference_to_title.yaml";

//// Act
var schema = await JsonSchemaYaml.FromFileAsync(path);
var json = schema.ToJson();

//// Assert
Assert.Equal(1, schema.Definitions.Count);
Assert.True(schema.Definitions.ContainsKey("Title"));
}

private string GetTestDirectory()
{
var codeBase = Assembly.GetExecutingAssembly().CodeBase;
Expand Down