Skip to content

Commit 8f9b2e0

Browse files
committed
fix: align multiline JSON body indentation in dry-run output
Continuation lines of JSON.stringify output are now indented to align with the first line after the 'Body: ' label prefix. Also uses getDefaultSdkConfig().baseUrl (with trailing-slash normalization) instead of raw getApiBaseUrl() in resolveRequestUrl to match the URL rawApiRequest would actually use.
1 parent a6e26f5 commit 8f9b2e0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/commands/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,9 @@ export function writeDryRunHuman(stdout: Writer, request: DryRunRequest): void {
995995
typeof request.body === "string"
996996
? request.body
997997
: JSON.stringify(request.body, null, 2);
998-
stdout.write(` Body: ${bodyStr}\n`);
998+
// Indent continuation lines to align with the first line after "Body: "
999+
const indented = bodyStr.replace(/\n/g, "\n ");
1000+
stdout.write(` Body: ${indented}\n`);
9991001
}
10001002

10011003
stdout.write("\n");

test/commands/api.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,6 +1861,26 @@ describe("writeDryRunHuman", () => {
18611861
expect(writer.output).toContain('"status": "resolved"');
18621862
});
18631863

1864+
test("multiline JSON body has aligned indentation", () => {
1865+
const writer = createMockWriter();
1866+
writeDryRunHuman(writer, {
1867+
method: "POST",
1868+
url: "https://sentry.io/api/0/issues/",
1869+
headers: {},
1870+
body: { status: "resolved", assignedTo: "user:123" },
1871+
});
1872+
1873+
// Each continuation line of the JSON body should be indented to align
1874+
// with the first line (12 spaces = " Body: " prefix width)
1875+
const lines = writer.output.split("\n");
1876+
const bodyLineIdx = lines.findIndex((l) => l.includes("Body:"));
1877+
expect(bodyLineIdx).toBeGreaterThan(-1);
1878+
// The JSON is multiline, so check that the next line starts with spaces
1879+
const nextLine = lines[bodyLineIdx + 1];
1880+
expect(nextLine).toBeDefined();
1881+
expect(nextLine!.startsWith(" ")).toBe(true);
1882+
});
1883+
18641884
test("writes string body as-is", () => {
18651885
const writer = createMockWriter();
18661886
writeDryRunHuman(writer, {

0 commit comments

Comments
 (0)