Skip to content

Commit

Permalink
OpenAPI attributes are not getting picked up if they are in a referen…
Browse files Browse the repository at this point in the history
…ced class library project #298
  • Loading branch information
PanosKousidis authored and Panos Kousidis committed Nov 1, 2021
1 parent 4ab63c2 commit f673fbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -30,7 +30,7 @@ public static class DocumentHelperExtensions
/// <returns>List of <see cref="MethodInfo"/> instances representing HTTP triggers.</returns>
public static List<MethodInfo> GetHttpTriggerMethods(this IDocumentHelper helper, Assembly assembly, IEnumerable<string> tags = null)
{
var methods = assembly.GetLoadableTypes()
var methods = assembly.GetLoadableTypes(includeReferenced: true)
.SelectMany(p => p.GetMethods())
.Where(p => p.ExistsCustomAttribute<FunctionAttribute>())
.Where(p => p.ExistsCustomAttribute<OpenApiOperationAttribute>())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using System.Reflection;

Expand All @@ -13,12 +13,20 @@ public static class AssemblyExtensions
/// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others.
/// </summary>
/// <param name="assembly"><see cref="Assembly"/> instance.</param>
/// <param name="includeReferenced">Set to true to load <see cref="Type"/>s from referenced assemblies too</param>
/// <returns>Returns the list of <see cref="Type"/>s that can be loaded.</returns>
public static Type[] GetLoadableTypes(this Assembly assembly)
public static Type[] GetLoadableTypes(this Assembly assembly, bool includeReferenced = false)
{
try
{
return assembly.GetTypes();
return includeReferenced
? assembly.GetTypes()
.Union(assembly
.GetReferencedAssemblies()
.SelectMany(x => Assembly.Load(x).GetTypes()))
.Distinct()
.ToArray()
: assembly.GetTypes();
}
catch (ReflectionTypeLoadException exception)
{
Expand Down

0 comments on commit f673fbe

Please sign in to comment.