Skip to content

Commit

Permalink
Merge pull request #33773 from dotnet/mdk/openapi-excluding
Browse files Browse the repository at this point in the history
Add doc on excluding endpoints in controller-based apps
  • Loading branch information
mikekistler authored Oct 5, 2024
2 parents 6617b50 + 31faf40 commit cdd29d0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions aspnetcore/fundamentals/openapi/aspnetcore-openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@ If an endpoint can return different response types in different scenarios, you c

#### Excluding endpoints from the generated document

<!-- TODO: Add information for controller-based apps in this section -->
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 that 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:

* <xref:Microsoft.AspNetCore.Http.OpenApiRouteHandlerBuilderExtensions.ExcludeFromDescription%2A>
* <xref:Microsoft.AspNetCore.Routing.ExcludeFromDescriptionAttribute>
Expand All @@ -346,6 +350,21 @@ app.MapGet("/attributes",
() => "Hello world!");
```

##### [Controllers](#tab/controllers)

In controller-based apps, the <xref:Microsoft.AspNetCore.Mvc.ApiExplorerSettingsAttribute> attribute can be used to exclude an endpoint or all endpoints in a controller class 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
Expand Down

0 comments on commit cdd29d0

Please sign in to comment.