-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.js
64 lines (50 loc) · 1.23 KB
/
spec.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Schema environment.
*/
'use strict';
/* jshint camelcase: false */
/**
* Module dependencies.
*/
var lodash = require('lodash');
var spec = require('swagger-spec');
var Environment = require('./environment');
/**
* Schema
*/
var env = new Environment();
spec.v1_2.forEach(function(s) {
var path = 'http://wordnik.github.io/schemas/v1.2/';
// remove path prefix
if (s.id.slice(0, path.length) === path) {
s.id = s.id.slice(path.length);
}
// strip trailing hash
if (s.id[s.id.length - 1] === '#') {
s.id = s.id.slice(0, s.id.length - 1);
}
switch (s.id) {
case 'apiDeclaration.json':
var apiObject = lodash.cloneDeep(s.definitions.apiObject);
apiObject.required = apiObject.required.filter(function(v) {
return v !== 'operations';
});
env.addSchema('ApiDeclaration', s);
env.addSchema('ApiObject', apiObject);
break;
case 'modelsObject.json':
env.addSchema('ModelObject', s);
break;
case 'operationObject.json':
env.addSchema('OperationObject', s);
break;
case 'resourceListing.json':
env.addSchema('ResourceListing', s);
break;
}
env.addSchema(s.id, s);
});
/**
* Expose spec schema.
*/
module.exports = env;