fix(openapi3): preserve @tagMetadata tag declaration order in emitted OpenAPI#10770
fix(openapi3): preserve @tagMetadata tag declaration order in emitted OpenAPI#10770Copilot wants to merge 3 commits into
Conversation
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/bf960a34-147a-499e-8598-bc0d9d392ade Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
|
@copilot add multiple test cases if we don't have them already: one where a tag is used at the operation level, but not defined at the tagMetadata/service level to see where it "inserts" itself. one where a tag is used at the operation level, and defined at the tagMetadata/service level to see where it "inserts" itself. |
commit: |
…data Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/3880bfa8-c4e5-41a8-b869-3b0c5826805e Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Added two new tests in commit 76ffa16:
|
|
You can try these changes here
|
markcowl
left a comment
There was a problem hiding this comment.
I don't think we can take this, as it is a breaking behavior change. If the order of tags is important, I think the best non-breaking short term solution would be to allow arrays in @tagMetadata. I think the longer term solution is probably here: #10771
When
@tagMetadatais applied, tags were emitted in reverse declaration order because TypeSpec decorators execute bottom-up, causing the metadata map to accumulate entries in reverse.Changes
packages/openapi3/src/openapi.ts: InresolveDocumentTags, reverseObject.entries(metadata)before iteration so emitted tags match TypeSpec source declaration order.packages/openapi3/test/tagmetadata.test.ts: Add explicit ordering tests; update existing parent-field tests whose expected values reflected the old reversed order. Added tests covering:@tagMetadatadecorators@tagMetadata— inserted before tagMetadata-defined tags@tagMetadata— emitted once in its tagMetadata-declared position (not duplicated)Example
Before: tags emitted as
Third → Second → FirstAfter: tags emitted as
First → Second → Third(matching declaration order)Tag insertion behavior
@tag) and not declared with@tagMetadataappear first in the output, in the order they are encountered across operations.@tagMetadatafollow, in TypeSpec source declaration order.@tagMetadatais emitted exactly once, at its@tagMetadata-declared position with its metadata.