Skip to content

Commit

Permalink
Update JsonObjectHandler to handle JsonExtensionData correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
rmorris committed Jan 14, 2020
1 parent 89a78db commit c47d3b7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ private OpenApiSchema CreateObjectSchema(Type type, SchemaRepository schemaRepos

foreach (var property in serializableProperties)
{
if (property.HasAttribute<JsonExtensionDataAttribute>() && property.PropertyType.IsDictionary(out Type keyType, out Type valueType))
{
schema.AdditionalPropertiesAllowed = true;
schema.AdditionalProperties = _schemaGenerator.GenerateSchema(valueType, schemaRepository);
continue;
}

var customAttributes = property.GetInlineOrMetadataTypeAttributes();

if (_generatorOptions.IgnoreObsoleteProperties && customAttributes.OfType<ObsoleteAttribute>().Any()) continue;
Expand All @@ -95,12 +102,6 @@ private OpenApiSchema CreateObjectSchema(Type type, SchemaRepository schemaRepos

if (customAttributes.OfType<RequiredAttribute>().Any())
schema.Required.Add(name);

if (property.HasAttribute<JsonExtensionDataAttribute>() && property.PropertyType.IsDictionary(out Type keyType, out Type valueType))
{
schema.AdditionalPropertiesAllowed = true;
schema.AdditionalProperties = _schemaGenerator.GenerateSchema(valueType, schemaRepository);
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ public void GenerateSchema_HonorsSerializerAttribute_JsonExtensionData()

var schema = schemaRepository.Schemas[referenceSchema.Reference.Id];
Assert.NotNull(schema.AdditionalProperties);
Assert.Equal(new[] { "Property1" }, schema.Properties.Keys.ToArray());
Assert.Equal("object", schema.AdditionalProperties.Type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ public void GenerateSchema_HonorsSerializerAttribute_JsonExtensionData()

var schema = schemaRepository.Schemas[referenceSchema.Reference.Id];
Assert.NotNull(schema.AdditionalProperties);
Assert.Equal(new[] { "Property1" }, schema.Properties.Keys.ToArray());
Assert.Equal("object", schema.AdditionalProperties.Type);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.ComponentModel;

namespace Basic.Controllers
{
Expand Down

0 comments on commit c47d3b7

Please sign in to comment.