Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude particular Web Api endpoint from the swagger UI

I'm using Swagger UI with asp.net core web api. For my CRUD operations, I have a base controller class, which defines abstract methods:

public class BaseController<TDto, TEntity>
{
    [HttpPost, Route("create-single")]
    public abstract Task<ObjectResult> CreateAsync(TDto input);

    [HttpPost, Route("create-many")]
    public abstract Task<ObjectResult> CreateManyAsync(IList<TDto> input);

    [HttpGet, Route("get-all")]
    public abstract Task<ObjectResult> GetAllAsync();

    [HttpGet, Route("get/{id}")]
    public abstract Task<ObjectResult> GetByIdAsync(Guid id);

    ...
    ...
}

Some controller might not need all the CRUD methods, and I need to disappear those endpoints from the swagger.

For example, I need to disappear /get/{id} endpoint for particular controller, what is the best way to achieve this?

like image 225
Arkadi Avatar asked Feb 04 '26 19:02

Arkadi


1 Answers

You can add the following attribute to Controllers and Actions to exclude them from the generated documentation: [ApiExplorerSettings(IgnoreApi = true)]

like image 186
Ajay Gupta Avatar answered Feb 07 '26 09:02

Ajay Gupta



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!