import { Ajv , ValidateFunction } from "ajv" ; import { JSONSchema6 } from "json-schema" ; import { getDataKeys , getSchemaId } from "../libs/resolve" ; import { warn } from "../utils" ; import { schemaFieldFactory , schemaKeysFactory } from "../factory" ; param { string } $id param { JSONSchema6 } schema param { Ajv } ajv return { JSONSchema6 } export default ( $id , schema , ajv ) => { if ( schema && schema . $ref ) { const schemaId = getSchemaId ( schema . $ref ) ; if ( schema . $id ) { schema . $ref = schema . $id + schema . $ref ; } else if ( ! schemaId ) { schema . $ref = getSchemaId ( $id ) + schema . $ref ; } const validate = ajv . getSchema ( schema . $ref ) ; if ( validate && validate . schema ) { let schemaAjv = Object . assign ( { } , validate . schema ) as JSONSchema6 ; schemaAjv . $ref = schema . $ref ; delete schemaAjv . $id ; Object . assign ( schemaAjv , { refKeys : getDataKeys ( schema . $ref ) } ) ; return schemaAjv ; } if ( __DEV__ ) { warn ( `${ schema . $ref } not exist.` ) ; } } return schema ; } ;