11import addFormats from 'ajv-formats' ;
22import Ajv from '@redocly/ajv/dist/2020.js' ;
33import { escapePointerFragment } from '../ref-utils.js' ;
4+ import { slash } from '../utils/slash.js' ;
45
56import type { Location } from '../ref-utils.js' ;
67import 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