/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/cypress-ajv-schema-validator@2.0.2/src/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import hljs from"highlight.js";import{validateSchema}from"core-ajv-schema-validator";import"./custom-log.js";const iconPassed="✔️",iconFailed="❌",iconMoreErrors="➕",issuesStylesDefault={iconPropertyError:"⚠️",colorPropertyError:"#d67e09",iconPropertyMissing:"❌",colorPropertyMissing:"#c10000"},warningDisableSchemaValidation="⚠️ API SCHEMA VALIDATION DISABLED ⚠️",msgDisableSchemaValidation='- The Cypress environment variable "disableSchemaValidation" has been set to true.',errorNoValidApiResponse="The element chained to the cy.validateSchema() command is expected to be an API response!",errorResponseBodyAgainstSchema="The response body is not valid against the schema!";Cypress.Commands.add("validateSchema",{prevSubject:!0},((e,s,r,o)=>{if(Cypress.env("disableSchemaValidation"))cy.colorLog(msgDisableSchemaValidation,"#e0e030",{displayName:warningDisableSchemaValidation}),console.log(`${warningDisableSchemaValidation} ${msgDisableSchemaValidation}`);else{if(null==e||!e.hasOwnProperty("body")&&!e.hasOwnProperty("status")&&!e.hasOwnProperty("headers"))throw console.log(errorNoValidApiResponse),new Error(errorNoValidApiResponse);const i=e.body;o={...issuesStylesDefault,...o};const t=validateSchema(i,s,r,o);_logValidationResult(i,t,o)}return cy.wrap(e,{log:!1})}));const _logValidationResult=(e,s,r,o=10)=>{let{errors:i,dataMismatches:t}=s;if(i){let s,a,n,l;const c=mustEnableMismatchesOnUI();c&&(a=Cypress.$('[id="api-plugin-root"] [id="api-view"]'),0!==a.length?(s="filip",n=a.clone(),l=n.find('section:last-of-type [data-cy="responseBody"] code > details > summary')):(a=Cypress.$(".cy-api-response:last-of-type pre"),0!==a.length&&(s="gleb")));const{iconPropertyError:p,colorPropertyError:h,iconPropertyMissing:y,colorPropertyMissing:m}=r;let d,g;"filip"===s&&i.forEach((s=>{let o,i=s.instancePath.replace(/^\//,"").split("/"),t=i.join("."),a=Cypress._.get(e,t);if("required"===s.keyword){const e=s.params.missingProperty;t=""===t?e:`${t}.${e}`,o=`${y} Missing property '${e}'`}else{const e=s.message;o=`${p} ${String(JSON.stringify(a)).replaceAll('"',"'")} ${e}`}c&&l&&l.length&&showDataMismatchesApiViewFilip(l,i,o,s,r,0)})),c&&("filip"===s?a.replaceWith(n):"gleb"===s&&a.replaceWith(Cypress.$(transformDataToHtmlGleb(t,r)))),cy.colorLog(`**THE RESPONSE BODY IS NOT VALID AGAINST THE SCHEMA (Number of schema errors: ${i.length}).**`,"#e34040",{displayName:"❌ FAILED -",info:{number_of_schema_errors:i.length,ajv_errors:i,data_mismatches:t}}),i.length>o+1?(d=i.slice(0,o),g=i.slice(o)):d=i,d.forEach((e=>{const s="required"===e.keyword?y:p,r="required"===e.keyword?m:h;cy.colorLog(`${JSON.stringify(e,"",1)}`,r,{displayName:s,info:{schema_error:e}})})),g&&cy.colorLog(`...and ${i.length-o} more errors.`,m,{displayName:"➕",info:{rest_of_errors:g}}),cy.then((()=>{throw console.log(errorResponseBodyAgainstSchema),new Error(errorResponseBodyAgainstSchema)}))}else cy.colorLog("**THE RESPONSE BODY IS VALID AGAINST THE SCHEMA.**","#66d966",{displayName:"✔️ PASSED -"})},transformDataToHtmlGleb=(e,s)=>{const{iconPropertyError:r,colorPropertyError:o,iconPropertyMissing:i,colorPropertyMissing:t}=s,a="font-weight: bold; font-size: 1.3em;";let n=JSON.stringify(e,null,4),l=hljs.highlight(n,{language:"json"}).value;const c=RegExp(`>&quot;${r}`,"g");l=l.replaceAll(c,(e=>` style="${a} color: ${o};"${e}`));const p=RegExp(`>&quot;${i}`,"g");return l=l.replaceAll(p,(e=>` style="${a}; color: ${t};"${e}`)),`<pre class="hljs">${l}</pre>`},showDataMismatchesApiViewFilip=(e,s,r,o,i,t)=>{const{colorPropertyError:a,iconPropertyError:n,colorPropertyMissing:l}=i,c="font-weight: bold; font-size: 1.3em;";let p=s.shift();if(e.hasClass("bracket")){const l=e.siblings("details").eq(parseInt(p));0===l.length?Cypress.$(`<span style="${c} padding-left: 15px; color: ${a};">${n} Array ${o.message} </span>`).insertAfter(e.parent().next()):showDataMismatchesApiViewFilip(l.children("summary"),s,r,o,i,t+1)}else if(e.hasClass("brace")){const a=e.siblings(`.token.property:contains("${p}")`).filter(((e,s)=>Cypress.$(s).text()===`"${p}"`));if(0===a.length)Cypress.$(`<br><span class="line-number text-slate-700 select-none contents align-top">      </span><span style="${c} padding-left: ${25+14*(t-1)}px; color: ${l};">"${o.params.missingProperty}": ${r} </span>`).insertAfter(e);else{let e=a.next().next();e.is("details")&&(e=e.children("summary")),showDataMismatchesApiViewFilip(e,s,r,o,i,t+1)}}else Cypress.$(`<span style="${c} padding-left: 15px; color: ${a};">${r} </span>`).insertAfter(e)},mustEnableMismatchesOnUI=()=>Cypress.config("isInteractive")&&Cypress.env("enableMismatchesOnUI");
//# sourceMappingURL=/sm/270e6ac91d9adc81b2b4d9b89dda34c9114f9b68f679eed4a61265e1d4819883.map