{"record":{"id":"90fb1c93dc7e7be4","repo":"RicoSuter/NSwag","slug":"some-operations-are-both-in-included-and-excluded-operation","errorCode":null,"errorMessage":"Some operations are both in included and excluded operation IDs ({operationsBothIncludedAndExcluded}).","messagePattern":"Some operations are both in included and excluded operation IDs \\((.+?)\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.CodeGeneration/ClientGeneratorBase.cs","lineNumber":166,"sourceCode":"        /// <param name=\"operation\">The operation.</param>\n        /// <param name=\"settings\">The settings.</param>\n        /// <returns>The operation model.</returns>\n        protected abstract TOperationModel CreateOperationModel(OpenApiOperation operation,\n            ClientGeneratorBaseSettings settings);\n\n        private static readonly char[] pathTrimChars = ['/'];\n\n        private List<TOperationModel> GetOperations(OpenApiDocument document)\n        {\n            document.GenerateOperationIds();\n\n            HashSet<string> operationsToInclude = [..BaseSettings.IncludedOperationIds ?? []];\n            HashSet<string> operationsToExclude = [.. BaseSettings.ExcludedOperationIds ?? []];\n\n            IEnumerable<string> operationsBothIncludedAndExcluded = operationsToInclude.Intersect(operationsToExclude);\n            if (operationsBothIncludedAndExcluded.Any())\n            {\n                throw new InvalidOperationException(\n                    $\"Some operations are both in included and excluded operation IDs ({string.Join(\", \", operationsBothIncludedAndExcluded)}).\"\n                    );\n            }\n\n            var result = new List<TOperationModel>();\n            foreach (var pair in document.Paths)\n            {\n                foreach (var p in pair.Value.ActualPathItem)\n                {\n                    var operation = p.Value;\n \n                    if ((operationsToInclude.Count is not 0 && !operationsToInclude.Contains(operation.OperationId))\n                        ||\n                        (operationsToExclude.Count is not 0 && operationsToExclude.Contains(operation.OperationId))\n                        )\n                    {\n                        continue;\n                    }","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.CodeGeneration/ClientGeneratorBase.cs#L148-L184","documentation":"When generating a client, NSwag filters operations by IncludedOperationIds and ExcludedOperationIds (usually via x-operation-id and SwaggerOperation attributes). GetOperations throws InvalidOperationException if any operation ID appears in both sets, since inclusion and exclusion are mutually exclusive filters.","triggerScenarios":"Setting config.IncludedOperationIds = [\"Op1\"] and config.ExcludedOperationIds = [\"Op1\"] (overlapping sets) on generator/client settings before calling GenerateAsync or nswag codegen.","commonSituations":"Building include/exclude lists programmatically from overlapping selectors (e.g. excluding by tag while including by ID); config files where one operation was added to both lists over time.","solutions":["Remove the conflicting operation IDs from ExcludedOperationIds (or IncludedOperationIds) so the sets do not intersect.","Compute ExcludedOperationIds as allIds.Except(IncludedOperationIds) when deriving one list from the other.","Verify operation IDs in attributes (SwaggerOperation) match exactly one list, not both."],"exampleFix":"// before\nsettings.IncludedOperationIds = new[] { \"GetUser\", \"CreateUser\" };\nsettings.ExcludedOperationIds = new[] { \"CreateUser\" };\n// after\nsettings.IncludedOperationIds = new[] { \"GetUser\", \"CreateUser\" };\nsettings.ExcludedOperationIds = new[] { \"DeleteUser\" };","handlingStrategy":"validation","validationCode":"var overlap = settings.IncludedOperationIds?.Intersect(settings.ExcludedOperationIds ?? Enumerable.Empty<string>()).ToList();\nif (overlap?.Any() == true) throw new ArgumentException($\"Operation IDs both included and excluded: {string.Join(\\\",\\\", overlap)}\");","typeGuard":"bool NoIncludeExcludeOverlap(ISystem.Collections.Generic.IEnumerable<string> inc, IEnumerable<string> exc) => !(inc ?? []).Intersect(exc ?? []).Any();","tryCatchPattern":"try { var code = generator.Generate(file); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"included and excluded operation IDs\")) { logger.LogError(ex, \"Fix IncludedOperationIds/ExcludedOperationIds overlap\"); throw; }","preventionTips":["Derive ExcludedOperationIds programmatically as allOperationIds.Except(IncludedOperationIds) instead of hand-maintaining both.","Grep generated config for an operation ID appearing in both arrays before running codegen.","Validate include/exclude lists in CI before invoking the generator."],"tags":["code-generation","configuration","operation-ids","nswag"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"63daf8fcc3a25151b62eb4b326a1e8ea048a0d41","analyzedAt":"2026-09-14T11:38:15.205Z","contentChangedAt":"2026-09-14T11:38:15.205Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}