Skip to content

Commit

Permalink
Load _version schema. Validate using 'attributes' as JSON root
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Sep 27, 2024
1 parent 1d55e98 commit c0374f5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export async function getSchema(schemaUrl) {
}

export function getVersion(ngffData) {
console.log("getVersion...", ngffData, 'attributes?', ngffData.attributes)
// console.log("getVersion...", ngffData, 'attributes?', ngffData.attributes)
// if we have attributes.ome then this is version 0.5+
if (ngffData.attributes?.ome) {
if (ngffData.attributes.ome.version) {
Expand Down Expand Up @@ -267,16 +267,22 @@ export async function validate(jsonData) {
// TODO: need to know whether to load other schemas...
// For now, we can use version check...
if (version === "0.5") {
// const ctSchema = await getSchema(version, "coordinate_transformation");
// const csSchema = await getSchema(version, "coordinate_systems");
const versionSchema = await getSchema(getSchemaUrl("version", version));
const versionSchema = await getSchema(getSchemaUrl("_version", version));
// const schemaSchema = await getSchema(getSchemaUrl("_schema_url", version));
refSchemas = [versionSchema];
}
let errors = [];
for (let s=0; s<schemaUrls.length; s++) {
let schema = await getSchema(schemaUrls[s]);
let errs = validateData(schema, jsonData, refSchemas);
errors = errors.concat(errs);
if (jsonData.attributes) {
for (let s=0; s<schemaUrls.length; s++) {
let schema = await getSchema(schemaUrls[s]);
let errs = validateData(schema, jsonData.attributes, refSchemas);
errors = errors.concat(errs);
}
} else {
errors.push("No 'attributes' key found in JSON data");
}
if (errors.length > 0) {
console.log("Validation errors", errors, jsonData);
}
return errors;
}
Expand Down

0 comments on commit c0374f5

Please sign in to comment.