Skip to content

Commit 400e5c9

Browse files
committed
validate
1 parent 4c8dd3b commit 400e5c9

File tree

1 file changed

+26
-10
lines changed
  • services/static-webserver/client/source/class/osparc/store

1 file changed

+26
-10
lines changed

services/static-webserver/client/source/class/osparc/store/Products.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
/**
1919
* @asset(osparc/ui_config.json")
20-
* @asset(form/product-ui.json)
20+
* @asset(schemas/product-ui.json)
2121
* @asset(object-path/object-path-0-11-4.min.js)
2222
* @asset(ajv/ajv-6-11-0.min.js)
2323
* @ignore(Ajv)
@@ -40,7 +40,7 @@ qx.Class.define("osparc.store.Products", {
4040
Promise.all([
4141
osparc.data.Resources.fetch("productMetadata", "getUiConfig"),
4242
osparc.utils.Utils.fetchJSON("/resource/osparc/ui_config.json"),
43-
osparc.utils.Utils.fetchJSON("/resource/form/product-ui.json"),
43+
osparc.utils.Utils.fetchJSON("/resource/schemas/product-ui.json"),
4444
])
4545
.then(values => {
4646
let uiConfig = {};
@@ -52,24 +52,40 @@ qx.Class.define("osparc.store.Products", {
5252
uiConfig = values[1][product];
5353
}
5454
}
55-
const schema = values[2];
55+
// const schema = values[2];
56+
const schema = {
57+
"type": "object",
58+
"properties": {
59+
"resourceType": { "type": "string" },
60+
"title": { "type": "string" },
61+
"icon": { "type": "string" },
62+
"newStudyLabel": { "type": "string" },
63+
"idToWidget": { "type": "string" }
64+
},
65+
"required": ["resourceType", "title"],
66+
};
5667
const ajvLoader = new qx.util.DynamicScriptLoader([
5768
"/resource/ajv/ajv-6-11-0.min.js",
5869
"/resource/object-path/object-path-0-11-4.min.js"
5970
]);
6071
ajvLoader.addListener("ready", () => {
61-
this.__ajv = new Ajv();
62-
if (this.__validate(schema.$schema, schema)) {
63-
// Schema is valid
64-
if (this.__validate(schema, uiConfig)) {
65-
// Validate data if present
66-
this.__uiConfig = uiConfig;
67-
}
72+
const ajv = new Ajv({
73+
allErrors: true,
74+
strictDefaults: true,
75+
useDefaults: true,
76+
});
77+
const validate = ajv.compile(schema);
78+
const valid = validate(uiConfig);
79+
if (valid) {
80+
// Validate data if present
81+
this.__uiConfig = uiConfig;
6882
resolve(this.__uiConfig);
6983
} else {
7084
console.error("wrong ui_config")
7185
}
7286
});
87+
ajvLoader.addListener("failed", console.error, this);
88+
ajvLoader.start();
7389
})
7490
.catch(console.error);
7591
});

0 commit comments

Comments
 (0)