{"record":{"id":"3e12da3e0d64e542","repo":"RicoSuter/NSwag","slug":"no-registered-openapi-swagger-document-found-for-the","errorCode":null,"errorMessage":"No registered OpenAPI/Swagger document found for the document name '{documentName}'. Add with the AddSwagger()/AddOpenApi() methods in ConfigureServices().","messagePattern":"No registered OpenAPI/Swagger document found for the document name '(.+?)'\\. Add with the AddSwagger\\(\\)/AddOpenApi\\(\\) methods in ConfigureServices\\(\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/NSwag.AspNetCore/OpenApiDocumentProvider.cs","lineNumber":48,"sourceCode":"            {\n                throw new ArgumentNullException(nameof(documentName));\n            }\n\n            foreach (var group in _documents.GroupBy(g => g.DocumentName))\n            {\n                if (group.Count() > 1)\n                {\n                    throw new ArgumentException(\"The OpenAPI/Swagger document '\" + group.Key + \"' registered multiple times: \" +\n                        \"Explicitly set the DocumentName property in \" +\n                        nameof(NSwagServiceCollectionExtensions.AddSwaggerDocument) + \"() or \" +\n                        nameof(NSwagServiceCollectionExtensions.AddOpenApiDocument) + \"().\");\n                }\n            }\n\n            var document = _documents.SingleOrDefault(g => g.DocumentName == documentName);\n            if (document?.Settings == null)\n            {\n                throw new InvalidOperationException($\"No registered OpenAPI/Swagger document found for the document name '{documentName}'. \" +\n                    $\"Add with the AddSwagger()/AddOpenApi() methods in ConfigureServices().\");\n            }\n\n            var generator = new AspNetCoreOpenApiDocumentGenerator(document?.Settings);\n            return generator.GenerateAsync(_serviceProvider);\n        }\n\n        // Called by the <c>dotnet-getdocument</c> tool from the Microsoft.Extensions.ApiDescription.Server package.\n        IEnumerable<string> IDocumentProvider.GetDocumentNames()\n        {\n            // DocumentName may be null. But, if it is, cannot generate the registered document.\n            return _documents\n                .Where(document => document.DocumentName != null)\n                .Select(document => document.DocumentName);\n        }\n\n        // Called by the <c>dotnet-getdocument</c> tool from the Microsoft.Extensions.ApiDescription.Server package.\n        async Task IDocumentProvider.GenerateAsync(string documentName, TextWriter writer)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/RicoSuter/NSwag/blob/63daf8fcc3a25151b62eb4b326a1e8ea048a0d41/src/NSwag.AspNetCore/OpenApiDocumentProvider.cs#L30-L66","documentation":"GenerateAsync looks up the registered document settings by documentName and throws InvalidOperationException when no registration matches (or its settings are null). The request document name must exactly match a DocumentName registered via AddOpenApiDocument/AddSwaggerDocument.","triggerScenarios":"Requesting /swagger/{name}/swagger.json where {name} does not match any registered DocumentName (case-sensitive), or code calling GenerateAsync(\"wrongName\") directly; also registering zero documents.","commonSituations":"Typo or casing mismatch in the URL; renaming DocumentName after upgrading; adding UseOpenApi with a documentName parameter that differs from the registered one; forgetting AddOpenApiDocument entirely.","solutions":["Ensure a document with the exact DocumentName is registered via AddOpenApiDocument/AddSwaggerDocument.","Fix the document name in the request URL or UseOpenApi(o => o.DocumentName = ...) to match the registration (names are case-sensitive).","Check for renamed documents after refactoring or upgrading NSwag."],"exampleFix":"// before\napp.UseOpenApi(o => o.DocumentName = \"api\");\nservices.AddOpenApiDocument(c => c.DocumentName = \"v1\");\n// after\napp.UseOpenApi(o => o.DocumentName = \"v1\");\nservices.AddOpenApiDocument(c => c.DocumentName = \"v1\");","handlingStrategy":"validation","validationCode":"var registered = new HashSet<string>(StringComparer.Ordinal) { \"v1\", \"v2\" };\nif (!registered.Contains(requestedDocumentName)) throw new ArgumentException($\"Unknown document '{requestedDocumentName}'. Registered: {string.Join(\",\", registered)}\");","typeGuard":"bool IsKnownDocument(string name, IEnumerable<string> registered) => registered.Contains(name, StringComparer.Ordinal);","tryCatchPattern":"try { var doc = await GenerateAsync(documentName); }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"No registered OpenAPI/Swagger document\")) { logger.LogWarning(\"Unknown document name {Name}\", documentName); }","preventionTips":["Keep a single constant list of document names shared between registrations and any code that requests them.","Remember document names are case-sensitive; compare with the exact registered value.","After renaming a document, update UseOpenApi/UseSwaggerUi DocumentName and all client-generation references."],"tags":["resource-not-found","configuration","aspnetcore","nswag"],"backgroundTag":"record-not-found","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"}