/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
var _validate;const DOT=".";function validateComponentJson(obj){var errors,error,s,i,ret=null;if(!_validate){_init()}if(!_validate(obj)){ret=[];errors=_validate.errors;for(i=0;i<errors.length;i++){error=errors[i];s=_cleanAjvMessages(error);if(s&&!s.includes("(if)")){ret.push({msg:s,error:error})}}}return ret};function _cleanAjvMessages(error){var prop,propType,msg,param,ret;var instPath=_convertJsonPointer(error.instancePath);if(instPath===""){instPath="JSON top-level"};switch(error.keyword){case"required":ret=`${error.message}  at ${instPath}`;break;case"enum":ret=`bad property '${instPath}' value : ${error.message}} [${error.params.allowedValues}]`;break;case"additionalProperties":if(error.params){param=error.params["additionalProperty"];param=param?` '${param}'`:"";if(error.instancePath.includes(DOT)){ret=`unexpected metadata property'${param}' in '${instPath}`}else{ret=`invalid property'${param}' in '${instPath}'`}}else{ret=`"unexpected property (unknown) at '${instPath}'`}break;case"type":ret=`${instPath} - ${error.message}`;break;case"not":msg=error.message;msg=msg.replace("must NOT be valid","is not permitted");if(instPath){propType=instPath.startsWith("prop")?"property":instPath.startsWith("events")?"events":instPath.startsWith("name")?"name":""}prop=error.propertyName?error.propertyName:"";ret=propType+(propType.length?" ":"")+(prop?"'"+prop+"'":"")+" at '"+instPath+"' "+msg;break;case"propertyNames":ret=error.message+(error.params&&error.params.propertyName?" - '"+error.params.propertyName+"'":"")+" at '"+instPath+"'";break;case"pattern":return`property '${instPath}' failed a schema format pattern match`;break;case"format":return`property '${instPath}' format - ${error.message}`;break;case"anyOf":return`property ${instPath} - ${error.message}`;break;case"if":break;default:ret=`unknown error ('${error.keyword}', '${error.message}')`}return ret};function _convertJsonPointer(ip){if(ip){if(ip.startsWith("/")){ip=ip.substring(1)}let elems=ip.split("/");for(let i=0;i<elems.length;i++){let elem=elems[i];if(elem!==DOT&&!isNaN(elem)){elems[i]="["+elem+"]"}}ip=elems.join(".");ip=ip.replace(/\.\[/g,"[")}return ip};const FAST_URI=/^(?:[a-z][a-z0-9+\-.]*:)(?:\/?\/)?[^\s]*$/i;const Z_ANCHOR=/[^\\]\\Z/;function isValidJSRegex(str){if(Z_ANCHOR.test(str))return false;try{new RegExp(str);return true}catch(e){return false}}function _init(){const schema=require("../schema/component-schema.json");const Ajv=require("ajv");const _ajv=new Ajv({allErrors:true,strictTypes:false,formats:{uri:FAST_URI,regex:isValidJSRegex}});_validate=_ajv.compile(schema)};module.exports.validateComponentJson=validateComponentJson;