Permalink
Browse files

Improved handling of open generic types in generator

  • Loading branch information...
RSuter committed Aug 15, 2017
1 parent 70d5a89 commit d6ae1f01ca436c8a121688858cc1c30f9590d519
View
@@ -13,4 +13,5 @@ src/packages/Newtonsoft.Json**
[Bb]in/
[Oo]bj/
/src/packages
/src/packages
.vs
@@ -35,5 +35,23 @@ public async Task When_class_inherits_from_IEnumerable_then_it_should_become_a_j
Assert.AreEqual(JsonObjectType.Array, schema.Type);
Assert.AreEqual(JsonObjectType.String, schema.Item.Type);
}
public class A<T>
{
public T B { get; set; }
}
[TestMethod]
public async Task When_open_generic_type_is_generated_then_no_exception_is_thrown()
{
//// Arrange
var schema = await JsonSchema4.FromTypeAsync(typeof(A<>));
//// Act
var json = schema.ToJson();
//// Assert
Assert.IsNotNull(json);
}
}
}
@@ -337,7 +337,7 @@ private async Task GeneratePropertiesAndInheritanceAsync(Type type, JsonContract
var info = propertiesAndFields.FirstOrDefault(p => p.Name == property.UnderlyingName);
var propertyInfo = info as PropertyInfo;
#if !LEGACY
if (Settings.GenerateAbstractProperties || propertyInfo == null ||
if (Settings.GenerateAbstractProperties || propertyInfo == null ||
(propertyInfo.GetMethod?.IsAbstract != true && propertyInfo.SetMethod?.IsAbstract != true))
#else
if (Settings.GenerateAbstractProperties || propertyInfo == null ||
@@ -639,7 +639,12 @@ private bool RequiresSchemaReference(Type type, IEnumerable<Attribute> parentAtt
return !typeDescription.IsDictionary && (typeDescription.Type.HasFlag(JsonObjectType.Object) || typeDescription.IsEnum);
}
private JsonContract ResolveContract(Type type) => Settings.ActualContractResolver.ResolveContract(type);
private JsonContract ResolveContract(Type type)
{
return !type.GetTypeInfo().IsGenericTypeDefinition ?
Settings.ActualContractResolver.ResolveContract(type) :
null;
}
private bool IsPropertyIgnored(Type propertyType, Type parentType, Attribute[] propertyAttributes)
{

0 comments on commit d6ae1f0

Please sign in to comment.