@@ -9,68 +9,79 @@ import {getManifestSchema} from "../../utils/ui5Manifest.js";
99const log = getLogger ( "tools:run_manifest_validation:runValidation" ) ;
1010const schemaCache = new Map < string , Promise < object > > ( ) ;
1111
12- async function createUI5ManifestValidateFunction ( ui5Schema : object ) {
13- const ajv = new Ajv2020 . default ( {
14- allErrors : true , // Collect all errors, not just the first one
15- strict : false , // Allow additional properties that are not in schema
16- unicodeRegExp : false ,
17- loadSchema : async ( uri ) => {
18- // Check cache first to prevent infinite loops
19- if ( schemaCache . has ( uri ) ) {
20- log . info ( `Loading cached schema: ${ uri } ` ) ;
12+ // Configuration constants
13+ const AJV_SCHEMA_PATHS = {
14+ draft06 : "node_modules/ajv/dist/refs/json-schema-draft-06.json" ,
15+ draft07 : "node_modules/ajv/dist/refs/json-schema-draft-07.json" ,
16+ } as const ;
2117
22- try {
23- const schema = await schemaCache . get ( uri ) ! ;
24- return schema ;
25- } catch {
26- schemaCache . delete ( uri ) ;
27- }
28- }
29-
30- log . info ( `Loading external schema: ${ uri } ` ) ;
31- let fetchSchema : Promise < object > ;
32-
33- try {
34- if ( uri . includes ( "adaptive-card.json" ) ) {
35- // Special handling for Adaptive Card schema to fix unsupported "id" property
36- // According to the JSON Schema spec Draft 06 (used by Adaptive Card schema),
37- // "$id" should be used instead of "id"
38- fetchSchema = fetchCdn ( uri )
39- . then ( ( response ) => {
40- if ( "id" in response && typeof response . id === "string" ) {
41- const typedResponse = response as Record < string , unknown > ;
42- typedResponse . $id = response . id ;
43- delete typedResponse . id ;
44- }
45- return response ;
46- } ) ;
47- } else {
48- fetchSchema = fetchCdn ( uri ) ;
18+ async function createUI5ManifestValidateFunction ( ui5Schema : object ) {
19+ try {
20+ const ajv = new Ajv2020 . default ( {
21+ allErrors : true , // Collect all errors, not just the first one
22+ strict : false , // Allow additional properties that are not in schema
23+ unicodeRegExp : false ,
24+ loadSchema : async ( uri ) => {
25+ // Check cache first to prevent infinite loops
26+ if ( schemaCache . has ( uri ) ) {
27+ log . info ( `Loading cached schema: ${ uri } ` ) ;
28+
29+ try {
30+ const schema = await schemaCache . get ( uri ) ! ;
31+ return schema ;
32+ } catch {
33+ schemaCache . delete ( uri ) ;
34+ }
4935 }
5036
51- schemaCache . set ( uri , fetchSchema ) ;
52- return fetchSchema ;
53- } catch ( error ) {
54- log . warn ( `Failed to load external schema ${ uri } :` +
55- `${ error instanceof Error ? error . message : String ( error ) } ` ) ;
37+ log . info ( `Loading external schema: ${ uri } ` ) ;
38+ let fetchSchema : Promise < object > ;
5639
57- throw error ;
58- }
59- } ,
60- } ) ;
61- const draft06MetaSchema = JSON . parse (
62- await readFile ( "node_modules/ajv/dist/refs/json-schema-draft-06.json" , "utf-8" )
63- ) as AnySchemaObject ;
64- const draft07MetaSchema = JSON . parse (
65- await readFile ( "node_modules/ajv/dist/refs/json-schema-draft-07.json" , "utf-8" )
66- ) as AnySchemaObject ;
40+ try {
41+ if ( uri . includes ( "adaptive-card.json" ) ) {
42+ // Special handling for Adaptive Card schema to fix unsupported "id" property
43+ // According to the JSON Schema spec Draft 06 (used by Adaptive Card schema),
44+ // "$id" should be used instead of "id"
45+ fetchSchema = fetchCdn ( uri )
46+ . then ( ( response ) => {
47+ if ( "id" in response && typeof response . id === "string" ) {
48+ const typedResponse = response as Record < string , unknown > ;
49+ typedResponse . $id = response . id ;
50+ delete typedResponse . id ;
51+ }
52+ return response ;
53+ } ) ;
54+ } else {
55+ fetchSchema = fetchCdn ( uri ) ;
56+ }
57+
58+ schemaCache . set ( uri , fetchSchema ) ;
59+ return fetchSchema ;
60+ } catch ( error ) {
61+ log . warn ( `Failed to load external schema ${ uri } :` +
62+ `${ error instanceof Error ? error . message : String ( error ) } ` ) ;
63+
64+ throw error ;
65+ }
66+ } ,
67+ } ) ;
68+ const draft06MetaSchema = JSON . parse (
69+ await readFile ( AJV_SCHEMA_PATHS . draft06 , "utf-8" )
70+ ) as AnySchemaObject ;
71+ const draft07MetaSchema = JSON . parse (
72+ await readFile ( AJV_SCHEMA_PATHS . draft07 , "utf-8" )
73+ ) as AnySchemaObject ;
6774
68- ajv . addMetaSchema ( draft06MetaSchema , "http://json-schema.org/draft-06/schema#" ) ;
69- ajv . addMetaSchema ( draft07MetaSchema , "http://json-schema.org/draft-07/schema#" ) ;
75+ ajv . addMetaSchema ( draft06MetaSchema , "http://json-schema.org/draft-06/schema#" ) ;
76+ ajv . addMetaSchema ( draft07MetaSchema , "http://json-schema.org/draft-07/schema#" ) ;
7077
71- const validate = await ajv . compileAsync ( ui5Schema ) ;
78+ const validate = await ajv . compileAsync ( ui5Schema ) ;
7279
73- return validate ;
80+ return validate ;
81+ } catch ( error ) {
82+ throw new Error ( `Failed to create UI5 manifest validate function: ` +
83+ `${ error instanceof Error ? error . message : String ( error ) } ` ) ;
84+ }
7485}
7586
7687async function readManifest ( path : string ) {
0 commit comments