import Ajv , { ValidateFunction } from "ajv" ; import { Json } from "../api" ; import { SchemaForApiJsonFiles } from "./api-json" ; import * as schema from "@ui5-language-assistant/semantic-model/resources/sap-ui-library-api.json" ; import * as jsonDraft06Schema from "ajv/lib/refs/json-schema-draft-06.json" ; import { isPlainObject , isArray } from "lodash" ; const validate = createSchemaValidator ( ) ; function createSchemaValidator ( ) { const ajv = new Ajv ( { ownProperties : true } ) ; ajv . addMetaSchema ( jsonDraft06Schema ) ; const validate = ajv . compile ( schema ) ; return validate ; } export function isLibraryFile ( fileName , fileContent , strict , printValidationErrors ) { const valid = validate ( fileContent ) ; if ( ! valid && printValidationErrors ) { console . log ( JSON . stringify ( validate . errors , undefined , 2 ) ) ; } if ( ! strict ) { if ( ! valid ) { return ( isPlainObject ( fileContent ) && isArray ( ( fileContent as Record < string , unknown > ) . symbols ) ) ; } return true ; } return valid as boolean ; }