Skip to content

Commit

Permalink
Merge pull request #1709 from domaindrivendev/support-stj-dynamic-types
Browse files Browse the repository at this point in the history
Generate empty schemas for JsonDocument & JsonElement types
  • Loading branch information
domaindrivendev committed Jun 17, 2020
2 parents 8fdcfd9 + 48042e4 commit a6dce86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
Expand Up @@ -65,6 +65,13 @@ public DataContract GetDataContractForType(Type type)
arrayItemType: itemType);
}

if (underlyingType.IsOneOf(typeof(JsonDocument), typeof(JsonElement)))
{
return new DataContract(
dataType: DataType.Unknown,
underlyingType: underlyingType);
}

return new DataContract(
dataType: DataType.Object,
underlyingType: underlyingType,
Expand Down
Expand Up @@ -640,6 +640,7 @@ public void GenerateSchema_GeneratesEmptySchema_IfJToken()
{
var schema = Subject().GenerateSchema(typeof(JToken), new SchemaRepository());

Assert.Null(schema.Reference);
Assert.Null(schema.Type);
}

Expand Down
Expand Up @@ -603,6 +603,17 @@ public void GenerateSchema_HonorsSerializerAttribute_JsonExtensionData()
Assert.Equal("object", schema.AdditionalProperties.Type);
}

[Theory]
[InlineData(typeof(JsonDocument))]
[InlineData(typeof(JsonElement))]
public void GenerateSchema_GeneratesEmptySchema_IfDynamicJsonType(Type type)
{
var schema = Subject().GenerateSchema(type, new SchemaRepository());

Assert.Null(schema.Reference);
Assert.Null(schema.Type);
}

private SchemaGenerator Subject(
Action<SchemaGeneratorOptions> configureGenerator = null,
Action<JsonSerializerOptions> configureSerializer = null)
Expand Down

0 comments on commit a6dce86

Please sign in to comment.