Skip to content

Commit 52f1269

Browse files
committed
fix: normalize window path with slash function
1 parent 7447189 commit 52f1269

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/core/src/rules/ajv.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import addFormats from 'ajv-formats';
22
import Ajv from '@redocly/ajv/dist/2020.js';
33
import { escapePointerFragment } from '../ref-utils.js';
4+
import { slash } from '../utils/slash.js';
45

56
import type { Location } from '../ref-utils.js';
67
import type { ValidateFunction, ErrorObject } from '@redocly/ajv/dist/2020.js';
@@ -26,9 +27,10 @@ function getAjv(resolve: ResolveFn, allowAdditionalProperties: boolean) {
2627
validateFormats: true,
2728
defaultUnevaluatedProperties: allowAdditionalProperties,
2829
loadSchemaSync(base: string, $ref: string, $id: string) {
29-
const resolvedRef = resolve({ $ref }, base.split('#')[0]);
30+
const resolvedRef = resolve({ $ref }, slash(base.split('#')[0]));
3031
if (!resolvedRef || !resolvedRef.location) return false;
31-
return { $id: resolvedRef.location.source.absoluteRef + '#' + $id, ...resolvedRef.node };
32+
const normalizedAbsoluteRef = slash(resolvedRef.location.source.absoluteRef);
33+
return { $id: normalizedAbsoluteRef + '#' + $id, ...resolvedRef.node };
3234
},
3335
logger: false,
3436
});
@@ -44,7 +46,7 @@ function getAjvValidator(
4446
allowAdditionalProperties: boolean
4547
): ValidateFunction | undefined {
4648
const ajv = getAjv(resolve, allowAdditionalProperties);
47-
const $id = encodeURI(loc.absolutePointer);
49+
const $id = encodeURI(slash(loc.absolutePointer));
4850

4951
if (!ajv.getSchema($id)) {
5052
ajv.addSchema({ $id, ...schema }, $id);

0 commit comments

Comments
 (0)