-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add test #929 * Fix property type resolution for any schemas in definitions, RicoSuter/NSwag#2028 * Test and potential Fix for Interfaces. (#909) (#921) * Add legacy support, #921 * v9.13.25
- Loading branch information
Showing
11 changed files
with
139 additions
and
9 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
62 changes: 62 additions & 0 deletions
62
src/NJsonSchema.CodeGeneration.CSharp.Tests/InterfaceTests.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,62 @@ | ||
using System.Threading.Tasks; | ||
using NJsonSchema.Generation; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.CodeGeneration.CSharp.Tests | ||
{ | ||
public class InterfaceTests | ||
{ | ||
public interface IPerson | ||
{ | ||
string LastName { get; set; } | ||
string FirstName { get; set; } | ||
} | ||
|
||
public class Person : IPerson | ||
{ | ||
public string LastName { get; set; } | ||
public string FirstName { get; set; } | ||
} | ||
|
||
[Fact] | ||
public async Task When_interface_has_properties_then_properties_are_included_in_schema() | ||
{ | ||
//// Arrange | ||
var schema = await JsonSchema4.FromTypeAsync<Person>(new JsonSchemaGeneratorSettings()); | ||
|
||
//// Act | ||
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings | ||
{ | ||
ClassStyle = CSharpClassStyle.Poco, | ||
SchemaType = SchemaType.Swagger2 | ||
}); | ||
var code = generator.GenerateFile("Person"); | ||
|
||
//// Assert | ||
Assert.Equal(2, schema.Properties.Count); | ||
Assert.Contains("public string LastName { get; set; }\n", code); | ||
Assert.Contains("public string FirstName { get; set; }\n", code); | ||
} | ||
|
||
[Fact] | ||
public async Task When_class_implements_interface_then_properties_are_included_in_schema() | ||
{ | ||
//// Arrange | ||
var schema = await JsonSchema4.FromTypeAsync<Person>(new JsonSchemaGeneratorSettings()); | ||
|
||
//// Act | ||
var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings | ||
{ | ||
ClassStyle = CSharpClassStyle.Poco, | ||
SchemaType = SchemaType.Swagger2 | ||
}); | ||
var code = generator.GenerateFile("Person"); | ||
|
||
//// Assert | ||
Assert.Equal(2, schema.Properties.Count); | ||
Assert.Contains("public string LastName { get; set; }\n", code); | ||
Assert.Contains("public string FirstName { get; set; }\n", 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
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