Skip to content
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

Root tags object not showing #2530

Open
greg-signi opened this issue Oct 31, 2022 · 6 comments
Open

Root tags object not showing #2530

greg-signi opened this issue Oct 31, 2022 · 6 comments

Comments

@greg-signi
Copy link

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 ?

@domaindrivendev
Copy link
Owner

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

@domaindrivendev domaindrivendev added the responded Responded with solution or request for more info label Nov 15, 2022
@greg-signi
Copy link
Author

greg-signi commented Nov 16, 2022

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 ?

@yingxinj
Copy link

Hello, please see the linked PR #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?

@personball
Copy link

personball commented Jul 26, 2023

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();
    }
}

Copy link
Contributor

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 github-actions bot added the stale Stale issues or pull requests label Apr 15, 2024
@martincostello
Copy link
Collaborator

#2565 (comment)

@martincostello martincostello removed responded Responded with solution or request for more info stale Stale issues or pull requests labels Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants