Unverified Commit 02a35ba9 authored by Dan Jones's avatar Dan Jones
Browse files

test: js validation of examples and schema

I've updated the messages and schemas so that all
messages pass validation with the js validator
parent 6dd0ac37
......@@ -126,8 +126,7 @@
"swath_width": 10
}
}
],
"region_of_interest": {}
]
},
{
"squad_ID": 3,
......@@ -153,8 +152,7 @@
"scan_type": "MBES"
}
}
],
"region_of_interest": {}
]
}
]
}
......
......@@ -22,7 +22,6 @@
"longitude": -11.122,
"quality_of_point": 0.50
}
],
"region_surveyed": ""
]
}
}
\ No newline at end of file
......@@ -47,7 +47,6 @@
"platform_ID": "reav-60-1",
"serial": "reav-60",
"emergency": {
"additional_data": {},
"target_waypoint_latitude": -7.432,
"target_waypoint_longitude": 50.365,
"safe_command": "go_home",
......@@ -55,8 +54,7 @@
},
"max_velocity": 0.9,
"min_altitude": 15.2,
"min_velocity": 0.1,
"additional_data": {}
"min_velocity": 0.1
}
],
"region_of_interest": {
......@@ -93,7 +91,6 @@
"serial": "ecosub-2",
"model": "ecosub",
"emergency": {
"additional_data": {},
"target_waypoint_latitude": -7.432,
"target_waypoint_longitude": 50.365,
"safe_command": "go_home",
......@@ -126,8 +123,7 @@
"swath_width": 10
}
}
],
"region_of_interest": {}
]
},
{
"squad_ID": 3,
......@@ -153,8 +149,7 @@
"scan_type": "MBES"
}
}
],
"region_of_interest": {}
]
}
]
}
......
......@@ -9,6 +9,7 @@ acknowledgement_schema = {
"type": "string",
"description": "Type of message",
"example": "acknowledgement",
"enum": ["acknowledgement"],
},
"autonomy_engine_plan_ID": {
"type": "integer",
......
......@@ -81,6 +81,7 @@ mission_plan_schema = {
"type": "string",
"description": "Type of message",
"example": "mission_plan",
"enum": ["mission_plan"],
},
"autonomy_engine_plan_ID": {
"type": "integer",
......
......@@ -36,6 +36,7 @@ observation_schema = {
"type": "string",
"description": "Type of message",
"example": "observation",
"enum": ["observation"],
},
"platform_ID": {
"type": "string",
......
......@@ -84,6 +84,7 @@ platform_schema = {
"additional_specs": {
"description": "Any addition fields/data to be added here",
"example": {"swath_width": 10.0, "scan_type": "DVL"},
"type": "object",
},
},
"required": [
......@@ -163,6 +164,7 @@ planning_configuration_schema = {
"type": "string",
"description": "Type of message",
"example": "planning_configuration",
"enum": ["planning_configuration"],
},
"planning_config_ID": {
"type": "integer",
......
......@@ -32,6 +32,7 @@ platform_status_schema = {
"type": "string",
"description": "Type of message",
"example": "platform_status",
"enum": ["platform_status"],
},
"platform_ID": {
"type": "string",
......
......@@ -31,8 +31,9 @@
"message_type":{
"description":"Type of message",
"example":"acknowledgement",
"type":"string"
},
"type":"string",
"enum": ["acknowledgement"]
},
"platform_ID":{
"description":"Unique identifier for this platform",
"example":"reav-x-1",
......@@ -107,7 +108,8 @@
"message_type":{
"description":"Type of message",
"example":"mission_plan",
"type":"string"
"type":"string",
"enum": ["mission_plan"]
},
"plan":{
"items":{
......@@ -202,7 +204,8 @@
"message_type":{
"description":"Type of message",
"example":"observation",
"type":"string"
"type":"string",
"enum": ["observation"]
},
"platform_ID":{
"description":"Unique identifier for this platform",
......@@ -319,7 +322,8 @@
"message_type":{
"description":"Type of message",
"example":"planning_configuration",
"type":"string"
"type":"string",
"enum": ["planning_configuration"]
},
"planning_config_ID":{
"description":"Unique identifier tagged to version of this configuration plan",
......@@ -351,7 +355,8 @@
"description":"Any addition fields/data to be added here",
"example":{
}
},
"type":"object"
},
"safe_command":{
"description":"Command/Action that is native to respective partner's platform/C2",
......@@ -569,7 +574,8 @@
"message_type":{
"description":"Type of message",
"example":"platform_status",
"type":"string"
"type":"string",
"enum": ["platform_status"]
},
"mission_plan_ID":{
"description":"Mission plan ID according to platform-C2 system",
......
node_modules/
\ No newline at end of file
FROM node:18.7.0-alpine
WORKDIR /app/tests-js
COPY tests-js/package.json /app/tests-js/package.json
RUN yarn install
WORKDIR /app
COPY . /app
WORKDIR /app/tests-js
CMD [ 'yarn', 'test' ]
version: '3.8'
services:
soar_js_test:
build:
context: ../..
dockerfile: tests-js/docker/Dockerfile
container_name: soar_js_test
volumes:
- ../../:/app
command: "yarn test"
{
"scripts": {
"test": "jest"
},
"devDependencies": {
"glob": "^9.1.2",
"jest": "^27.4.4",
"openapi-schema-validator": "^12.1.0",
"swagger-model-validator": "^3.0.21"
}
}
const { globSync } = require('glob');
const Validator = require('swagger-model-validator');
const OpenAPISchemaValidator = require('openapi-schema-validator').default;
const getSchema = () => {
const schema = require(`${__dirname}/../projects/soar/swagger.json`);
return schema;
};
const validateSchema = (schema) => {
const validator = new OpenAPISchemaValidator({ version: 3 });
let validation = validator.validate(schema);
validation.valid = (validation.errors.length === 0);
return validation;
};
const validateMessage = (message, schema, model='MESSAGE') => {
let validator = new Validator(schema);
let validation = validator.validate(
message,
schema.components.schemas[model],
schema.components.schemas,
false,
false
);
return validation;
};
test('schema validates', () => {
let schema = getSchema();
let schemaValidation = validateSchema(schema);
expect(schemaValidation.valid).toBe(true);
});
describe('examples validate', () => {
let schema = getSchema();
let validation, payloadValidation;
let valid;
let message;
let messages = globSync(`${__dirname}/../examples/**/*.json`)
console.log('examples', messages);
messages.forEach(messageFile => {
test(`validate ${messageFile}`, () => {
message = require(messageFile);
validation = validateMessage(message, schema);
valid = validation.valid;
if (!valid) {
console.log(`validation: ${messageFile}`, validation);
payloadValidation = validateMessage(message.payload, schema, message.payload.message_type)
console.log(`payload ${message.payload.message_type}`, payloadValidation);
}
expect(valid).toBe(true);
});
});
});
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment