-
Notifications
You must be signed in to change notification settings - Fork 709
AddVersionedApiExplorer duplicates APIs when inheriting from base controller #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Honestly, it's been a very long time since I've used the Help Pages since most have switched to Swagger. The API Explorer for API versioning uses the same discovery process as routing. If things route the way you expect, then there is likely not an issue with inheritance. How are you building your help page? While it is possible, it's much harder to use the IApiExplorer interface directly because its design has no support for API versioning. The VersionedApiExplorer does implement this interface, but the ApiDescription items are reported in a flat list, which is all that IApiExplorer supports. I recommend using the VersionedApiExplorer directly instead. You can achieve this by capturing the reference when it's added or cast it from the registered instance. // capture during registration
var apiExplorer = configuration.AddVersionedApiExplorer();
// cast from registered instance
apiExplorer = (VersionedApiExplorer) configuration.Services.GetApiExplorer(); Once you have an reference to the strongly-typed VersionedApiExplorer instance, the
When you use IApiExplorer directly, the list is flat, which has the appearance of duplicates. The entries are not actually duplicates, but are identical route templates for different API versions. You should be able to confirm that through the debugger display. It's possible to cast the individual ApiDescription entries to their VersionedApiDescription equivalent, which will contain the API version and group information as well. One final note. Remember that when you version by URL segment the API version is a route parameter value with a constraint. The API Explorer is not going to fill in or translate the URL for you. It will, however, include a parameter that defaults to the expected value. If you want the URLs to be pre-generated, you'll have to add your own code to perform the replacement. The behavior is no different than if the route was I hope that helps. Let me know if you have more questions. |
It makes sense if I have multiple versions like you said (1.0 and 2.0). I only have 1 version. |
API descriptions are de-duplicated by ID and API version. |
Hmmm.... seems like there might be a problem. I was able to repro your scenario in the Web API Swagger sample. The issue seems to be evaluation of the API version itself. I think there may be a bug here. I need to investigate further. To unblock you though, try changing your attribute from Try that and hopefully you'll be unblocked. I'll continue investigating. Thanks. |
Thanks. We removed the inheritance for now but your solution is an alternative that we can use too. Thanks for looking into it |
Uggg ... it's a bug. The fix is pretty simple, but I'm amazed no one else has neither hit this error or reported it. Nevertheless, the behavior is wrong. I have several fixes I'm working on. I will roll this into it and push it out as soon as possible. I'm advertising the end of next week, but there is a good chance it will be much sooner than that. I tried the inheritance combination and that worked just fine. If BaseController doesn't provide a public API surface, consider making it abstract. That should guarantee it's excluded from the results. As a workaround, you can use |
I have a following code
In WebConfig.cs , I have
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 ?
The text was updated successfully, but these errors were encountered: