-
-
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.
Correctly handle JArray in generator, closes RicoSuter/NSwag#755
- Loading branch information
Showing
2 changed files
with
34 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json.Linq; | ||
using NJsonSchema.Generation; | ||
using Xunit; | ||
|
||
namespace NJsonSchema.Tests.Generation | ||
{ | ||
public class ArrayGenerationTests | ||
{ | ||
public class ClassWithJArray | ||
{ | ||
public string Foo { get; set; } | ||
|
||
public JArray Array { get; set; } | ||
} | ||
|
||
[Fact] | ||
public async Task When_property_is_JArray_then_schema_with_any_array_is_generated() | ||
{ | ||
//// Act | ||
var schema = await JsonSchema4.FromTypeAsync<ClassWithJArray>(new JsonSchemaGeneratorSettings { SchemaType = SchemaType.OpenApi3 }); | ||
var json = schema.ToJson(); | ||
|
||
//// Assert | ||
Assert.Equal(2, schema.ActualProperties.Count); | ||
var arrayProperty = schema.ActualProperties["Array"].ActualTypeSchema; | ||
Assert.Equal(JsonObjectType.Array, arrayProperty.Type); | ||
Assert.True(arrayProperty.Item.ActualTypeSchema.IsAnyType); | ||
} | ||
} | ||
} |
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