Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
schulz3000 committed Oct 4, 2023
1 parent ebd165d commit 59c5058
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/NJsonSchema.Tests/Schema/JsonSchemaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Xunit;

namespace NJsonSchema.Tests.Schema
Expand Down Expand Up @@ -425,5 +426,20 @@ public async Task When_azure_schema_is_loaded_then_no_exception()
Assert.NotNull(schema);
Assert.Contains("The identity type.", json);
}

[Fact]
public void When_sample_json_has_mixed_type_array_anyOf_should_be_used_for_schema_items()
{
//https://github.com/RicoSuter/NJsonSchema/issues/1593

//// Arrange
var schema = JsonSchema.FromSampleJson("[1, { \"a\": \"b\"}, \"value\"]");

//// Act
var json = schema.ToJson();

//// Assert
Assert.Contains("anyOf", json);
}
}
}
5 changes: 4 additions & 1 deletion src/NJsonSchema/SampleJsonSchemaGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ private void GenerateArray(JToken token, JsonSchema schema, JsonSchema rootSchem
}
else
{
schema.Item = itemSchemas.First();
schema.Item = new JsonSchema
{
AnyOf = itemSchemas
};
}
}

Expand Down

0 comments on commit 59c5058

Please sign in to comment.