Exclude particular Web Api endpoint from the swagger UI

Viewed 1884

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?

1 Answers

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

Related