-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
TagActionsBy custom tag or controller name #467
Comments
There's a built-in SwaggerOperationAttribute that should allow you override the default tags for any given action |
Thanks for the reply @domaindrivendev. My understanding is that the SwaggerOperationAttribute can only be applied to actions. I was looking for a way to do it at the controller level. Is there an equivalent attribute that I can put onto the controller? |
I was hoping to use the |
For reference, I am now doing:
|
+1 |
@CumpsD I cann't found operation.Tags in v2.2.0. |
For anyone that needs it, v2.5.0 deprecates some ApiDescription extensions which make the
|
Another option is to use the [ApiExplorerSettings(GroupName = "Group")] on your controllers and then replace the default DocInclusionPredicate and TagActionsBy. Something like this:
|
In the output swagger, Ideally I'd like to do a custom
the |
I'm using 5.0.0-beta and got the following to work:
|
5.0.0-beta now includes an |
@domaindrivendev custom tags and tag descriptions (from controller xml docs) do not play well together. do you have any nice workaround in mind where I can link a custom tag to a controller's description? |
By default Tags array in json output of swashbuckle is made by XmlCommentsDocumentFilter. For changing this behavior is there any way to disable this filter and user our own filter instead? |
@enriquecorp Tags attribute works great, but how can I add a description for that tag? |
@apetrut and others - my linked PR fixes the issue where tags created using TagsAttribute do not play well with the description pulled from the controller XML docs, please let me know if this would be useful :) |
This solution just worked for me. Adapted from: https://stackoverflow.com/a/65067565/670028 Step 1: Add controller convention class /// <summary>
/// Uses the [DisplayName] attribute as the Controller name in OpenAPI spec and Swagger/ReDoc UI if available else the default Controller name.
/// </summary>
public class ControllerDocumentationConvention : IControllerModelConvention
{
void IControllerModelConvention.Apply(ControllerModel controller)
{
if (controller == null)
{
return;
}
foreach (var attribute in controller.Attributes)
{
if (attribute is DisplayNameAttribute displayNameAttribute && !string.IsNullOrWhiteSpace(displayNameAttribute.DisplayName))
{
controller.ControllerName = displayNameAttribute.DisplayName;
}
}
}
} Step 2: Add convention to startup services.AddControllers(o =>
{
o.Conventions.Add(new ControllerDocumentationConvention());
}); Step 3: Add |
@randyburden did a good solution but if you use tags you can do it
But there is one trouble - your api has changed. So, we are waiting for |
I looked at commit 2565 and wrote such class in my code.
|
Hi,
I was looking for a solution where I could group the actions of one or more controllers under a custom tag. I did a bit of searching round and found this section in the documentation. I dug into it and managed to produce a solution where I assign a custom attribute to controller(s) that I want to be tagged together. I then created an extension method for the ApiDescription class that will either extract the name in my custom attribute or use the name of the controller if the attribute is not present. This has worked, however, it was a little painful getting the name of the controller when my attribute was not present. I ended up having to duplicate some of the code in the ApiDescriptionExtensions class. Ideally, I would have just used the
ControllerName
extension method but this has been marked as internal.I have two questions:
ControllerName
extension method is marked as internal? If not, would it be possible to make it public?Here is the code that I have produced to achieve this.
The text was updated successfully, but these errors were encountered: