Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/RSuter/NJsonSchema
- Loading branch information
Showing
12 changed files
with
259 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFrameworks>netcoreapp2.0;net46;net45</TargetFrameworks> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DocumentationFile>bin\Debug\$(TargetFramework)\NJsonSchema.Yaml.Tests.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
<PackageReference Condition="'$(TargetFramework)' == 'netcoreapp2.0'" Include="System.ComponentModel.Annotations" Version="4.4.0" /> | ||
<Reference Condition="'$(TargetFramework)' == 'net45'" Include="System.ComponentModel.DataAnnotations"> | ||
</Reference> | ||
<Reference Condition="'$(TargetFramework)' == 'net46'" Include="System.ComponentModel.DataAnnotations"> | ||
</Reference> | ||
<PackageReference Include="NodaTime" Version="2.2.0" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\NJsonSchema\NJsonSchema.csproj" /> | ||
<ProjectReference Include="..\NJsonSchema.Yaml\NJsonSchema.Yaml.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Content Include="References\YamlReferencesTest\collection.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="References\YamlReferencesTest\collection.yaml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="References\YamlReferencesTest\json_schema_with_yaml_reference.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="References\YamlReferencesTest\json_schema_with_json_reference.json"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="References\YamlReferencesTest\yaml_schema_with_json_reference.yaml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
<Content Include="References\YamlReferencesTest\yaml_schema_with_yaml_reference.yaml"> | ||
<CopyToOutputDirectory>Always</CopyToOutputDirectory> | ||
</Content> | ||
</ItemGroup> | ||
</Project> |
8 changes: 8 additions & 0 deletions
8
src/NJsonSchema.Yaml.Tests/References/YamlReferencesTest/collection.json
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,8 @@ | ||
{ | ||
"myInt": { | ||
"type": "integer" | ||
}, | ||
"myBool": { | ||
"type": "boolean" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/NJsonSchema.Yaml.Tests/References/YamlReferencesTest/collection.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,5 @@ | ||
--- | ||
myInt: | ||
type: integer | ||
myBool: | ||
type: boolean |
16 changes: 16 additions & 0 deletions
16
...NJsonSchema.Yaml.Tests/References/YamlReferencesTest/json_schema_with_json_reference.json
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,16 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"bar": { | ||
"$ref": "./collection.json#/myBool" | ||
}, | ||
"foo": { | ||
"$ref": "#/definitions/collection/myInt" | ||
} | ||
}, | ||
"definitions": { | ||
"collection": { | ||
"$ref": "./collection.json" | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...NJsonSchema.Yaml.Tests/References/YamlReferencesTest/json_schema_with_yaml_reference.json
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,16 @@ | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"bar": { | ||
"$ref": "./collection.yaml#/myBool" | ||
}, | ||
"foo": { | ||
"$ref": "#/definitions/collection/myInt" | ||
} | ||
}, | ||
"definitions": { | ||
"collection": { | ||
"$ref": "./collection.yaml" | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...NJsonSchema.Yaml.Tests/References/YamlReferencesTest/yaml_schema_with_json_reference.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,10 @@ | ||
--- | ||
type: object | ||
properties: | ||
bar: | ||
"$ref": "./collection.json#/myBool" | ||
foo: | ||
"$ref": "#/definitions/collection/myInt" | ||
definitions: | ||
collection: | ||
"$ref": "./collection.json" |
10 changes: 10 additions & 0 deletions
10
...NJsonSchema.Yaml.Tests/References/YamlReferencesTest/yaml_schema_with_yaml_reference.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,10 @@ | ||
--- | ||
type: object | ||
properties: | ||
bar: | ||
"$ref": "./collection.yaml#/myBool" | ||
foo: | ||
"$ref": "#/definitions/collection/myInt" | ||
definitions: | ||
collection: | ||
"$ref": "./collection.yaml" |
38 changes: 38 additions & 0 deletions
38
src/NJsonSchema.Yaml.Tests/References/YamlReferencesTests.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,38 @@ | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.Yaml.Tests.References | ||
{ | ||
public class LocalReferencesTests | ||
{ | ||
[Theory] | ||
[InlineData("/References/YamlReferencesTest/json_schema_with_json_reference.json", "./collection.json")] | ||
[InlineData("/References/YamlReferencesTest/yaml_schema_with_json_reference.yaml", "./collection.json")] | ||
[InlineData("/References/YamlReferencesTest/yaml_schema_with_yaml_reference.yaml", "./collection.yaml")] | ||
[InlineData("/References/YamlReferencesTest/json_schema_with_yaml_reference.json", "./collection.yaml")] | ||
public async Task When_yaml_schema_has_references_it_works(string relativePath, string documentPath) | ||
{ | ||
//// Arrange | ||
var path = GetTestDirectory() + relativePath; | ||
|
||
//// Act | ||
var schema = await JsonSchemaYaml.FromFileAsync(path); | ||
var json = schema.ToJson(); | ||
|
||
//// Assert | ||
Assert.Equal(JsonObjectType.Integer, schema.Properties["foo"].ActualTypeSchema.Type); | ||
Assert.Equal(1, schema.Definitions.Count); | ||
Assert.Equal(documentPath, schema.Definitions["collection"].DocumentPath); | ||
} | ||
|
||
private string GetTestDirectory() | ||
{ | ||
var codeBase = Assembly.GetExecutingAssembly().CodeBase; | ||
var uri = new UriBuilder(codeBase); | ||
return Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.