forked from opensearch-project/opensearch-api-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpecValidator.ts
36 lines (32 loc) · 1.33 KB
/
SpecValidator.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
import SchemasFolder from './components/SchemasFolder'
import NamespacesFolder from './components/NamespacesFolder'
import RootFile from './components/RootFile'
import { type ValidationError } from '../types'
import PathRefsValidator from './PathRefsValidator'
import SchemaRefsValidator from './SchemaRefsValidator'
export default class SpecValidator {
root_file: RootFile
namespaces_folder: NamespacesFolder
schemas_folder: SchemasFolder
path_refs_validator: PathRefsValidator
schema_refs_validator: SchemaRefsValidator
constructor (root_folder: string) {
this.root_file = new RootFile(`${root_folder}/opensearch-openapi.yaml`)
this.namespaces_folder = new NamespacesFolder(`${root_folder}/namespaces`)
this.schemas_folder = new SchemasFolder(`${root_folder}/schemas`)
this.path_refs_validator = new PathRefsValidator(this.root_file, this.namespaces_folder)
this.schema_refs_validator = new SchemaRefsValidator(this.namespaces_folder, this.schemas_folder)
}
validate (): ValidationError[] {
const component_errors = [
...this.root_file.validate(),
...this.namespaces_folder.validate(),
...this.schemas_folder.validate()
]
if (component_errors.length) return component_errors
return [
...this.path_refs_validator.validate(),
...this.schema_refs_validator.validate()
]
}
}