Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/api-ls-path-separator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"clerk": patch
---

Keep a separator between the path and description in `clerk api ls` so long endpoint paths no longer run straight into their summaries.
24 changes: 24 additions & 0 deletions packages/cli-core/src/commands/api/ls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,19 @@ import { parseSpec, _setCacheDir } from "./catalog.ts";
import { useCaptureLog, stubFetch } from "../../test/lib/stubs.ts";
import { apiLs } from "./ls.ts";

const LONG_PATH_SPEC = `
openapi: "3.0.0"
info:
title: Test API
version: "1.0"
paths:
/organizations/{organization_id}/memberships/{user_id}:
get:
tags: [Organizations]
summary: Get organization membership
operationId: GetOrganizationMembership
`;

const MINIMAL_SPEC = `
openapi: "3.0.0"
info:
Expand Down Expand Up @@ -112,4 +125,15 @@ describe("apiLs", () => {
await runApiLs(undefined, { platform: true });
expect(captured.out).not.toBe("");
});

test("long path (>=50 chars) is separated from summary by at least two spaces", async () => {
const longPath = "/organizations/{organization_id}/memberships/{user_id}";
const cached = parseSpec(LONG_PATH_SPEC);
cached.fetchedAt = Date.now();
await Bun.write(join(tempDir, "bapi-catalog.json"), JSON.stringify(cached));

await runApiLs(undefined, {});

expect(captured.out).toContain(`${longPath} Get organization membership`);
});
});
4 changes: 3 additions & 1 deletion packages/cli-core/src/commands/api/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function printTable(endpoints: EndpointInfo[]): void {

for (const ep of endpoints) {
const method = ep.method.padEnd(methodWidth);
const path = ep.path.padEnd(pathWidth);
// padEnd is a no-op once the path meets/exceeds pathWidth, so guarantee a
// separator for over-long paths instead of gluing the summary onto them.
const path = ep.path.length >= pathWidth ? `${ep.path} ` : ep.path.padEnd(pathWidth);
Comment thread
rafa-thayto marked this conversation as resolved.
log.data(`${method}${path}${ep.summary}`);
}
}
Loading