Skip to content

Fix x-ms-paths sorting for query-only paths#4088

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-autorest-sorting-issue
Draft

Fix x-ms-paths sorting for query-only paths#4088
Copilot wants to merge 2 commits intomainfrom
copilot/fix-autorest-sorting-issue

Conversation

Copy link
Contributor

Copilot AI commented Mar 23, 2026

compareUrl in the JSON schema sorter fails to sort x-ms-paths entries starting with ? (e.g. ?a=1, ?b=1). The function splits by / then calls .slice(1), which produces empty arrays for query-only paths, making them all compare as equal.

Fix: Split path and query portions before segment comparison. When path segments are equal (including both empty for query-only paths), fall back to lexicographic comparison of the query string.

// These x-ms-paths entries now sort alphabetically
@route("?b=1")
op one_q(): void;

@route("?a=1")
op two_q(): void;
// Output: "?a=1" before "?b=1"
Original prompt

This section details on the original issue you should resolve

<issue_title>Autorest output doesn't sort x-ms-paths path that start with ?</issue_title>
<issue_description>

import "@typespec/http";

using Http;

@route("/b")
op one_p(): void;

@route("/a")
op two_p(): void;

// Here paths remain in the order they are defined not alpha sorted
@route("?b=1")
op one_q(): void;

@route("?a=1")
op two_q(): void;

Playground Link</issue_description>

<agent_instructions>Make sure our special sorting for paths and x-ms-paths handles sorting with hard coded query path too</agent_instructions>

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

@microsoft-github-policy-service microsoft-github-policy-service bot added the emitter:autorest Issues for @azure-tools/typespec-autorest emitter label Mar 23, 2026
Copilot AI changed the title [WIP] Fix autorest output sorting for x-ms-paths with query parameters Fix x-ms-paths sorting for query-only paths Mar 23, 2026
Copilot AI requested a review from timotheeguerin March 23, 2026 18:21
@timotheeguerin timotheeguerin added the int:azure-specs Run integration tests against azure-rest-api-specs label Mar 23, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@azure-tools/typespec-autorest@4088

commit: 77bd8de

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:autorest Issues for @azure-tools/typespec-autorest emitter int:azure-specs Run integration tests against azure-rest-api-specs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Autorest output doesn't sort x-ms-paths path that start with ?

2 participants