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

[Bug]: Operation order is not preserved when @tagMetadata decorator is used #6454

Open
4 tasks done
aelberg opened this issue Mar 14, 2025 · 3 comments
Open
4 tasks done
Labels
design:needed A design request has been raised that needs a proposal lib:openapi triaged:core
Milestone

Comments

@aelberg
Copy link

aelberg commented Mar 14, 2025

Describe the bug

Using the openapi3 emitter version 0.66.0.
When the @tagMetadata is not applied on the namespace the Operations are grouped by their tag in the order defined.
When the @tagMetadata decorator is used the tags are reordered alphabetically and the order of tags is no longer preserved.

Reproduction

Without @tagMetadata

Using @tagMetadata

Checklist

@aelberg aelberg added the bug Something isn't working label Mar 14, 2025
@timotheeguerin
Copy link
Member

you are talking about this field only right?

with @tagMetadata

tags:
  - name: Child Widgets
    description: My description
  - name: Widgets
    description: My description

without @tagMetadata

tags:
  - name: Widgets
  - name: Child Widgets

First I do agree this is not good consitencyhowever I think the operation order as in the 2nd one is not a good order to prevent changes(#2293) Any reason you want it that way instead of having it alphabetized?

@aelberg
Copy link
Author

aelberg commented Mar 14, 2025

Correct using the @tagMetadata decorator is impacting the order that tags are emitted in the openapi spec which impacts the order in SwaggerUI.

As far as controlling the order of operations this is mostly for a "logical" order. Having parent resources appear before child (we could probably group these in the same tag as well but currently we are not).
We also typically have the more commonly used operations towards the top.
We have some utility type operations that are on every api that we typically put at the end.

I know the order can be controlled via SwaggerUI or other interfaces as well so ordering is not guaranteed. I was just surprised to see it change one I started using the tagMetadata as it had always been ordered based on the order of operations in my typespec file previously.

@timotheeguerin
Copy link
Member

so just tested and the order isn't actually alphabetized it is the order as defined in the order the decorators run(bottom up)

playground

change the order you get different results.

However as you are finding out decorator order is also confusing and we general try not to rely on it.

@markcowl markcowl added this to the Backlog milestone Mar 18, 2025
@markcowl markcowl added lib:openapi triaged:core design:needed A design request has been raised that needs a proposal and removed needs-area bug Something isn't working labels Mar 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design:needed A design request has been raised that needs a proposal lib:openapi triaged:core
Projects
None yet
Development

No branches or pull requests

3 participants