Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly respect interfaces in GetInheritanceChain #2826

Merged
merged 2 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; }
}
}