Skip to content

Commit

Permalink
Correctly handle interfaces for derived types (#2826)
Browse files Browse the repository at this point in the history
* Correctly respect interfaces in `GetInheritanceChain`.
  • Loading branch information
angelaki authored Apr 23, 2024
1 parent c936acb commit e60acef
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public static object GetDefaultValue(this Type type)

public static Type[] GetInheritanceChain(this Type type)
{
if (type.IsInterface) { return type.GetInterfaces(); }

var inheritanceChain = new List<Type>();

var current = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ public void GenerateSchema_IncludesInheritedProperties_IfTypeIsAnInterfaceHierar
Assert.Equal(expectedPropertyNames.OrderBy(n => n), schema.Properties.Keys.OrderBy(k => k));
}

[Fact]
public void GenerateSchema_KeepMostDerivedType_IfTypeIsAnInterface()
{
var schemaRepository = new SchemaRepository();

var referenceSchema = Subject().GenerateSchema(typeof(INewBaseInterface), schemaRepository);

var schema = schemaRepository.Schemas[referenceSchema.Reference.Id];
Assert.Equal("integer", schema.Properties["BaseProperty"].Type);
}

[Fact]
public void GenerateSchema_ExcludesIndexerProperties_IfComplexTypeIsIndexed()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,9 @@ public interface IMultiSubInterface : ISubInterface1, ISubInterface2
{
public int Property3 { get; set; }
}

public interface INewBaseInterface : IBaseInterface
{
public new int BaseProperty { get; set; }
}
}

0 comments on commit e60acef

Please sign in to comment.