From 3bacb48238e0783ad5cc6c50be9c004cc40a1963 Mon Sep 17 00:00:00 2001 From: Rico Suter Date: Thu, 14 Jun 2018 19:20:33 +0200 Subject: [PATCH] Correctly handle JArray in generator, closes https://github.com/RSuter/NSwag/issues/755 --- .../Generation/ArrayGenerationTests.cs | 31 +++++++++++++++++++ .../Generation/DefaultReflectionService.cs | 3 ++ 2 files changed, 34 insertions(+) create mode 100644 src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs diff --git a/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs b/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs new file mode 100644 index 000000000..181ac16e5 --- /dev/null +++ b/src/NJsonSchema.Tests/Generation/ArrayGenerationTests.cs @@ -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(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); + } + } +} \ No newline at end of file diff --git a/src/NJsonSchema/Generation/DefaultReflectionService.cs b/src/NJsonSchema/Generation/DefaultReflectionService.cs index ea52df6ee..d9bd68bed 100644 --- a/src/NJsonSchema/Generation/DefaultReflectionService.cs +++ b/src/NJsonSchema/Generation/DefaultReflectionService.cs @@ -105,6 +105,9 @@ public virtual JsonTypeDescription GetDescription(Type type, IEnumerable