From b4c1d2788ce09ae02d61292ea775919eb2d34f5b Mon Sep 17 00:00:00 2001 From: Mike Kistler Date: Thu, 3 Oct 2024 07:51:56 -0500 Subject: [PATCH] Add doc on excluding endpoints in controller-based apps --- .../openapi/aspnetcore-openapi.md | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md b/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md index fbedc9008b..d1c8b99a4e 100644 --- a/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md +++ b/aspnetcore/fundamentals/openapi/aspnetcore-openapi.md @@ -328,9 +328,14 @@ If an endpoint can return different response types in different scenarios, you c #### Excluding endpoints from the generated document - +By default, all endpoints that are defined in an app are documented in the generated OpenAPI file, +but endpoints can be excluded from the document using attributes or extension methods. -By default, all endpoints that are defined in an app are documented in the generated OpenAPI file. Minimal APIs support two strategies for excluding a given endpoint from the OpenAPI document, using: +The mechanism for specifying an endpoint should be excluded depends on the type of app being developed. + +##### [Minimal APIs](#tab/minimal-apis) + +Minimal APIs support two strategies for excluding a given endpoint from the OpenAPI document, using: * * @@ -346,6 +351,21 @@ app.MapGet("/attributes", () => "Hello world!"); ``` +##### [Controllers](#tab/controllers) + +In controller-based apps, the attribute can be used to exclude an endpoint from the OpenAPI document. + +The following example demonstrates how to exclude an endpoint from the generated OpenAPI document. + +```csharp + [HttpGet("/private")] + [ApiExplorerSettings(IgnoreApi = true)] + public IActionResult PrivateEndpoint() { + return Ok("This is a private endpoint"); + } +``` +--- + ### Including OpenAPI metadata for data types C# classes or records used in request or response bodies are represented as schemas