-
-
Notifications
You must be signed in to change notification settings - Fork 155
/
validate.ts
40 lines (33 loc) · 1.37 KB
/
validate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { Args } from '@oclif/core';
import Command from '../core/base';
import { validate, ValidateOptions, ValidationStatus, parse } from '../core/parser';
import { load } from '../core/models/SpecificationFile';
import { specWatcher } from '../core/globals';
import { validateFlags } from '../core/flags/validate.flags';
import { calculateScore } from '../core/utils/scoreCalculator';
export default class Validate extends Command {
static description = 'validate asyncapi file';
static flags = validateFlags();
static args = {
'spec-file': Args.string({description: 'spec path, url, or context-name', required: false}),
};
async run() {
const { args, flags } = await this.parse(Validate); //NOSONAR
const filePath = args['spec-file'];
const watchMode = flags.watch;
if (flags['score']) {
this.specFile = await load(filePath);
const { document } = await parse(this,this.specFile);
this.log(`The score of the asyncapi document is ${await calculateScore(document)}`);
}
this.specFile = await load(filePath);
if (watchMode) {
specWatcher({ spec: this.specFile, handler: this, handlerName: 'validate' });
}
const result = await validate(this, this.specFile, flags as ValidateOptions);
this.metricsMetadata.validation_result = result;
if (result === ValidationStatus.INVALID) {
process.exitCode = 1;
}
}
}