using NSwag.Generation.Processors; using NSwag.Generation.Processors.Contexts; namespace GB5Shared.Swagger; /// /// Drops every operation whose owning module (stashed in ExtensionData by /// under ) doesn't match /// this document's target module. Registered as the last OperationProcessor on a per-module /// SwaggerDocument() so that document ends up containing only that module's endpoints - covers /// FastEndpoints AND MVC/Dapr-controller-sourced operations alike, since both get tagged by /// ModuleTagProcessor through the same NSwag operation pipeline before this runs. This is what makes /// /ads/GB5Documentation show only Admin instead of every module bundled into the same consolidated /// Host process. /// /// Checks ExtensionData rather than Operation.Tags - ModuleTagProcessor sets the visible tag to /// "{Module}.{Feature}" (e.g. "MM.BOM") for Swagger UI's own per-feature grouping, so the plain /// module name is no longer present as a tag to match against directly. /// public sealed class ModuleScopedProcessor : IOperationProcessor { private readonly string _moduleName; public ModuleScopedProcessor(string moduleName) { _moduleName = moduleName; } public bool Process(OperationProcessorContext context) { var extensionData = context.OperationDescription.Operation.ExtensionData; return extensionData is not null && extensionData.TryGetValue(ModuleTagProcessor.ModuleKey, out var owningModule) && string.Equals(owningModule as string, _moduleName, StringComparison.OrdinalIgnoreCase); } }