Skip to content

Commit 4ab6e09

Browse files
authored
fix: hash ending path resolution fails (#1408)
1 parent 8bff6a8 commit 4ab6e09

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

.changeset/soft-planets-watch.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@redocly/openapi-core": patch
3+
"@redocly/cli": patch
4+
---
5+
6+
Fixed an issue where `$ref`s ending in `#` (instead of `#/`) would break the application.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: 3.0.3
2+
paths:
3+
/pets/{petId}:
4+
get:
5+
responses:
6+
'200':
7+
content:
8+
application/json:
9+
schema:
10+
$ref: './schemas/Pet.json#'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
apis:
2+
main:
3+
root: ./openapi.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`E2E bundle reference-ending-in-hash 1`] = `
4+
openapi: 3.0.3
5+
paths:
6+
/pets/{petId}:
7+
get:
8+
responses:
9+
'200':
10+
content:
11+
application/json:
12+
schema:
13+
$ref: '#/components/schemas/Pet'
14+
components:
15+
schemas:
16+
Pet: {}
17+
18+
bundling ./openapi.yaml...
19+
📦 Created a bundle for ./openapi.yaml at stdout <test>ms.
20+
21+
`;

packages/core/src/ref-utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ export function escapePointer<T extends string | number>(fragment: T): T {
4343
}
4444

4545
export function parseRef(ref: string): { uri: string | null; pointer: string[] } {
46-
const [uri, pointer] = ref.split('#/');
46+
const [uri, pointer = ''] = ref.split('#');
4747
return {
4848
uri: uri || null,
49-
pointer: pointer ? pointer.split('/').map(unescapePointer).filter(isTruthy) : [],
49+
pointer: parsePointer(pointer),
5050
};
5151
}
5252

5353
export function parsePointer(pointer: string) {
54-
return pointer.substr(2).split('/').map(unescapePointer);
54+
return pointer.split('/').map(unescapePointer).filter(isTruthy);
5555
}
5656

5757
export function pointerBaseName(pointer: string) {

0 commit comments

Comments
 (0)