-
-
Notifications
You must be signed in to change notification settings - Fork 523
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 #884 from RSuter/master
Release v9.13.16
- Loading branch information
Showing
24 changed files
with
391 additions
and
15 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
20 changes: 20 additions & 0 deletions
20
src/NJsonSchema.CodeGeneration.CSharp.Tests/References/A.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,20 @@ | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"signalPaths" | ||
], | ||
"description": "This is the class A", | ||
"properties": { | ||
"type": { | ||
"$ref": "./C.json", | ||
"description": "This is the type of A" | ||
}, | ||
"signalPaths": { | ||
"children": "array", | ||
"items": { | ||
"$ref": "./B.json", | ||
"description": "This is a list of children" | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/NJsonSchema.CodeGeneration.CSharp.Tests/References/B.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,18 @@ | ||
{ | ||
"type": "object", | ||
"description": "This is the class B", | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"description": "This is the ID of B" | ||
}, | ||
"type": { | ||
"$ref": "./C.json", | ||
"description": "This is the type of B" | ||
}, | ||
"empty": { | ||
"$ref": "./D.json", | ||
"description": "This one should be of type D and not object" | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/NJsonSchema.CodeGeneration.CSharp.Tests/References/C.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 @@ | ||
{ | ||
"type":"string", | ||
"description":"Possible types", | ||
"enum":[ | ||
"First", | ||
"Second" | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
src/NJsonSchema.CodeGeneration.CSharp.Tests/References/D.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,4 @@ | ||
{ | ||
"type": "object", | ||
"description": "Possible types" | ||
} |
52 changes: 52 additions & 0 deletions
52
src/NJsonSchema.CodeGeneration.CSharp.Tests/References/E.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,52 @@ | ||
{ | ||
"definitions": { | ||
"B": { | ||
"type": "object", | ||
"description": "This is the class B", | ||
"properties": { | ||
"id": { | ||
"type": "string", | ||
"description": "This is the ID of B" | ||
}, | ||
"type": { | ||
"$ref": "#/definitions/C", | ||
"description": "This is the type of B" | ||
}, | ||
"empty": { | ||
"$ref": "#/definitions/D", | ||
"description": "This one should be of type D and not object" | ||
} | ||
} | ||
}, | ||
"C": { | ||
"type": "string", | ||
"description": "Possible types", | ||
"enum": [ | ||
"First", | ||
"Second" | ||
] | ||
}, | ||
"D": { | ||
"type": "object", | ||
"description": "Possible types" | ||
} | ||
}, | ||
"type": "object", | ||
"required": [ | ||
"signalPaths" | ||
], | ||
"description": "This is the class E", | ||
"properties": { | ||
"type": { | ||
"$ref": "#/definitions/C", | ||
"description": "This is the type of E" | ||
}, | ||
"signalPaths": { | ||
"children": "array", | ||
"items": { | ||
"$ref": "#/definitions/B", | ||
"description": "This is a list of children" | ||
} | ||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
src/NJsonSchema.CodeGeneration.CSharp.Tests/ReferencesTest.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,55 @@ | ||
using NJsonSchema.CodeGeneration.CSharp; | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.CodeGeneration.Tests.CSharp | ||
{ | ||
public class ReferencesTest | ||
{ | ||
[Fact] | ||
public async Task When_ref_is_definitions_no_types_are_duplicated() | ||
{ | ||
//// Arrange | ||
var path = GetTestDirectory() + "/References/E.json"; | ||
|
||
//// Act | ||
var schema = await JsonSchema4.FromFileAsync(path); | ||
var generator = new CSharpGenerator(schema); | ||
|
||
//// Act | ||
var code = generator.GenerateFile("MyClass"); | ||
|
||
//// Assert | ||
Assert.Contains("public enum C", code); | ||
Assert.DoesNotContain("public enum C2", code); | ||
} | ||
|
||
[Fact] | ||
public async Task When_ref_is_file_no_types_are_duplicated() | ||
{ | ||
//// Arrange | ||
var path = GetTestDirectory() + "/References/A.json"; | ||
|
||
//// Act | ||
var schema = await JsonSchema4.FromFileAsync(path); | ||
var generator = new CSharpGenerator(schema); | ||
|
||
//// Act | ||
var code = generator.GenerateFile("MyClass"); | ||
|
||
//// Assert | ||
Assert.Contains("public enum C", code); | ||
Assert.DoesNotContain("public enum C2", code); | ||
} | ||
|
||
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
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
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.