Skip to content

AddVersionedApiExplorer duplicates APIs when inheriting from base controller  #229

Closed
@sabmah

Description

@sabmah

I have a following code

public class BaseController : ApiController{}

 [ApiVersion("1")]
 [RoutePrefix("api/v{version:apiversion}/myresource")]
 public class MyController: BaseController{

    [Route("")]
    public async Task<IHttpActionResult> GetUsers()
    {
        var users = await _userRepository.GetAllUsersAsync();
        return Ok(users);
    }
}

In WebConfig.cs , I have

      config.AddApiVersioning(opt =>
            {
                opt.ReportApiVersions = true;
                opt.AssumeDefaultVersionWhenUnspecified = true;
                opt.ApiVersionSelector = new CurrentImplementationApiVersionSelector(opt);
            }
        );

config.AddVersionedApiExplorer()

When I go to my Help Page, I see duplicates:
GET api/v{version:apiversion}/myresource
GET api/v{version:apiversion}/myresource

But when I remove the Base Controller and just inherit directly ApiController to "MyController", I don't see the duplicates.

Is there a problem with inheriting ?

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions