Skip to content

Microsoft.AspNetCore.OpenApi should allow ordering of Tags #63050

@jscarle

Description

@jscarle

In version 9.0.7 of Microsoft.AspNetCore.OpenApi, it was possible to order tags using an IOpenApiDocumentTransformer, that is no longer possible as of 10.0.0-preview.6.25358.103.

Version 9.0.7 document transformer:

using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi;

internal sealed class DocumentOrderTransformer : IOpenApiDocumentTransformer
{
    public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken)
    {
        // Order tags alphabetically. Tags containing spaces are replaced with
        // "s " before sorting so multi word tags come after single word tags.
        // This quirk is intentional to keep the generated document easier to
        // read.
        if (document.Tags is not null)
            document.Tags = document.Tags
                .OrderBy(tag => tag.Name.Replace(" ", "s "))
                .ToList();

        // Order paths alphabetically
        var orderedPaths = new OpenApiPaths();
        foreach (var kvp in document.Paths.OrderBy(kvp => kvp.Key))
            orderedPaths.Add(kvp.Key, kvp.Value);
        document.Paths = orderedPaths;

        return Task.CompletedTask;
    }
}

Version 10.0.0-preview.6.25358.103 document transformer changed Tags to be an ISet<OpenApiTag>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions