Skip to content

Commit

Permalink
port domaindrivendev#2826 Correctly respect interfaces in GetInherita…
Browse files Browse the repository at this point in the history
…nceChain
  • Loading branch information
Havunen committed May 5, 2024
1 parent c3c3a8a commit 1247e24
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 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 @@ -2538,14 +2538,14 @@
"IChild": {
"type": "object",
"properties": {
"value": {
"parentValue": {
"type": "string",
"description": "The child value.",
"description": "The parent value.",
"nullable": true
},
"parentValue": {
"value": {
"type": "string",
"description": "The parent value.",
"description": "The child value.",
"nullable": true
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ public void GenerateSchema_HonorsEnumDictionaryKeys_StringEnumConverter()
Assert.Equal(typeof(IntEnum).GetEnumNames(), referenceSchema.Properties.Keys);
}


[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);
}



[Theory]
[InlineData(typeof(IntEnum), "integer", "int32", "2", "4", "8")]
[InlineData(typeof(LongEnum), "integer", "int64", "2", "4", "8")]
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 1247e24

Please sign in to comment.