Mvc: ApiExplorer: ApiDescriptionGroup.GroupName is always empty

Created on 21 Jun 2018  路  7Comments  路  Source: aspnet/Mvc

I'm using IApiDescriptionGroupCollectionProvider to get information about the API. But ApiDescriptionGroup.GroupName is always empty when iterating over group collection.

According to this post https://andrewlock.net/introduction-to-the-apiexplorer-in-asp-net-core/ it is supposed to return controller name?

Now because this doesn't work I have to group all the ApiDescriptions by controller manually.

All 7 comments

It's controlled by the GroupName property on ApiExplorerSettingsAttribute. If you look at the blog post, the value is explicitly set using the attribute:

[Route("api/[controller]")]
[ApiExplorerSettings(IgnoreApi = false, GroupName = nameof(ValuesController))]
public class ValuesController : Controller  

@glennc \ @rynowak we could consider defaulting this to a prettified controller name for ApiController instances with an ApiBehaviorOption to suppress it.
@tuespetre does something similar in https://github.com/aspnet/Mvc/issues/5179.

I think want need to understand why that's important 馃槅 What do the swagger frameworks use it for?

It's supposed to translate in to tags which you could then logically group operations by - https://swagger.io/docs/specification/2-0/grouping-operations-with-tags. Although scanning the code, it doesn't look like think either NSwag or Swashbuckle uses this property today.

But group name is a single thing - not a set of tags. We also intended it to be used for things like versioning.

Right. My suggestion was for consumers to use it as a tag value when available.

We also intended it to be used for things like versioning.

Ok. I guess we can solve exposing the notion of ApiDescription.Tags independent of this (and nobody's clamored for it as yet).

Closing for now until we figure out how this field needs to play with versioning and \ or tags. @lecoque for the time being, I'd recommend using the ApiExplorerSettingsAttribute to set it. Alternatively, you could consider an application model convention to do this for all controllers. https://github.com/aspnet/Mvc/issues/5179 has an example of setting this up.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

janpieterz picture janpieterz  路  43Comments

sk29110 picture sk29110  路  33Comments

xaviergxf picture xaviergxf  路  35Comments

mdmoura picture mdmoura  路  33Comments

dougbu picture dougbu  路  54Comments