Skip to content
This repository was archived by the owner on Jan 12, 2026. It is now read-only.

Commit 8001d02

Browse files
authored
Handle spaces in file path for capture (#2652)
1 parent 48adf9b commit 8001d02

7 files changed

Lines changed: 132 additions & 8 deletions

File tree

projects/openapi-io/src/parser/sourcemap.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,19 @@ export class JsonSchemaSourcemap {
7979
}
8080

8181
logPointer(pathRelativeToFile: string, pathRelativeToRoot: string) {
82+
const relativePathDecoded =
83+
jsonPointerHelpers.unescapeUriSafePointer(pathRelativeToFile);
84+
const rootKey = jsonPointerHelpers.unescapeUriSafePointer(
85+
pathRelativeToRoot.substring(1)
86+
);
87+
8288
const thisFile = this.files.find((i) =>
83-
pathRelativeToFile.startsWith(i.path)
89+
relativePathDecoded.startsWith(i.path)
8490
);
8591

8692
if (thisFile) {
87-
const rootKey = jsonPointerHelpers.unescapeUriSafePointer(
88-
pathRelativeToRoot.substring(1)
89-
);
90-
9193
const jsonPointer = jsonPointerHelpers.unescapeUriSafePointer(
92-
pathRelativeToFile.split(thisFile.path)[1].substring(1) || '/'
94+
relativePathDecoded.split(thisFile.path)[1].substring(1) || '/'
9395
);
9496

9597
if (rootKey === jsonPointer) return;

projects/openapi-utilities/src/openapi3/implementations/openapi3/sourcemap-reader.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ export function sourcemapReader(sourcemap: SerializedSourcemap) {
115115
} else {
116116
cursor.pathInCurrentFile.push(component);
117117
}
118-
119-
// console.log(cursor);
120118
});
121119

122120
const file = sourcemap.files.find((i) => i.index === cursor.currentFile)!;

projects/optic/src/__tests__/integration/__snapshots__/capture.test.ts.snap

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,71 @@ exports[`capture with requests update behavior handles update in other file 3`]
17261726
"
17271727
`;
17281728

1729+
exports[`capture with requests update behavior handles update in other file with spaces 1`] = `
1730+
"Generating traffic to send to server
1731+
GET /books
1732+
✓ 200 response
1733+
[200 response body] 'name' has been added (/properties/books/items/properties/name)
1734+
[200 response body] 'author_id' has been added (/properties/books/items/properties/author_id)
1735+
[200 response body] 'status' has been added (/properties/books/items/properties/status)
1736+
[200 response body] 'price' has been added (/properties/books/items/properties/price)
1737+
[200 response body] 'created_at' has been added (/properties/books/items/properties/created_at)
1738+
[200 response body] 'updated_at' has been added (/properties/books/items/properties/updated_at)
1739+
"
1740+
`;
1741+
1742+
exports[`capture with requests update behavior handles update in other file with spaces 2`] = `
1743+
"openapi: 3.0.3
1744+
info:
1745+
title: a spec
1746+
description: The API
1747+
version: 0.1.0
1748+
paths:
1749+
/books:
1750+
get:
1751+
responses:
1752+
"200":
1753+
description: 200 response
1754+
content:
1755+
application/json:
1756+
schema:
1757+
$ref: ./with space/books.yml#/GetBooks200ResponseBody
1758+
"
1759+
`;
1760+
1761+
exports[`capture with requests update behavior handles update in other file with spaces 3`] = `
1762+
"GetBooks200ResponseBody:
1763+
type: object
1764+
properties:
1765+
books:
1766+
type: array
1767+
items:
1768+
type: object
1769+
properties:
1770+
id:
1771+
type: string
1772+
name:
1773+
type: string
1774+
author_id:
1775+
type: string
1776+
status:
1777+
type: string
1778+
price:
1779+
type: number
1780+
created_at:
1781+
type: string
1782+
updated_at:
1783+
type: string
1784+
required:
1785+
- name
1786+
- author_id
1787+
- status
1788+
- price
1789+
- created_at
1790+
- updated_at
1791+
"
1792+
`;
1793+
17291794
exports[`capture with requests update behavior respects x-optic-path-ignore 1`] = `
17301795
"Generating traffic to send to server
17311796
GET /authors

projects/optic/src/__tests__/integration/capture.test.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ describe('capture with requests', () => {
216216
)
217217
).toMatchSnapshot();
218218
});
219+
220+
test('handles update in other file with spaces', async () => {
221+
const workspace = await setupWorkspace('capture/with-server');
222+
await setPortInFile(workspace, 'optic.yml');
223+
224+
const { combined, code } = await runOptic(
225+
workspace,
226+
'capture openapi-with-external-ref-spaces.yml --update'
227+
);
228+
expect(normalizeWorkspace(workspace, combined)).toMatchSnapshot();
229+
expect(code).toBe(0);
230+
expect(
231+
await fs.readFile(
232+
path.join(workspace, 'openapi-with-external-ref-spaces.yml'),
233+
'utf-8'
234+
)
235+
).toMatchSnapshot();
236+
expect(
237+
await fs.readFile(
238+
path.join(workspace, './with space/books.yml'),
239+
'utf-8'
240+
)
241+
).toMatchSnapshot();
242+
});
219243
});
220244
});
221245

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
openapi: 3.0.3
2+
info:
3+
title: a spec
4+
description: The API
5+
version: 0.1.0
6+
paths:
7+
/books:
8+
get:
9+
responses:
10+
"200":
11+
description: 200 response
12+
content:
13+
application/json:
14+
schema:
15+
$ref: ./with space/books.yml#/GetBooks200ResponseBody

projects/optic/src/__tests__/integration/workspaces/capture/with-server/optic.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,16 @@ capture:
9898
send:
9999
- path: /books
100100
method: GET
101+
openapi-with-external-ref-spaces.yml:
102+
server:
103+
command: node server.js
104+
url: http://localhost:%PORT
105+
ready_endpoint: /healthcheck
106+
ready_timeout: 5000
107+
requests:
108+
send:
109+
- path: /books
110+
method: GET
101111
openapi-with-server-prefix.yml:
102112
server:
103113
command: node server.js
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
GetBooks200ResponseBody:
2+
type: object
3+
properties:
4+
books:
5+
type: array
6+
items:
7+
type: object
8+
properties:
9+
id:
10+
type: string

0 commit comments

Comments
 (0)