How would you exclude specific endpoints or entire controllers from appearing in the generated Swagger documentation?
Short answer
The [ApiExplorerSettings(IgnoreApi = true)] attribute excludes a specific controller or action from Swagger generation, while minimal API endpoints use .ExcludeFromDescription() -- useful for internal-only diagnostic endpoints, deprecated routes not yet removed, or endpoints…
Advertisement
AModel answer
The [ApiExplorerSettings(IgnoreApi = true)] attribute excludes a specific controller or action from Swagger generation, while minimal API endpoints use .ExcludeFromDescription() -- useful for internal-only diagnostic endpoints, deprecated routes not yet removed, or endpoints intentionally undocumented for external consumers while still functioning.
[ApiExplorerSettings(IgnoreApi = true)]
[HttpGet("internal/debug-info")]
public IActionResult DebugInfo() { ... }
// Minimal API equivalent
app.MapGet("/internal/debug-info", () => { ... }).ExcludeFromDescription();Real-world example
An internal diagnostics endpoint used only by the operations team for troubleshooting is deliberately excluded from the public-facing Swagger documentation using ExcludeFromDescription, keeping the published API contract focused on genuinely supported public functionality.
Likely follow-ups
- What's the risk of an undocumented endpoint still being discoverable and callable by anyone?
- How does this differ from actually restricting access via authorization?
Related topics