-
Notifications
You must be signed in to change notification settings - Fork 9
/
annotation.js
42 lines (38 loc) · 1.2 KB
/
annotation.js
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
41
42
const createLocationSchema = require('./location');
const createOriginSchema = require('./origin');
const TYPES = ['error', 'warning'];
const COMPONENTS = ['apiDescriptionParser', 'parametersValidation', 'uriTemplateExpansion'];
module.exports = function createAnnotationSchema(options = {}) {
// Either filename string or undefined (= doesn't matter)
const { filename } = options;
// options.message should be substring or RegExp
const messageSchema = { type: 'string' };
if (options.message) { messageSchema.pattern = options.message; }
return {
type: 'object',
properties: {
type: {
type: 'string',
enum: options.type ? [options.type] : TYPES
},
component: {
type: 'string',
enum: options.component ? [options.component] : COMPONENTS
},
message: messageSchema,
location: createLocationSchema(),
origin: createOriginSchema({ filename })
},
required: ['type', 'component', 'message', 'location'],
dependencies: {
origin: {
properties: {
component: {
enum: ['parametersValidation', 'uriTemplateExpansion']
}
}
}
},
additionalProperties: false
};
};