Skip to content

Commit 666c5e0

Browse files
committed
fix: for resolving base correctly for windows env
1 parent 52f1269 commit 666c5e0

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/core/src/rules/ajv.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
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';
54

65
import type { Location } from '../ref-utils.js';
76
import type { ValidateFunction, ErrorObject } from '@redocly/ajv/dist/2020.js';
@@ -27,10 +26,14 @@ function getAjv(resolve: ResolveFn, allowAdditionalProperties: boolean) {
2726
validateFormats: true,
2827
defaultUnevaluatedProperties: allowAdditionalProperties,
2928
loadSchemaSync(base: string, $ref: string, $id: string) {
30-
const resolvedRef = resolve({ $ref }, slash(base.split('#')[0]));
29+
const decodedBase = decodeURI(base.split('#')[0]);
30+
const resolvedRef = resolve({ $ref }, decodedBase);
3131
if (!resolvedRef || !resolvedRef.location) return false;
32-
const normalizedAbsoluteRef = slash(resolvedRef.location.source.absoluteRef);
33-
return { $id: normalizedAbsoluteRef + '#' + $id, ...resolvedRef.node };
32+
33+
return {
34+
$id: encodeURI(resolvedRef.location.source.absoluteRef) + '#' + $id,
35+
...resolvedRef.node,
36+
};
3437
},
3538
logger: false,
3639
});
@@ -46,7 +49,7 @@ function getAjvValidator(
4649
allowAdditionalProperties: boolean
4750
): ValidateFunction | undefined {
4851
const ajv = getAjv(resolve, allowAdditionalProperties);
49-
const $id = encodeURI(slash(loc.absolutePointer));
52+
const $id = encodeURI(loc.absolutePointer);
5053

5154
if (!ajv.getSchema($id)) {
5255
ajv.addSchema({ $id, ...schema }, $id);

0 commit comments

Comments
 (0)