fix: hash ending path resolution fails (#1408)

This commit is contained in:
Emin Arakelian
2024-02-04 23:31:04 -08:00
committed by GitHub
parent 8bff6a814b
commit 4ab6e09e18
6 changed files with 44 additions and 3 deletions

View File

@@ -0,0 +1,6 @@
---
"@redocly/openapi-core": patch
"@redocly/cli": patch
---
Fixed an issue where `$ref`s ending in `#` (instead of `#/`) would break the application.

View File

@@ -0,0 +1,10 @@
openapi: 3.0.3
paths:
/pets/{petId}:
get:
responses:
'200':
content:
application/json:
schema:
$ref: './schemas/Pet.json#'

View File

@@ -0,0 +1,3 @@
apis:
main:
root: ./openapi.yaml

View File

@@ -0,0 +1 @@
{}

View File

@@ -0,0 +1,21 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`E2E bundle reference-ending-in-hash 1`] = `
openapi: 3.0.3
paths:
/pets/{petId}:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Pet'
components:
schemas:
Pet: {}
bundling ./openapi.yaml...
📦 Created a bundle for ./openapi.yaml at stdout <test>ms.
`;

View File

@@ -43,15 +43,15 @@ export function escapePointer<T extends string | number>(fragment: T): T {
}
export function parseRef(ref: string): { uri: string | null; pointer: string[] } {
const [uri, pointer] = ref.split('#/');
const [uri, pointer = ''] = ref.split('#');
return {
uri: uri || null,
pointer: pointer ? pointer.split('/').map(unescapePointer).filter(isTruthy) : [],
pointer: parsePointer(pointer),
};
}
export function parsePointer(pointer: string) {
return pointer.substr(2).split('/').map(unescapePointer);
return pointer.split('/').map(unescapePointer).filter(isTruthy);
}
export function pointerBaseName(pointer: string) {