Skip to content

Commit

Permalink
Fixes an issue where interface chain is not checked for parameters, t…
Browse files Browse the repository at this point in the history
…his resolves issue: domaindrivendev#2596 for #3
  • Loading branch information
Havunen committed Feb 25, 2024
1 parent f354f74 commit ae51f83
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,27 @@ public static PropertyInfo PropertyInfo(this ApiParameterDescription apiParamete
{
var modelMetadata = apiParameter.ModelMetadata;

return modelMetadata?.ContainerType?.GetProperty(modelMetadata.PropertyName);
if (modelMetadata.ContainerType != null)
{
PropertyInfo propertyInfo = modelMetadata.ContainerType.GetProperty(modelMetadata.PropertyName);

if (propertyInfo != null)
{
return propertyInfo;
}

foreach (var type in modelMetadata.ContainerType.GetInterfaces())
{
propertyInfo = type.GetProperty(modelMetadata.PropertyName);

if (propertyInfo != null)
{
return propertyInfo;
}
}
}

return null;
}

public static IEnumerable<object> CustomAttributes(this ApiParameterDescription apiParameter)
Expand Down
23 changes: 23 additions & 0 deletions test/WebSites/Basic/Controllers/CrudActionsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Net.Mime;
using Microsoft.AspNetCore.Mvc;

namespace Basic.Controllers
Expand Down Expand Up @@ -97,6 +98,28 @@ public ProductStatus PostStatus([FromBody] ProductStatus status)
{
return status;
}

[HttpGet("GetDoc")]
[Consumes(typeof(IChild), MediaTypeNames.Application.Json)]
[Produces(typeof(IChild))]
public IActionResult GetDoc([FromQuery] IChild query)
{
return null;
}
}

/// <summary>The parent.</summary>
public interface IParent
{
/// <summary>The parent value.</summary>
string? ParentValue { get; set; }
}

/// <summary>The child.</summary>
public interface IChild : IParent
{
/// <summary>The child value.</summary>
string? Value { get; set; }
}

public enum ProductStatus
Expand Down

0 comments on commit ae51f83

Please sign in to comment.