Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: OpenAPI attributes are not getting picked up if they are in a referenced class library project #298 #301

Merged
merged 6 commits into from
Feb 9, 2022
Merged
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
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 @@ -10,15 +10,23 @@ namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions
public static class AssemblyExtensions
{
/// <summary>
/// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others.
/// Loads the <see cref="Assembly"/>'s <see cref="Type"/>s that can be loaded ignoring others (includes referenced assemblies).
/// </summary>
/// <param name="assembly"><see cref="Assembly"/> instance.</param>
/// <returns>Returns the list of <see cref="Type"/>s that can be loaded.</returns>
public static Type[] GetLoadableTypes(this Assembly assembly)
{
try
{
return assembly.GetTypes();
return assembly.GetTypes()
.Union(assembly
.GetReferencedAssemblies()
.Where(x =>
!x.FullName.StartsWith("Microsoft.Azure.WebJobs.Extensions.OpenApi") &&
!x.FullName.StartsWith("Microsoft.Azure.Functions.Worker.Extensions.OpenApi"))
.SelectMany(x => Assembly.Load(x).GetTypes()))
.Distinct()
.ToArray();
}
catch (ReflectionTypeLoadException exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static VisitorCollection CreateInstance()
var collection = new VisitorCollection();
collection.Visitors = typeof(IVisitor).Assembly
.GetLoadableTypes()
.Where(p => p.Name.EndsWith("Visitor") && p.IsClass && !p.IsAbstract)
.Where(p => p.HasInterface<IVisitor>() && p.IsClass && !p.IsAbstract)
.Select(p => (IVisitor)Activator.CreateInstance(p, collection)).ToList(); // NOTE: there is no direct enforcement on the constructor arguments of the visitors
return collection;
}
Expand Down