Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Inline dictionary or array inheritance (#785)
* Inline dictionary or array inheritance * Fix c# generation
- Loading branch information
Showing
9 changed files
with
214 additions
and
24 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
41 changes: 41 additions & 0 deletions
41
src/NJsonSchema.CodeGeneration.CSharp.Tests/InheritanceTests.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 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using NJsonSchema.CodeGeneration.CSharp; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.CodeGeneration.Tests.CSharp | ||
{ | ||
public class InheritanceTests | ||
{ | ||
public class MyContainer | ||
{ | ||
public EmptyClassInheritingDictionary CustomDictionary { get; set; } | ||
} | ||
|
||
public sealed class EmptyClassInheritingDictionary : Dictionary<string, object> | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task When_empty_class_inherits_from_dictionary_then_allOf_inheritance_still_works() | ||
{ | ||
//// Arrange | ||
var schema = await JsonSchema4.FromTypeAsync<MyContainer>(); | ||
var data = schema.ToJson(); | ||
|
||
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings()); | ||
|
||
//// Act | ||
var code = generator.GenerateFile(); | ||
|
||
//// Assert | ||
var dschema = schema.Definitions["EmptyClassInheritingDictionary"]; | ||
Assert.Equal(0, dschema.AllOf.Count); | ||
Assert.True(dschema.IsDictionary); | ||
|
||
Assert.Contains("public EmptyClassInheritingDictionary CustomDictionary", code); | ||
Assert.Contains("public partial class EmptyClassInheritingDictionary : System.Collections.Generic.Dictionary<string, object>", code); | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
src/NJsonSchema.CodeGeneration.TypeScript.Tests/InheritanceTests.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,39 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.CodeGeneration.TypeScript.Tests | ||
{ | ||
public class InheritanceTests | ||
{ | ||
public class MyContainer | ||
{ | ||
public EmptyClassInheritingDictionary CustomDictionary { get; set; } | ||
} | ||
|
||
public sealed class EmptyClassInheritingDictionary : Dictionary<string, object> | ||
{ | ||
} | ||
|
||
[Fact] | ||
public async Task When_empty_class_inherits_from_dictionary_then_allOf_inheritance_still_works() | ||
{ | ||
//// Arrange | ||
var schema = await JsonSchema4.FromTypeAsync<MyContainer>(); | ||
var data = schema.ToJson(); | ||
|
||
var generator = new TypeScriptGenerator(schema, new TypeScriptGeneratorSettings { TypeScriptVersion = 2.0m }); | ||
|
||
//// Act | ||
var code = generator.GenerateFile("ContainerClass"); | ||
|
||
//// Assert | ||
var dschema = schema.Definitions["EmptyClassInheritingDictionary"]; | ||
Assert.Equal(0, dschema.AllOf.Count); | ||
Assert.True(dschema.IsDictionary); | ||
|
||
Assert.DoesNotContain("EmptyClassInheritingDictionary", code); | ||
Assert.Contains("customDictionary: { [key: string] : any; } | undefined;", code); | ||
} | ||
} | ||
} |
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