Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -11,12 +11,13 @@ public static MethodInfo GetUnderlyingGenericTypeMethod(this MethodInfo construc
var genericTypeDefinition = constructedType.GetGenericTypeDefinition();
var genericArguments = constructedType.GenericTypeArguments;

var constructedTypeParameters = constructedTypeMethod.GetParameters();

// Retrieve list of candidate methods that match name and parameter count
var candidateMethods = genericTypeDefinition.GetMethods()
.Where(m =>
{
var genericTypeDefinitionParameters = m.GetParameters();
var constructedTypeParameters = constructedTypeMethod.GetParameters();
if (m.Name == constructedTypeMethod.Name && genericTypeDefinitionParameters.Length == constructedTypeParameters.Length)
{
for (var i = 0; i < genericTypeDefinitionParameters.Length; i++)
Expand All @@ -36,6 +37,10 @@ public static MethodInfo GetUnderlyingGenericTypeMethod(this MethodInfo construc
}
else if (genericTypeDefinitionParameters[i].ParameterType.IsConstructedGenericType && constructedTypeParameters[i].ParameterType.IsConstructedGenericType)
{
if (genericTypeDefinitionParameters[i].ParameterType.GetGenericTypeDefinition() != constructedTypeParameters[i].ParameterType.GetGenericTypeDefinition())
{
return false;
}
var genericTypeDefinitionArguments = genericTypeDefinitionParameters[i].ParameterType.GetGenericArguments();
var constructedDefinitionArguments = constructedTypeParameters[i].ParameterType.GetGenericArguments();
if (genericTypeDefinitionArguments.Length != constructedDefinitionArguments.Length)
Expand All @@ -44,7 +49,6 @@ public static MethodInfo GetUnderlyingGenericTypeMethod(this MethodInfo construc
}
for (var j = 0; j < genericTypeDefinitionArguments.Length; j++)
{

if (genericTypeDefinitionArguments[j].IsGenericParameter && genericArguments.Any(p => p == constructedDefinitionArguments[j]))
{
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"version": "1"
},
"paths": {
"/{tennantId}/orders": {
"/{tenantId}/orders": {
"post": {
"tags": [
"Orders"
],
"summary": "Creates a resource",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -65,7 +65,7 @@
"summary": "Delete by Ids",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -133,15 +133,15 @@
}
}
},
"/{tennantId}/orders/DeleteById": {
"/{tenantId}/orders/DeleteById": {
"delete": {
"tags": [
"Orders"
],
"summary": "Delete by Id",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -200,15 +200,15 @@
}
}
},
"/{tennantId}/orders/Delete/List": {
"/{tenantId}/orders/Delete/List": {
"delete": {
"tags": [
"Orders"
],
"summary": "Delete by Id List",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -276,15 +276,15 @@
}
}
},
"/{tennantId}/products": {
"/{tenantId}/products": {
"post": {
"tags": [
"Products"
],
"summary": "Creates a resource",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -336,7 +336,7 @@
"summary": "Delete by Ids",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -404,15 +404,15 @@
}
}
},
"/{tennantId}/products/DeleteById": {
"/{tenantId}/products/DeleteById": {
"delete": {
"tags": [
"Products"
],
"summary": "Delete by Id",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down Expand Up @@ -471,15 +471,15 @@
}
}
},
"/{tennantId}/products/Delete/List": {
"/{tenantId}/products/Delete/List": {
"delete": {
"tags": [
"Products"
],
"summary": "Delete by Id List",
"parameters": [
{
"name": "tennantId",
"name": "tenantId",
"in": "path",
"required": true,
"schema": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Threading;
using Microsoft.AspNetCore.Mvc;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures
{
internal class FakeGenericResourceController<T>
where T : class
{
public virtual int DifferentMethodsSignatures([FromBody, Required] T t, CancellationToken cancellationToken) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] string key, T t) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] T[] ts) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] string[] strings) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] List<T> ts) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] List<string> strings) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] Dictionary<int, T> ts) => 1;
public virtual int DifferentMethodsSignatures([FromBody, Required] IEnumerable<T> ts) => 1;
}
internal class NonGenericResourceController : FakeGenericResourceController<XmlAnnotatedRecord>
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Linq;
using System.Reflection;
using Swashbuckle.AspNetCore.SwaggerGen.Test.Fixtures;
using Xunit;

namespace Swashbuckle.AspNetCore.SwaggerGen.Test
{
public class XmlMethodInfoExtensionsTests
{
[Theory, MemberData(nameof(DifferentMethodsSignatures))]
public void DifferentMethodsSignatures_ShouldNotBeNull(MethodInfo methodInfo)
{
Assert.NotNull(methodInfo.GetUnderlyingGenericTypeMethod());
}

public static TheoryData<MethodInfo> DifferentMethodsSignatures =>
new(typeof(NonGenericResourceController).GetMethods()
.Where(s =>
{
return s.Name == nameof(NonGenericResourceController.DifferentMethodsSignatures);
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GenericControllers.Controllers
{
[Route("{tennantId}/orders")]
[Route("{tenantId}/orders")]
public class OrdersController : GenericResourceController<Order>
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GenericControllers.Controllers
{
[Route("{tennantId}/products")]
[Route("{tenantId}/products")]
public class ProductsController : GenericResourceController<Product>
{ }

Expand Down