yaml-validator
yaml-validator copied to clipboard
Structure Validation does not work
Expected behaviour
options.structure should get considered by validator see bottom of this ticket, change e.g. description from string to number -> no effect
Actual behaviour
using options.structure with a structure object always works
report() always returns 1 and no warning gets printed out
Versions and environment
- Operating system: MacOSx
- Node.js: 10.15.3
- npm: 6.4.1
- yaml-validator: ^2.2.0
Thank you and have some :grapes:.
api.yml
globals:
consumer:
- event: "#/definitions/Register"
- event: "#/definitions/Next"
- event: "#/definitions/Previous"
- event: "#/definitions/Destroy"
producer:
- event: "#/definitions/Initialize"
apps:
- name: "login"
consumer:
- event: "#/definitions/Register"
- event: "#/definitions/Next"
- event: "#/definitions/Destroy"
producer:
definitions:
- event: "Register"
name: "[Registration] register"
description: "MF registers itself at the CL"
- event: "Next"
name: "[Routing] next"
description: "MF tells the CL to route to the next MF"
- event: "Previous"
name: "[Routing] previous"
description: "MF tells the CL to route to the previous MF"
- event: "Initialize"
name: "[Lifecycle] initialize"
description: "CL may send the MF a configuration and/or a state (e.g. previous state - for-/backwards-navigation)"
payload:
- name: "config"
type: "any"
- name: "state"
type: "any"
- event: "Destroy"
name: "[Lifecycle] destroy"
description: "MF tells the CL that it has been destroyed and may pass the (latest) state"
payload:
- name: "state"
type: "any"
api-schemal.validator.ts
import * as YamlValidator from 'yaml-validator';
export class ApiSchemaValidator {
static structure = {
globals: {
consumer: [{ event: 'string' }],
producer: [{ event: 'string' }],
},
apps: [
{
name: 'string',
consumer: [{ event: 'string' }],
producer: [{ event: 'string' }],
},
],
definitions: [
{
event: 'string',
name: 'string',
description: 'string',
'payload?': [
{
name: 'string',
type: 'string',
},
],
},
],
};
options: YamlValidator.IYamlValidatorOptions = {
log: false,
structure: ApiSchemaValidator.structure,
onWarning: (error, filepath) => {
console.warn(filepath + ' has error: ' + error);
},
writeJson: false,
};
validate(file: string): number {
console.log(`Validating ${file}...`);
// console.log(JSON.stringify(this.options));
const validator = new YamlValidator(this.options);
validator.validate([file]);
return validator.report();
}
}
In addition, correct schema is wrongly validated as false.
E.g. adding events to producer below:
apps:
- name: "login"
consumer:
- event: "#/definitions/Register"
- event: "#/definitions/Next"
- event: "#/definitions/Destroy"
producer:
Thanks for the issue. Would you be willing to add these test cases to the unit tests via PR?
Hi @paazmaya : I'm going to take another path and won't pursue yaml-validator anymore. I'm sorry.
Any success here, I have same issue with schema validation :( yaml file:
VRO.PLUGINS.USAGE.VCACCAFE: description: n/a weight: 0 impact: '' VRO.PLUGINS.USAGE.VCACCAFEINFRASTRUCTURE: weight: 0 impact: '' remedy: '[TBD]' CONTENT.COE: description: n/a weight: 0 impact: '' remedy: '[TBD]' CONTENT.SOVLABS: description: n/a weight: 0 impact: '' remedy: '[TBD]'
current configuration
const options = {
log: 'false',
structure: {
'id?': {
'description!': 'string',
'weight!': 'number',
'impact!': 'string',
'remedy!': 'string'
}
},
onWarning: undefined,
writeJson: false
};
const validator = new YamlValidator(options);
validator.validate([yamlFile]);
First record is missing "description", second one missing: "remedy".
If we have duplicate key it's working, but if something is missing from YAML file it's saying no errrors.