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

Tagging controllers from additional module assemblies #2651

Open
j-mok opened this issue May 5, 2023 · 0 comments
Open

Tagging controllers from additional module assemblies #2651

j-mok opened this issue May 5, 2023 · 0 comments
Assignees

Comments

@j-mok
Copy link
Contributor

j-mok commented May 5, 2023

Problem:
The current logic for controller action tagging in Swagger is to group actions by modules and tag the rest with Platform fallback:

private static IList<string> GroupByModuleName(this ApiDescription api, IServiceCollection services)
{
var providerSnapshot = services.BuildServiceProvider();
var moduleCatalog = providerSnapshot.GetRequiredService<ILocalModuleCatalog>();
// ------
// Lifted from ApiDescriptionExtensions
var actionDescriptor = api.GetProperty<ControllerActionDescriptor>();
if (actionDescriptor == null)
{
actionDescriptor = api.ActionDescriptor as ControllerActionDescriptor;
api.SetProperty(actionDescriptor);
}
// ------
var moduleAssembly = actionDescriptor?.ControllerTypeInfo.Assembly ?? Assembly.GetExecutingAssembly();
var groupName = moduleCatalog.Modules.FirstOrDefault(m => m.ModuleInstance != null && m.Assembly == moduleAssembly);
return new List<string> { groupName != null ? groupName.ModuleName : "Platform" };
}

The problem is that if some or all module controllers are not in the main module assembly (usually the Foo.Web) but in referenced assemblies, then they end up tagged with Platform. That clutters the Platform tag with non-platform controller actions and gives the impression that the module is missing its own actions.

Solution:
Allow additional assemblies to be enumerated in module manifest and then treated as module's own when grouping controller actions. This could look like this:

<module>
    <id>Foo</id>
    <!-- ... -->
    <api>
        <swagger>
            <additionalAssemblies>
                <include>Foo.Web.MoreControllers</include>
                <include>Foo.Web.EvenMoreControllers</include>
            </additionalAssemblies>
        </swagger>
    </api>
</module>

Some assumptions:

  • Assemblies are referenced using their simple names.
  • Entry validation skipped for simplicity.
  • It is the responsibility of module author to include appropriate assemblies, otherwise current behavior applies.
  • The root module assembly is not required to be included in the list (hence addtional) - it is always considered for per-module tagging.

Alternative:
Module assembly dependency graph can be crawled and all found assemblies could be considered for controller action tagging. The downsides are more complex implementation, possibly bigger resource usage and lack of fine control. The upside is that it would work automatically without the need to maintain the manifest.

Proposal of changes:
Implement module manifest extension as described above (or something similar) and modify action grouping accordingly.

Additional context:
It's probably not a frequent requirement, and small, focused modules will not benefit from it. Nonetheless there are sometimes overgrown modules split into multiple assemblies but deployed as a single module that have segregated controllers some of which incorrectly end up in the Platform tag.

@OlegoO OlegoO self-assigned this May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants