Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/components/Dialogs/ContributeToCatalogDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const VALIDATION_TM_JSON =
"https://raw.githubusercontent.com/wot-oss/tmc/main/internal/commands/validate/tm-json-schema-validation.json";
const VALIDATION_MODBUS =
"https://raw.githubusercontent.com/wot-oss/tmc/refs/heads/main/internal/commands/validate/modbus.schema.json";
const VALIDATION_MODBUS_OLD =
"https://raw.githubusercontent.com/wot-oss/tmc/main/internal/commands/validate/modbus-old.schema.json";

const ContributeToCatalogDialog = forwardRef((props, ref) => {
const context = useContext(ediTDorContext);
Expand Down Expand Up @@ -286,6 +288,19 @@ const ContributeToCatalogDialog = forwardRef((props, ref) => {
throw new Error(message);
}

response = await fetch(VALIDATION_MODBUS_OLD);
if (!response.ok)
throw new Error(`Failed to fetch schema from ${VALIDATION_MODBUS_OLD}`);
schema = await response.json();
validate = ajv.compile(schema);
valid = validate(tdTransformed);
if (!valid) {
let message = `Validation failed for ${VALIDATION_MODBUS_OLD}: ${
validate.errors ? ajv.errorsText(validate.errors) : ""
}`;
throw new Error(message);
}

dispatch({ type: "SET_BACKGROUND_TD_TO_SEND", payload: tdTransformed });
dispatch({ type: "SET_METADATA_ERROR_MESSAGE", payload: "" });
dispatch({ type: "SET_METADATA_VALIDATION", payload: "VALID" });
Expand Down