Skip to content

Commit 982ad22

Browse files
Fix: OpenAPI attributes are not getting picked up if they are in a referenced class library project #298 (#301)
1 parent f8639d0 commit 982ad22

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/Microsoft.Azure.Functions.Worker.Extensions.OpenApi/Extensions/DocumentHelperExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Reflection;

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Extensions/AssemblyExtensions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Linq;
33
using System.Reflection;
44

@@ -10,15 +10,23 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
1010
public static class AssemblyExtensions
1111
{
1212
/// <summary>
13-
/// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others.
13+
/// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others (includes referenced assemblies).
1414
/// </summary>
1515
/// <param name="assembly"><see cref="Assembly"/> instance.</param>
1616
/// <returns>Returns the list of <see cref="Type"/>s that can be loaded.</returns>
1717
public static Type[] GetLoadableTypes(this Assembly assembly)
1818
{
1919
try
2020
{
21-
return assembly.GetTypes();
21+
return assembly.GetTypes()
22+
.Union(assembly
23+
.GetReferencedAssemblies()
24+
.Where(x =>
25+
!x.FullName.StartsWith("Microsoft.Azure.WebJobs.Extensions.OpenApi") &&
26+
!x.FullName.StartsWith("Microsoft.Azure.Functions.Worker.Extensions.OpenApi"))
27+
.SelectMany(x => Assembly.Load(x).GetTypes()))
28+
.Distinct()
29+
.ToArray();
2230
}
2331
catch (ReflectionTypeLoadException exception)
2432
{

src/Microsoft.Azure.WebJobs.Extensions.OpenApi.Core/Visitors/VisitorCollection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static VisitorCollection CreateInstance()
4949
var collection = new VisitorCollection();
5050
collection.Visitors = typeof(IVisitor).Assembly
5151
.GetLoadableTypes()
52-
.Where(p => p.Name.EndsWith("Visitor") && p.IsClass && !p.IsAbstract)
52+
.Where(p => p.HasInterface<IVisitor>() && p.IsClass && !p.IsAbstract)
5353
.Select(p => (IVisitor)Activator.CreateInstance(p, collection)).ToList(); // NOTE: there is no direct enforcement on the constructor arguments of the visitors
5454
return collection;
5555
}

0 commit comments

Comments
 (0)