{"record":{"id":"5e7491a7e8a4c279","repo":"RicoSuter/NSwag","slug":"globalscopenames","errorCode":null,"errorMessage":"globalScopeNames","messagePattern":"globalScopeNames","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/NSwag.Generation/Processors/Security/SecurityDefinitionAppender.cs","lineNumber":36,"sourceCode":"        private readonly OpenApiSecurityScheme _swaggerSecurityScheme;\n\n        /// <summary>Initializes a new instance of the <see cref=\"SecurityDefinitionAppender\" /> class where the security requirement must be manually added.</summary>\n        /// <param name=\"name\">The name/key of the security scheme/definition.</param>\n        /// <param name=\"swaggerSecurityScheme\">The Swagger security scheme.</param>\n        public SecurityDefinitionAppender(string name, OpenApiSecurityScheme swaggerSecurityScheme)\n        {\n            _name = name;\n            _swaggerSecurityScheme = swaggerSecurityScheme;\n        }\n\n        /// <summary>Initializes a new instance of the <see cref=\"SecurityDefinitionAppender\" /> class.</summary>\n        /// <param name=\"name\">The name/key of the security scheme/definition.</param>\n        /// <param name=\"globalScopeNames\">The global scope names to add to as security requirement with the scheme name in the document's 'security' property (can be an empty list).</param>\n        /// <param name=\"swaggerSecurityScheme\">The Swagger security scheme.</param>\n        public SecurityDefinitionAppender(string name, IEnumerable<string> globalScopeNames, OpenApiSecurityScheme swaggerSecurityScheme)\n        {\n            _name = name;\n            _scopeNames = globalScopeNames ?? throw new ArgumentNullException(nameof(globalScopeNames));\n            _swaggerSecurityScheme = swaggerSecurityScheme;\n        }\n\n        /// <summary>Processes the specified Swagger document.</summary>\n        /// <param name=\"context\"></param>\n        public void Process(DocumentProcessorContext context)\n        {\n            context.Document.SecurityDefinitions[_name] = _swaggerSecurityScheme;\n\n            if (_scopeNames != null)\n            {\n                if (context.Document.Security == null)\n                {\n                    context.Document.Security = [];\n                }\n\n                context.Document.Security.Add(new OpenApiSecurityRequirement\n                {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.Generation/Processors/Security/SecurityDefinitionAppender.cs#L18-L54","documentation":"The SecurityDefinitionAppender constructor throws ArgumentNullException when globalScopeNames is null. The scope name list is stored directly as the security requirement's scope names, so a null sequence is rejected even though an empty list is allowed.","triggerScenarios":"Constructing SecurityDefinitionAppender(name, null, securityScheme) — typically when the scope list comes from configuration that was not populated.","commonSituations":"Adding OAuth2/API-key security definitions in a document processor pipeline where global scopes come from appsettings that are missing or null at that point.","solutions":["Pass an empty array instead of null when there are no global scopes","Initialize the scope list from config with a null-coalescing default","Validate config before constructing the appender"],"exampleFix":"// before\nnew SecurityDefinitionAppender(\"oauth2\", config.Scopes, scheme);\n// after\nnew SecurityDefinitionAppender(\"oauth2\", config.Scopes ?? Array.Empty<string>(), scheme);","handlingStrategy":"validation","validationCode":"var scopes = globalScopeNames ?? Array.Empty<string>();\nnew SecurityDefinitionAppender(name, scopes, scheme);","typeGuard":"bool canAppend = globalScopeNames is not null;","tryCatchPattern":null,"preventionTips":["Default optional scope lists to empty collections, never null","Validate security configuration sections before building document processors"],"tags":["nswag","null-argument","security","constructor"],"backgroundTag":"null-argument","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"}