Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

Root tags object not showing

Open greg-signi opened this issue 1 year ago • 6 comments

I set the attribute [Tags("...")] in the Controler and despite having my openapi.json object with tags under the designated methods, eg:

"paths": { "/sessions": { "post": { "tags": [ "Authentication Session" ], "summary": "Create a session",

The root object tags is not created. Any idea what's missing ?

greg-signi avatar Oct 31 '22 13:10 greg-signi

I'm not familiar with the TagsAttribute you're referring to. Could you please provide more info (sample code, expected output etc.).

domaindrivendev avatar Nov 15 '22 23:11 domaindrivendev

Hello, either the [Tags("Session")] from Microsoft.AspNetCore.Http or [SwaggerOperation(Tags = new[] { "Session" }] from Swashbuckle.Swagger.Annotations

And they work in some instance since they are able to get appended to the method information "paths": { "/sessions": { "post": { "tags": [ "Session" ], "summary": "Create a session",

But the array tags at the root level object, that encompasses all the tags available in the api, remains empty. I did a workaround where I create a IDocumentFilter and fill the array swaggerDoc.Tags by hand.. But I shouldn't have to do this right ?

greg-signi avatar Nov 16 '22 11:11 greg-signi

Hello, please see the linked PR https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/2565 that adds support for the TagsAttribute - let me know if this would be helpful for resolving your issue, or if you had a different approach to implementing a workaround @greg-signi?

yingxinj avatar Dec 19 '22 15:12 yingxinj

Hi, any update for ” the array tags at the root level object, that encompasses all the tags available in the api, remains empty“ ?

Solved with:

using System.Linq;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
public class SwaggerTagsFilter : IDocumentFilter
{
    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
    {
        swaggerDoc.Tags = swaggerDoc.Paths.SelectMany(p => p.Value.Operations)
                            .SelectMany(o => o.Value.Tags)
                            .Select(t => t.Name)
                            .Where(g => !string.IsNullOrWhiteSpace(g))
                            .Select(name => new OpenApiTag { Name = name })
                            .ToList();
    }
}

personball avatar Jul 26 '23 01:07 personball

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

github-actions[bot] avatar Apr 15 '24 02:04 github-actions[bot]

https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/2565#issuecomment-2053577323

martincostello avatar Apr 15 '24 05:04 martincostello

This issue is stale because it has been open for 60 days with no activity. It will be automatically closed in 14 days if no further updates are made.

github-actions[bot] avatar Jun 15 '24 01:06 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 02 '24 01:07 github-actions[bot]