serverless-openapi-documenter 0.0.110 → 0.0.112
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,700 +1,927 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
2
|
|
|
3
|
-
const fs = require(
|
|
4
|
-
const path = require(
|
|
3
|
+
const fs = require("fs").promises;
|
|
4
|
+
const path = require("path");
|
|
5
5
|
|
|
6
|
-
const expect = require(
|
|
7
|
-
const nock = require(
|
|
6
|
+
const expect = require("chai").expect;
|
|
7
|
+
const nock = require("nock");
|
|
8
8
|
|
|
9
|
-
const modelsDocumentOG = require(
|
|
10
|
-
const modelsAltDocumentOG = require(
|
|
11
|
-
const modelsListDocumentOG = require(
|
|
12
|
-
const modelsListAltDocumentOG = require(
|
|
13
|
-
|
|
14
|
-
const serverlessMock = require('../helpers/serverless')
|
|
15
|
-
const SchemaHandler = require('../../src/schemaHandler')
|
|
9
|
+
const modelsDocumentOG = require("../models/models/models.json");
|
|
10
|
+
const modelsAltDocumentOG = require("../models/models/models-alt.json");
|
|
11
|
+
const modelsListDocumentOG = require("../models/models/modelsList.json");
|
|
12
|
+
const modelsListAltDocumentOG = require("../models/models/modelsList-alt.json");
|
|
16
13
|
|
|
14
|
+
const serverlessMock = require("../helpers/serverless");
|
|
15
|
+
const SchemaHandler = require("../../src/schemaHandler");
|
|
17
16
|
|
|
18
17
|
describe(`SchemaHandler`, function () {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
18
|
+
let mockServerless;
|
|
19
|
+
let openAPI;
|
|
20
|
+
let modelsDocument,
|
|
21
|
+
modelsAltDocument,
|
|
22
|
+
modelsListDocument,
|
|
23
|
+
modelsListAltDocument;
|
|
24
|
+
|
|
25
|
+
const logger = {
|
|
26
|
+
verbose: (str) => {
|
|
27
|
+
console.log(str);
|
|
28
|
+
},
|
|
29
|
+
warn: (str) => {
|
|
30
|
+
console.log(str);
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const v4 = new RegExp(
|
|
35
|
+
/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const openAPISchema = {
|
|
39
|
+
version: "3.0.3",
|
|
40
|
+
components: {
|
|
41
|
+
schemas: {},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
beforeEach(function () {
|
|
46
|
+
mockServerless = JSON.parse(JSON.stringify(serverlessMock));
|
|
47
|
+
modelsDocument = JSON.parse(JSON.stringify(modelsDocumentOG));
|
|
48
|
+
modelsAltDocument = JSON.parse(JSON.stringify(modelsAltDocumentOG));
|
|
49
|
+
modelsListDocument = JSON.parse(JSON.stringify(modelsListDocumentOG));
|
|
50
|
+
modelsListAltDocument = JSON.parse(JSON.stringify(modelsListAltDocumentOG));
|
|
51
|
+
openAPI = JSON.parse(JSON.stringify(openAPISchema));
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe(`constuctor`, function () {
|
|
55
|
+
it("should return an instance of SchemaHandler", function () {
|
|
56
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
57
|
+
expect(expected).to.be.an.instanceOf(SchemaHandler);
|
|
37
58
|
});
|
|
38
59
|
|
|
39
|
-
describe(`
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
60
|
+
describe(`standardising the models`, function () {
|
|
61
|
+
it(`should standardise models syntax in to the correct format`, function () {
|
|
62
|
+
Object.assign(
|
|
63
|
+
mockServerless.service.custom.documentation,
|
|
64
|
+
modelsDocument
|
|
65
|
+
);
|
|
66
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
67
|
+
|
|
68
|
+
expect(expected.models).to.be.an("array");
|
|
69
|
+
expect(expected.models.length).to.be.equal(1);
|
|
70
|
+
|
|
71
|
+
expect(expected.models[0].name).to.equal("ErrorResponse");
|
|
72
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
73
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
74
|
+
expect(expected.models[0].schema).to.be.eql({
|
|
75
|
+
type: "object",
|
|
76
|
+
properties: { error: { type: "string" } },
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it(`should standardise alternative models syntax in to the correct format`, function () {
|
|
81
|
+
Object.assign(
|
|
82
|
+
mockServerless.service.custom.documentation,
|
|
83
|
+
modelsAltDocument
|
|
84
|
+
);
|
|
85
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
86
|
+
|
|
87
|
+
expect(expected.models).to.be.an("array");
|
|
88
|
+
expect(expected.models.length).to.be.equal(1);
|
|
89
|
+
|
|
90
|
+
expect(expected.models[0].name).to.equal("ErrorResponse");
|
|
91
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
92
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
93
|
+
expect(expected.models[0].schema).to.be.eql({
|
|
94
|
+
type: "object",
|
|
95
|
+
properties: { error: { type: "string" } },
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it(`should standardise modelsList syntax in to the correct format`, function () {
|
|
100
|
+
Object.assign(
|
|
101
|
+
mockServerless.service.custom.documentation,
|
|
102
|
+
modelsListDocument
|
|
103
|
+
);
|
|
104
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
105
|
+
|
|
106
|
+
expect(expected.models).to.be.an("array");
|
|
107
|
+
expect(expected.models.length).to.be.equal(1);
|
|
108
|
+
|
|
109
|
+
expect(expected.models[0].name).to.equal("ErrorResponse");
|
|
110
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
111
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
112
|
+
expect(expected.models[0].schema).to.be.eql({
|
|
113
|
+
type: "object",
|
|
114
|
+
properties: { error: { type: "string" } },
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it(`should standardise alternative modelsList syntax in to the correct format`, function () {
|
|
119
|
+
Object.assign(
|
|
120
|
+
mockServerless.service.custom.documentation,
|
|
121
|
+
modelsListAltDocument
|
|
122
|
+
);
|
|
123
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
124
|
+
|
|
125
|
+
expect(expected.models).to.be.an("array");
|
|
126
|
+
expect(expected.models.length).to.be.equal(1);
|
|
127
|
+
|
|
128
|
+
expect(expected.models[0].name).to.equal("ErrorResponse");
|
|
129
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
130
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
131
|
+
expect(expected.models[0].schema).to.be.eql({
|
|
132
|
+
type: "object",
|
|
133
|
+
properties: { error: { type: "string" } },
|
|
43
134
|
});
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it(`should standardise mixed models syntax in to the correct format`, function () {
|
|
138
|
+
const newModelsDocument = JSON.parse(JSON.stringify(modelsDocument));
|
|
139
|
+
Object.assign(
|
|
140
|
+
mockServerless.service.custom.documentation,
|
|
141
|
+
newModelsDocument
|
|
142
|
+
);
|
|
143
|
+
mockServerless.service.custom.documentation.models.push({
|
|
144
|
+
name: "SuccessResponse",
|
|
145
|
+
description: "A success response",
|
|
146
|
+
contentType: "application/json",
|
|
147
|
+
schema: {
|
|
148
|
+
type: "string",
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
44
152
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
Object.assign(mockServerless.service.custom.documentation, modelsDocument)
|
|
48
|
-
const expected = new SchemaHandler(mockServerless, openAPI)
|
|
153
|
+
expect(expected.models).to.be.an("array");
|
|
154
|
+
expect(expected.models.length).to.be.equal(2);
|
|
49
155
|
|
|
50
|
-
|
|
51
|
-
|
|
156
|
+
expect(expected.models[0].name).to.equal("ErrorResponse");
|
|
157
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
158
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
159
|
+
expect(expected.models[0].schema).to.be.eql({
|
|
160
|
+
type: "object",
|
|
161
|
+
properties: { error: { type: "string" } },
|
|
162
|
+
});
|
|
52
163
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
164
|
+
expect(expected.models[1].name).to.equal("SuccessResponse");
|
|
165
|
+
expect(expected.models[1]).to.have.property("contentType");
|
|
166
|
+
expect(expected.models[1]).to.have.property("schema");
|
|
167
|
+
expect(expected.models[1].schema).to.be.eql({ type: "string" });
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it(`should standardise mixed modelsList syntax in to the correct format`, function () {
|
|
171
|
+
const newModelsDocument = JSON.parse(
|
|
172
|
+
JSON.stringify(modelsListDocument)
|
|
173
|
+
);
|
|
174
|
+
Object.assign(
|
|
175
|
+
mockServerless.service.custom.documentation,
|
|
176
|
+
newModelsDocument
|
|
177
|
+
);
|
|
178
|
+
mockServerless.service.custom.documentation.modelsList.push({
|
|
179
|
+
name: "SuccessResponse",
|
|
180
|
+
description: "A success response",
|
|
181
|
+
contentType: "application/json",
|
|
182
|
+
schema: {
|
|
183
|
+
type: "string",
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
58
187
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const expected = new SchemaHandler(mockServerless, openAPI)
|
|
188
|
+
expect(expected.models).to.be.an("array");
|
|
189
|
+
expect(expected.models.length).to.be.equal(2);
|
|
62
190
|
|
|
63
|
-
|
|
64
|
-
|
|
191
|
+
expect(expected.models[0].name).to.equal("ErrorResponse");
|
|
192
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
193
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
194
|
+
expect(expected.models[0].schema).to.be.eql({
|
|
195
|
+
type: "object",
|
|
196
|
+
properties: { error: { type: "string" } },
|
|
197
|
+
});
|
|
65
198
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
199
|
+
expect(expected.models[1].name).to.equal("SuccessResponse");
|
|
200
|
+
expect(expected.models[1]).to.have.property("contentType");
|
|
201
|
+
expect(expected.models[1]).to.have.property("schema");
|
|
202
|
+
expect(expected.models[1].schema).to.be.eql({ type: "string" });
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it(`should standardise mixed models and modelsList syntax in to the correct format`, function () {
|
|
206
|
+
const newModelsDocument = JSON.parse(
|
|
207
|
+
JSON.stringify(modelsListDocument)
|
|
208
|
+
);
|
|
209
|
+
Object.assign(
|
|
210
|
+
mockServerless.service.custom.documentation,
|
|
211
|
+
newModelsDocument
|
|
212
|
+
);
|
|
213
|
+
Object.assign(mockServerless.service.custom.documentation, {
|
|
214
|
+
models: [
|
|
215
|
+
{
|
|
216
|
+
name: "SuccessResponse",
|
|
217
|
+
description: "A success response",
|
|
218
|
+
contentType: "application/json",
|
|
219
|
+
schema: {
|
|
220
|
+
type: "string",
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
],
|
|
224
|
+
});
|
|
71
225
|
|
|
72
|
-
|
|
73
|
-
Object.assign(mockServerless.service.custom.documentation, modelsListDocument)
|
|
74
|
-
const expected = new SchemaHandler(mockServerless, openAPI)
|
|
226
|
+
const expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
75
227
|
|
|
76
|
-
|
|
77
|
-
|
|
228
|
+
expect(expected.models).to.be.an("array");
|
|
229
|
+
expect(expected.models.length).to.be.equal(2);
|
|
78
230
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
231
|
+
expect(expected.models[0].name).to.equal("SuccessResponse");
|
|
232
|
+
expect(expected.models[0]).to.have.property("contentType");
|
|
233
|
+
expect(expected.models[0]).to.have.property("schema");
|
|
234
|
+
expect(expected.models[0].schema).to.be.eql({ type: "string" });
|
|
84
235
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
236
|
+
expect(expected.models[1].name).to.equal("ErrorResponse");
|
|
237
|
+
expect(expected.models[1]).to.have.property("contentType");
|
|
238
|
+
expect(expected.models[1]).to.have.property("schema");
|
|
239
|
+
expect(expected.models[1].schema).to.be.eql({
|
|
240
|
+
type: "object",
|
|
241
|
+
properties: { error: { type: "string" } },
|
|
242
|
+
});
|
|
243
|
+
});
|
|
244
|
+
});
|
|
88
245
|
|
|
89
|
-
|
|
90
|
-
|
|
246
|
+
it(`should correctly resolve the RefParserOptions`, async function () {
|
|
247
|
+
let expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
248
|
+
expect(expected.refParserOptions).to.be.an("object");
|
|
249
|
+
expect(expected.refParserOptions).to.be.empty;
|
|
250
|
+
|
|
251
|
+
await fs.mkdir(path.resolve("options")).catch((err) => {
|
|
252
|
+
console.error(err);
|
|
253
|
+
throw err;
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
await fs
|
|
257
|
+
.copyFile(
|
|
258
|
+
path.resolve("test/helpers/ref-parser.js"),
|
|
259
|
+
path.resolve("options/ref-parser.js")
|
|
260
|
+
)
|
|
261
|
+
.catch((err) => {
|
|
262
|
+
console.error(err);
|
|
263
|
+
throw err;
|
|
264
|
+
});
|
|
91
265
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
expect(expected.models[0].schema).to.be.eql({type: 'object', properties: {error: {type: 'string'}}})
|
|
96
|
-
});
|
|
266
|
+
expected = new SchemaHandler(mockServerless, openAPI, logger);
|
|
267
|
+
expect(expected.refParserOptions).to.be.an("object");
|
|
268
|
+
expect(expected.refParserOptions).to.have.property("continueOnError");
|
|
97
269
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
{
|
|
103
|
-
name: 'SuccessResponse',
|
|
104
|
-
description: 'A success response',
|
|
105
|
-
contentType: 'application/json',
|
|
106
|
-
schema: {
|
|
107
|
-
type: 'string'
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
)
|
|
111
|
-
const expected = new SchemaHandler(mockServerless, openAPI)
|
|
112
|
-
|
|
113
|
-
expect(expected.models).to.be.an('array')
|
|
114
|
-
expect(expected.models.length).to.be.equal(2)
|
|
115
|
-
|
|
116
|
-
expect(expected.models[0].name).to.equal('ErrorResponse')
|
|
117
|
-
expect(expected.models[0]).to.have.property('contentType')
|
|
118
|
-
expect(expected.models[0]).to.have.property('schema')
|
|
119
|
-
expect(expected.models[0].schema).to.be.eql({type: 'object', properties: {error: {type: 'string'}}})
|
|
120
|
-
|
|
121
|
-
expect(expected.models[1].name).to.equal('SuccessResponse')
|
|
122
|
-
expect(expected.models[1]).to.have.property('contentType')
|
|
123
|
-
expect(expected.models[1]).to.have.property('schema')
|
|
124
|
-
expect(expected.models[1].schema).to.be.eql({type: 'string'})
|
|
125
|
-
});
|
|
270
|
+
await fs.rm(path.resolve("options/ref-parser.js")).catch((err) => {
|
|
271
|
+
console.error(err);
|
|
272
|
+
throw err;
|
|
273
|
+
});
|
|
126
274
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
275
|
+
await fs.rmdir(path.resolve("options")).catch((err) => {
|
|
276
|
+
console.error(err);
|
|
277
|
+
throw err;
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
describe(`addModelsToOpenAPI`, function () {
|
|
283
|
+
describe(`embedded simple schemas`, function () {
|
|
284
|
+
it(`should add the model to the openAPI schema`, async function () {
|
|
285
|
+
Object.assign(
|
|
286
|
+
mockServerless.service.custom.documentation,
|
|
287
|
+
modelsDocument
|
|
288
|
+
);
|
|
289
|
+
const schemaHandler = new SchemaHandler(
|
|
290
|
+
mockServerless,
|
|
291
|
+
openAPI,
|
|
292
|
+
logger
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
296
|
+
|
|
297
|
+
expect(schemaHandler.openAPI).to.have.property("components");
|
|
298
|
+
expect(schemaHandler.openAPI.components).to.have.property("schemas");
|
|
299
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
300
|
+
"ErrorResponse"
|
|
301
|
+
);
|
|
302
|
+
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.an(
|
|
303
|
+
"object"
|
|
304
|
+
);
|
|
305
|
+
expect(
|
|
306
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
307
|
+
).to.be.eql({
|
|
308
|
+
type: "object",
|
|
309
|
+
properties: { error: { type: "string" } },
|
|
310
|
+
});
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it(`should add a model with references to the openAPI schema`, async function () {
|
|
314
|
+
Object.assign(
|
|
315
|
+
mockServerless.service.custom.documentation,
|
|
316
|
+
modelsDocument
|
|
317
|
+
);
|
|
318
|
+
mockServerless.service.custom.documentation.models.push({
|
|
319
|
+
name: "SuccessResponse",
|
|
320
|
+
contentType: "application/json",
|
|
321
|
+
schema: {
|
|
322
|
+
type: "object",
|
|
323
|
+
properties: {
|
|
324
|
+
name: {
|
|
325
|
+
$ref: "#/definitions/nameObject",
|
|
326
|
+
},
|
|
327
|
+
},
|
|
328
|
+
definitions: {
|
|
329
|
+
nameObject: {
|
|
330
|
+
type: "object",
|
|
331
|
+
properties: {
|
|
332
|
+
firstName: {
|
|
333
|
+
type: "string",
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
},
|
|
339
|
+
});
|
|
340
|
+
const schemaHandler = new SchemaHandler(
|
|
341
|
+
mockServerless,
|
|
342
|
+
openAPI,
|
|
343
|
+
logger
|
|
344
|
+
);
|
|
345
|
+
|
|
346
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
347
|
+
|
|
348
|
+
expect(schemaHandler.openAPI).to.have.property("components");
|
|
349
|
+
expect(schemaHandler.openAPI.components).to.have.property("schemas");
|
|
350
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
351
|
+
"ErrorResponse"
|
|
352
|
+
);
|
|
353
|
+
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.an(
|
|
354
|
+
"object"
|
|
355
|
+
);
|
|
356
|
+
expect(
|
|
357
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
358
|
+
).to.be.eql({
|
|
359
|
+
type: "object",
|
|
360
|
+
properties: { error: { type: "string" } },
|
|
361
|
+
});
|
|
155
362
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
363
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
364
|
+
"SuccessResponse"
|
|
365
|
+
);
|
|
366
|
+
expect(
|
|
367
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
368
|
+
).to.be.an("object");
|
|
369
|
+
expect(
|
|
370
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
371
|
+
).to.be.eql({
|
|
372
|
+
type: "object",
|
|
373
|
+
properties: {
|
|
374
|
+
name: {
|
|
375
|
+
type: "object",
|
|
376
|
+
properties: {
|
|
377
|
+
firstName: {
|
|
378
|
+
type: "string",
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it(`should add a model with poorly dereferenced references to the openAPI schema`, async function () {
|
|
387
|
+
Object.assign(
|
|
388
|
+
mockServerless.service.custom.documentation,
|
|
389
|
+
modelsDocument
|
|
390
|
+
);
|
|
391
|
+
mockServerless.service.custom.documentation.models.push({
|
|
392
|
+
name: "SuccessResponse",
|
|
393
|
+
contentType: "application/json",
|
|
394
|
+
schema: {
|
|
395
|
+
type: "object",
|
|
396
|
+
$ref: "#/definitions/nameObject",
|
|
397
|
+
definitions: {
|
|
398
|
+
nameObject: {
|
|
399
|
+
type: "object",
|
|
400
|
+
properties: {
|
|
401
|
+
firstName: {
|
|
402
|
+
type: "string",
|
|
403
|
+
},
|
|
404
|
+
},
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
},
|
|
408
|
+
});
|
|
409
|
+
const schemaHandler = new SchemaHandler(
|
|
410
|
+
mockServerless,
|
|
411
|
+
openAPI,
|
|
412
|
+
logger
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
416
|
+
|
|
417
|
+
expect(schemaHandler.openAPI).to.have.property("components");
|
|
418
|
+
expect(schemaHandler.openAPI.components).to.have.property("schemas");
|
|
419
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
420
|
+
"ErrorResponse"
|
|
421
|
+
);
|
|
422
|
+
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.an(
|
|
423
|
+
"object"
|
|
424
|
+
);
|
|
425
|
+
expect(
|
|
426
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
427
|
+
).to.be.eql({
|
|
428
|
+
type: "object",
|
|
429
|
+
properties: { error: { type: "string" } },
|
|
190
430
|
});
|
|
191
431
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
await fs.copyFile(path.resolve('test/helpers/ref-parser.js'), path.resolve('options/ref-parser.js'))
|
|
204
|
-
.catch(err => {
|
|
205
|
-
console.error(err)
|
|
206
|
-
throw err
|
|
207
|
-
})
|
|
208
|
-
|
|
209
|
-
expected = new SchemaHandler(mockServerless, openAPI)
|
|
210
|
-
expect(expected.refParserOptions).to.be.an('object')
|
|
211
|
-
expect(expected.refParserOptions).to.have.property('continueOnError')
|
|
212
|
-
|
|
213
|
-
await fs.rm(path.resolve('options/ref-parser.js'))
|
|
214
|
-
.catch(err => {
|
|
215
|
-
console.error(err)
|
|
216
|
-
throw err
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
await fs.rmdir(path.resolve('options'))
|
|
220
|
-
.catch(err => {
|
|
221
|
-
console.error(err)
|
|
222
|
-
throw err
|
|
223
|
-
})
|
|
432
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
433
|
+
"SuccessResponse"
|
|
434
|
+
);
|
|
435
|
+
expect(
|
|
436
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
437
|
+
).to.be.an("object");
|
|
438
|
+
expect(
|
|
439
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
440
|
+
).to.be.eql({
|
|
441
|
+
type: "object",
|
|
442
|
+
properties: { firstName: { type: "string" } },
|
|
224
443
|
});
|
|
444
|
+
});
|
|
225
445
|
});
|
|
226
446
|
|
|
227
|
-
describe(`
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
447
|
+
describe(`schemas with references`, function () {
|
|
448
|
+
describe(`file references`, function () {
|
|
449
|
+
it(`should add schemas with file references to the openAPI schema`, async function () {});
|
|
450
|
+
});
|
|
451
|
+
|
|
452
|
+
describe(`component references`, function () {
|
|
453
|
+
it(`should add schemas with component references to the openAPI schema`, async function () {
|
|
454
|
+
Object.assign(
|
|
455
|
+
mockServerless.service.custom.documentation,
|
|
456
|
+
modelsDocument
|
|
457
|
+
);
|
|
458
|
+
mockServerless.service.custom.documentation.models.push({
|
|
459
|
+
name: "SuccessResponse",
|
|
460
|
+
contentType: "application/json",
|
|
461
|
+
schema: {
|
|
462
|
+
type: "array",
|
|
463
|
+
items: {
|
|
464
|
+
$ref: "#/components/schemas/Agency",
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
mockServerless.service.custom.documentation.models.push({
|
|
469
|
+
name: "Agency",
|
|
470
|
+
contentType: "application/json",
|
|
471
|
+
schema: {
|
|
472
|
+
type: "string",
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
|
|
476
|
+
const schemaHandler = new SchemaHandler(
|
|
477
|
+
mockServerless,
|
|
478
|
+
openAPI,
|
|
479
|
+
logger
|
|
480
|
+
);
|
|
481
|
+
|
|
482
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
483
|
+
|
|
484
|
+
expect(schemaHandler.openAPI).to.have.property("components");
|
|
485
|
+
expect(schemaHandler.openAPI.components).to.have.property("schemas");
|
|
486
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
487
|
+
"ErrorResponse"
|
|
488
|
+
);
|
|
489
|
+
expect(
|
|
490
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
491
|
+
).to.be.an("object");
|
|
492
|
+
expect(
|
|
493
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
494
|
+
).to.be.eql({
|
|
495
|
+
type: "object",
|
|
496
|
+
properties: { error: { type: "string" } },
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
500
|
+
"SuccessResponse"
|
|
501
|
+
);
|
|
502
|
+
expect(
|
|
503
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
504
|
+
).to.be.an("object");
|
|
505
|
+
expect(
|
|
506
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
507
|
+
).to.be.eql({
|
|
508
|
+
type: "array",
|
|
509
|
+
items: {
|
|
510
|
+
$ref: "#/components/schemas/Agency",
|
|
511
|
+
},
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
515
|
+
"Agency"
|
|
516
|
+
);
|
|
517
|
+
expect(schemaHandler.openAPI.components.schemas.Agency).to.be.an(
|
|
518
|
+
"object"
|
|
519
|
+
);
|
|
520
|
+
expect(schemaHandler.openAPI.components.schemas.Agency).to.be.eql({
|
|
521
|
+
type: "string",
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
describe(`other references`, function () {
|
|
527
|
+
it(`should add a model that is a webUrl to the openAPI schema`, async function () {
|
|
528
|
+
Object.assign(
|
|
529
|
+
mockServerless.service.custom.documentation,
|
|
530
|
+
modelsDocument
|
|
531
|
+
);
|
|
532
|
+
mockServerless.service.custom.documentation.models.push({
|
|
533
|
+
name: "SuccessResponse",
|
|
534
|
+
contentType: "application/json",
|
|
535
|
+
schema: "https://google.com/build/LicensedMember.json",
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
nock("https://google.com")
|
|
539
|
+
.get("/build/LicensedMember.json")
|
|
540
|
+
.reply(200, {
|
|
541
|
+
type: "object",
|
|
542
|
+
properties: {
|
|
543
|
+
memberId: {
|
|
544
|
+
type: "string",
|
|
545
|
+
},
|
|
546
|
+
createdAt: {
|
|
547
|
+
type: "integer",
|
|
548
|
+
},
|
|
549
|
+
},
|
|
293
550
|
});
|
|
294
551
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
552
|
+
const schemaHandler = new SchemaHandler(
|
|
553
|
+
mockServerless,
|
|
554
|
+
openAPI,
|
|
555
|
+
logger
|
|
556
|
+
);
|
|
557
|
+
|
|
558
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
559
|
+
|
|
560
|
+
expect(schemaHandler.openAPI).to.have.property("components");
|
|
561
|
+
expect(schemaHandler.openAPI.components).to.have.property("schemas");
|
|
562
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
563
|
+
"ErrorResponse"
|
|
564
|
+
);
|
|
565
|
+
expect(
|
|
566
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
567
|
+
).to.be.an("object");
|
|
568
|
+
expect(
|
|
569
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
570
|
+
).to.be.eql({
|
|
571
|
+
type: "object",
|
|
572
|
+
properties: { error: { type: "string" } },
|
|
573
|
+
});
|
|
574
|
+
|
|
575
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
576
|
+
"SuccessResponse"
|
|
577
|
+
);
|
|
578
|
+
expect(
|
|
579
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
580
|
+
).to.be.an("object");
|
|
581
|
+
expect(
|
|
582
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
583
|
+
).to.be.eql({
|
|
584
|
+
type: "object",
|
|
585
|
+
properties: {
|
|
586
|
+
memberId: {
|
|
587
|
+
type: "string",
|
|
588
|
+
},
|
|
589
|
+
createdAt: {
|
|
590
|
+
type: "integer",
|
|
591
|
+
},
|
|
592
|
+
},
|
|
593
|
+
});
|
|
334
594
|
});
|
|
335
595
|
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
596
|
+
it(`should add a complex model that is a webUrl to the openAPI schema`, async function () {
|
|
597
|
+
Object.assign(
|
|
598
|
+
mockServerless.service.custom.documentation,
|
|
599
|
+
modelsDocument
|
|
600
|
+
);
|
|
601
|
+
mockServerless.service.custom.documentation.models.push({
|
|
602
|
+
name: "SuccessResponse",
|
|
603
|
+
contentType: "application/json",
|
|
604
|
+
schema: "https://google.com/build/LicensedMember.json",
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
nock("https://google.com")
|
|
608
|
+
.get("/build/LicensedMember.json")
|
|
609
|
+
.reply(200, {
|
|
610
|
+
type: "object",
|
|
611
|
+
properties: {
|
|
612
|
+
street_address: {
|
|
613
|
+
type: "string",
|
|
614
|
+
},
|
|
615
|
+
country: {
|
|
616
|
+
default: "United States of America",
|
|
617
|
+
enum: ["United States of America", "Canada"],
|
|
618
|
+
},
|
|
619
|
+
},
|
|
620
|
+
if: {
|
|
621
|
+
properties: { country: { const: "United States of America" } },
|
|
622
|
+
},
|
|
623
|
+
then: {
|
|
624
|
+
properties: {
|
|
625
|
+
postal_code: { pattern: "[0-9]{5}(-[0-9]{4})?" },
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
else: {
|
|
629
|
+
properties: {
|
|
630
|
+
postal_code: { pattern: "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" },
|
|
631
|
+
},
|
|
632
|
+
},
|
|
341
633
|
});
|
|
342
634
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
635
|
+
const schemaHandler = new SchemaHandler(
|
|
636
|
+
mockServerless,
|
|
637
|
+
openAPI,
|
|
638
|
+
logger
|
|
639
|
+
);
|
|
640
|
+
|
|
641
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
642
|
+
|
|
643
|
+
expect(schemaHandler.openAPI).to.have.property("components");
|
|
644
|
+
expect(schemaHandler.openAPI.components).to.have.property("schemas");
|
|
645
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
646
|
+
"ErrorResponse"
|
|
647
|
+
);
|
|
648
|
+
expect(
|
|
649
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
650
|
+
).to.be.an("object");
|
|
651
|
+
expect(
|
|
652
|
+
schemaHandler.openAPI.components.schemas.ErrorResponse
|
|
653
|
+
).to.be.eql({
|
|
654
|
+
type: "object",
|
|
655
|
+
properties: { error: { type: "string" } },
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
expect(schemaHandler.openAPI.components.schemas).to.have.property(
|
|
659
|
+
"SuccessResponse"
|
|
660
|
+
);
|
|
661
|
+
expect(
|
|
662
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
663
|
+
).to.be.an("object");
|
|
664
|
+
expect(
|
|
665
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse.properties
|
|
666
|
+
).to.be.eql({
|
|
667
|
+
street_address: {
|
|
668
|
+
type: "string",
|
|
669
|
+
},
|
|
670
|
+
country: {
|
|
671
|
+
default: "United States of America",
|
|
672
|
+
enum: ["United States of America", "Canada"],
|
|
673
|
+
},
|
|
674
|
+
});
|
|
675
|
+
expect(
|
|
676
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse
|
|
677
|
+
).to.have.property("oneOf");
|
|
678
|
+
expect(
|
|
679
|
+
schemaHandler.openAPI.components.schemas.SuccessResponse.oneOf
|
|
680
|
+
.length
|
|
681
|
+
).to.be.equal(2);
|
|
682
|
+
expect(
|
|
683
|
+
Object.keys(schemaHandler.openAPI.components.schemas).length
|
|
684
|
+
).to.be.equal(3);
|
|
685
|
+
});
|
|
394
686
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
const schemaHandler = new SchemaHandler(mockServerless, openAPI)
|
|
421
|
-
|
|
422
|
-
await schemaHandler.addModelsToOpenAPI()
|
|
423
|
-
|
|
424
|
-
expect(schemaHandler.openAPI).to.have.property('components')
|
|
425
|
-
expect(schemaHandler.openAPI.components).to.have.property('schemas')
|
|
426
|
-
expect(schemaHandler.openAPI.components.schemas).to.have.property('ErrorResponse')
|
|
427
|
-
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.an('object')
|
|
428
|
-
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.eql({type: 'object', properties: {error: {type: 'string'}}})
|
|
429
|
-
|
|
430
|
-
expect(schemaHandler.openAPI.components.schemas).to.have.property('SuccessResponse')
|
|
431
|
-
expect(schemaHandler.openAPI.components.schemas.SuccessResponse).to.be.an('object')
|
|
432
|
-
expect(schemaHandler.openAPI.components.schemas.SuccessResponse).to.be.eql({
|
|
433
|
-
type: 'object',
|
|
434
|
-
properties: {
|
|
435
|
-
memberId: {
|
|
436
|
-
type: 'string'
|
|
437
|
-
},
|
|
438
|
-
createdAt: {
|
|
439
|
-
type: 'integer'
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
})
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
it(`should add a complex model that is a webUrl to the openAPI schema`, async function() {
|
|
446
|
-
Object.assign(mockServerless.service.custom.documentation, modelsDocument)
|
|
447
|
-
mockServerless.service.custom.documentation.models.push(
|
|
448
|
-
{
|
|
449
|
-
name: 'SuccessResponse',
|
|
450
|
-
contentType: 'application/json',
|
|
451
|
-
schema: 'https://google.com/build/LicensedMember.json'
|
|
452
|
-
}
|
|
453
|
-
)
|
|
454
|
-
|
|
455
|
-
nock('https://google.com')
|
|
456
|
-
.get('/build/LicensedMember.json')
|
|
457
|
-
.reply(200, {
|
|
458
|
-
"type": "object",
|
|
459
|
-
"properties": {
|
|
460
|
-
"street_address": {
|
|
461
|
-
"type": "string"
|
|
462
|
-
},
|
|
463
|
-
"country": {
|
|
464
|
-
"default": "United States of America",
|
|
465
|
-
"enum": ["United States of America", "Canada"]
|
|
466
|
-
}
|
|
467
|
-
},
|
|
468
|
-
"if": {
|
|
469
|
-
"properties": { "country": { "const": "United States of America" } }
|
|
470
|
-
},
|
|
471
|
-
"then": {
|
|
472
|
-
"properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } }
|
|
473
|
-
},
|
|
474
|
-
"else": {
|
|
475
|
-
"properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } }
|
|
476
|
-
}
|
|
477
|
-
})
|
|
478
|
-
|
|
479
|
-
const schemaHandler = new SchemaHandler(mockServerless, openAPI)
|
|
480
|
-
|
|
481
|
-
await schemaHandler.addModelsToOpenAPI()
|
|
482
|
-
|
|
483
|
-
expect(schemaHandler.openAPI).to.have.property('components')
|
|
484
|
-
expect(schemaHandler.openAPI.components).to.have.property('schemas')
|
|
485
|
-
expect(schemaHandler.openAPI.components.schemas).to.have.property('ErrorResponse')
|
|
486
|
-
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.an('object')
|
|
487
|
-
expect(schemaHandler.openAPI.components.schemas.ErrorResponse).to.be.eql({type: 'object', properties: {error: {type: 'string'}}})
|
|
488
|
-
|
|
489
|
-
expect(schemaHandler.openAPI.components.schemas).to.have.property('SuccessResponse')
|
|
490
|
-
expect(schemaHandler.openAPI.components.schemas.SuccessResponse).to.be.an('object')
|
|
491
|
-
expect(schemaHandler.openAPI.components.schemas.SuccessResponse.properties).to.be.eql({
|
|
492
|
-
"street_address": {
|
|
493
|
-
"type": "string"
|
|
494
|
-
},
|
|
495
|
-
"country": {
|
|
496
|
-
"default": "United States of America",
|
|
497
|
-
"enum": ["United States of America", "Canada"]
|
|
498
|
-
}
|
|
499
|
-
})
|
|
500
|
-
expect(schemaHandler.openAPI.components.schemas.SuccessResponse).to.have.property('oneOf')
|
|
501
|
-
expect(schemaHandler.openAPI.components.schemas.SuccessResponse.oneOf.length).to.be.equal(2)
|
|
502
|
-
expect(Object.keys(schemaHandler.openAPI.components.schemas).length).to.be.equal(3)
|
|
503
|
-
});
|
|
504
|
-
|
|
505
|
-
it(`should throw when a webUrl returns a 404`, async function() {
|
|
506
|
-
Object.assign(mockServerless.service.custom.documentation, modelsDocument)
|
|
507
|
-
mockServerless.service.custom.documentation.models.push(
|
|
508
|
-
{
|
|
509
|
-
name: 'SuccessResponse',
|
|
510
|
-
contentType: 'application/json',
|
|
511
|
-
schema: 'https://google.com/build/LicensedMember.json'
|
|
512
|
-
}
|
|
513
|
-
)
|
|
514
|
-
|
|
515
|
-
nock('https://google.com')
|
|
516
|
-
.get('/build/LicensedMember.json')
|
|
517
|
-
.reply(404, {body: 'Bad Request'})
|
|
518
|
-
|
|
519
|
-
const schemaHandler = new SchemaHandler(mockServerless, openAPI)
|
|
520
|
-
|
|
521
|
-
await schemaHandler.addModelsToOpenAPI()
|
|
522
|
-
.catch(err => {
|
|
523
|
-
expect(err).to.not.be.undefined
|
|
524
|
-
})
|
|
525
|
-
});
|
|
526
|
-
});
|
|
687
|
+
it(`should throw when a webUrl returns a 404`, async function () {
|
|
688
|
+
Object.assign(
|
|
689
|
+
mockServerless.service.custom.documentation,
|
|
690
|
+
modelsDocument
|
|
691
|
+
);
|
|
692
|
+
mockServerless.service.custom.documentation.models.push({
|
|
693
|
+
name: "SuccessResponse",
|
|
694
|
+
contentType: "application/json",
|
|
695
|
+
schema: "https://google.com/build/LicensedMember.json",
|
|
696
|
+
});
|
|
697
|
+
|
|
698
|
+
nock("https://google.com")
|
|
699
|
+
.get("/build/LicensedMember.json")
|
|
700
|
+
.reply(404, { body: "Bad Request" });
|
|
701
|
+
|
|
702
|
+
const schemaHandler = new SchemaHandler(
|
|
703
|
+
mockServerless,
|
|
704
|
+
openAPI,
|
|
705
|
+
logger
|
|
706
|
+
);
|
|
707
|
+
|
|
708
|
+
await schemaHandler.addModelsToOpenAPI().catch((err) => {
|
|
709
|
+
expect(err).to.not.be.undefined;
|
|
710
|
+
});
|
|
527
711
|
});
|
|
712
|
+
});
|
|
528
713
|
});
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
describe(`createSchema`, function () {
|
|
717
|
+
it(`returns a reference to the schema when the schema already exists in components and we don't pass through a schema`, async function () {
|
|
718
|
+
Object.assign(
|
|
719
|
+
mockServerless.service.custom.documentation,
|
|
720
|
+
modelsDocument
|
|
721
|
+
);
|
|
722
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
529
723
|
|
|
530
|
-
|
|
531
|
-
it(`returns a reference to the schema when the schema already exists in components and we don't pass through a schema`, async function() {
|
|
532
|
-
Object.assign(mockServerless.service.custom.documentation, modelsDocument)
|
|
533
|
-
const schemaHandler = new SchemaHandler(mockServerless, openAPI)
|
|
724
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
534
725
|
|
|
535
|
-
|
|
726
|
+
const expected = await schemaHandler.createSchema("ErrorResponse");
|
|
536
727
|
|
|
537
|
-
|
|
728
|
+
expect(expected).to.be.equal("#/components/schemas/ErrorResponse");
|
|
729
|
+
});
|
|
538
730
|
|
|
539
|
-
|
|
731
|
+
it(`throws an error when the name of the schema does not exist in components and we don't pass through a schema`, async function () {
|
|
732
|
+
Object.assign(
|
|
733
|
+
mockServerless.service.custom.documentation,
|
|
734
|
+
modelsDocument
|
|
735
|
+
);
|
|
736
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
737
|
+
|
|
738
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
739
|
+
|
|
740
|
+
const expected = await schemaHandler
|
|
741
|
+
.createSchema("PUTRequest")
|
|
742
|
+
.catch((err) => {
|
|
743
|
+
expect(err).to.not.be.undefined;
|
|
744
|
+
expect(err.message).to.be.equal(
|
|
745
|
+
"Expected a file path, URL, or object. Got undefined"
|
|
746
|
+
);
|
|
540
747
|
});
|
|
541
748
|
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
const schemaHandler = new SchemaHandler(mockServerless, openAPI)
|
|
749
|
+
expect(expected).to.be.undefined;
|
|
750
|
+
});
|
|
545
751
|
|
|
546
|
-
|
|
752
|
+
it(`returns a reference to a schema when the schema does not exist in components already`, async function () {
|
|
753
|
+
Object.assign(
|
|
754
|
+
mockServerless.service.custom.documentation,
|
|
755
|
+
modelsDocument
|
|
756
|
+
);
|
|
757
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
758
|
+
|
|
759
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
760
|
+
const schema = {
|
|
761
|
+
type: "object",
|
|
762
|
+
properties: {
|
|
763
|
+
createdAt: {
|
|
764
|
+
type: "number",
|
|
765
|
+
},
|
|
766
|
+
},
|
|
767
|
+
};
|
|
768
|
+
const expected = await schemaHandler
|
|
769
|
+
.createSchema("PUTRequest", schema)
|
|
770
|
+
.catch((err) => {
|
|
771
|
+
expect(err).to.be.undefined;
|
|
772
|
+
});
|
|
547
773
|
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
774
|
+
expect(expected).to.be.equal("#/components/schemas/PUTRequest");
|
|
775
|
+
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(
|
|
776
|
+
schema
|
|
777
|
+
);
|
|
778
|
+
});
|
|
553
779
|
|
|
554
|
-
|
|
780
|
+
it(`returns a reference to a schema when the schema exists in components already and the same schema is being passed through`, async function () {
|
|
781
|
+
Object.assign(
|
|
782
|
+
mockServerless.service.custom.documentation,
|
|
783
|
+
modelsDocument
|
|
784
|
+
);
|
|
785
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
786
|
+
|
|
787
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
788
|
+
const schema = {
|
|
789
|
+
type: "object",
|
|
790
|
+
properties: {
|
|
791
|
+
createdAt: {
|
|
792
|
+
type: "number",
|
|
793
|
+
},
|
|
794
|
+
},
|
|
795
|
+
};
|
|
796
|
+
let expected = await schemaHandler
|
|
797
|
+
.createSchema("PUTRequest", schema)
|
|
798
|
+
.catch((err) => {
|
|
799
|
+
expect(err).to.be.undefined;
|
|
555
800
|
});
|
|
556
801
|
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
802
|
+
expect(expected).to.be.equal("#/components/schemas/PUTRequest");
|
|
803
|
+
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(
|
|
804
|
+
schema
|
|
805
|
+
);
|
|
560
806
|
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
createdAt: {
|
|
566
|
-
type: 'number'
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
const expected = await schemaHandler.createSchema('PUTRequest', schema)
|
|
571
|
-
.catch(err => {
|
|
572
|
-
expect(err).to.be.undefined
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
expect(expected).to.be.equal('#/components/schemas/PUTRequest')
|
|
576
|
-
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(schema)
|
|
807
|
+
expected = await schemaHandler
|
|
808
|
+
.createSchema("PUTRequest", schema)
|
|
809
|
+
.catch((err) => {
|
|
810
|
+
expect(err).to.be.undefined;
|
|
577
811
|
});
|
|
578
812
|
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
813
|
+
expect(expected).to.be.equal("#/components/schemas/PUTRequest");
|
|
814
|
+
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(
|
|
815
|
+
schema
|
|
816
|
+
);
|
|
817
|
+
});
|
|
582
818
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
})
|
|
604
|
-
|
|
605
|
-
expect(expected).to.be.equal('#/components/schemas/PUTRequest')
|
|
606
|
-
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(schema)
|
|
819
|
+
it(`returns a reference to a new schema when the schema exists in components already and a different schema is being passed through`, async function () {
|
|
820
|
+
Object.assign(
|
|
821
|
+
mockServerless.service.custom.documentation,
|
|
822
|
+
modelsDocument
|
|
823
|
+
);
|
|
824
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
825
|
+
|
|
826
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
827
|
+
const schema = {
|
|
828
|
+
type: "object",
|
|
829
|
+
properties: {
|
|
830
|
+
createdAt: {
|
|
831
|
+
type: "number",
|
|
832
|
+
},
|
|
833
|
+
},
|
|
834
|
+
};
|
|
835
|
+
let expected = await schemaHandler
|
|
836
|
+
.createSchema("PUTRequest", schema)
|
|
837
|
+
.catch((err) => {
|
|
838
|
+
expect(err).to.be.undefined;
|
|
607
839
|
});
|
|
608
840
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
expect(expected).to.be.equal('#/components/schemas/PUTRequest')
|
|
628
|
-
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(schema)
|
|
629
|
-
|
|
630
|
-
const differentSchema = {
|
|
631
|
-
type: 'object',
|
|
632
|
-
properties: {
|
|
633
|
-
updatedAt: {
|
|
634
|
-
type: 'number'
|
|
635
|
-
}
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
expected = await schemaHandler.createSchema('PUTRequest', differentSchema)
|
|
640
|
-
.catch(err => {
|
|
641
|
-
expect(err).to.be.undefined
|
|
642
|
-
})
|
|
643
|
-
|
|
644
|
-
const splitPath = expected.split('/')
|
|
645
|
-
expect(v4.test(splitPath[3].split('PUTRequest-')[1])).to.be.true
|
|
646
|
-
expect(expected).to.be.equal(`#/components/schemas/${splitPath[3]}`)
|
|
647
|
-
expect(schemaHandler.openAPI.components.schemas[splitPath[3]]).to.be.eql(differentSchema)
|
|
841
|
+
expect(expected).to.be.equal("#/components/schemas/PUTRequest");
|
|
842
|
+
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(
|
|
843
|
+
schema
|
|
844
|
+
);
|
|
845
|
+
|
|
846
|
+
const differentSchema = {
|
|
847
|
+
type: "object",
|
|
848
|
+
properties: {
|
|
849
|
+
updatedAt: {
|
|
850
|
+
type: "number",
|
|
851
|
+
},
|
|
852
|
+
},
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
expected = await schemaHandler
|
|
856
|
+
.createSchema("PUTRequest", differentSchema)
|
|
857
|
+
.catch((err) => {
|
|
858
|
+
expect(err).to.be.undefined;
|
|
648
859
|
});
|
|
649
860
|
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
861
|
+
const splitPath = expected.split("/");
|
|
862
|
+
expect(v4.test(splitPath[3].split("PUTRequest-")[1])).to.be.true;
|
|
863
|
+
expect(expected).to.be.equal(`#/components/schemas/${splitPath[3]}`);
|
|
864
|
+
expect(schemaHandler.openAPI.components.schemas[splitPath[3]]).to.be.eql(
|
|
865
|
+
differentSchema
|
|
866
|
+
);
|
|
867
|
+
});
|
|
653
868
|
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
869
|
+
it(`returns a reference to a new schema when the schema passed through is a URL`, async function () {
|
|
870
|
+
Object.assign(
|
|
871
|
+
mockServerless.service.custom.documentation,
|
|
872
|
+
modelsDocument
|
|
873
|
+
);
|
|
874
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
875
|
+
|
|
876
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
877
|
+
const schema = "https://google.com/build/LicensedMember.json";
|
|
878
|
+
const schemaObj = {
|
|
879
|
+
type: "object",
|
|
880
|
+
properties: {
|
|
881
|
+
name: {
|
|
882
|
+
type: "string",
|
|
883
|
+
},
|
|
884
|
+
address: {
|
|
885
|
+
type: "string",
|
|
886
|
+
},
|
|
887
|
+
},
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
nock("https://google.com")
|
|
891
|
+
.get("/build/LicensedMember.json")
|
|
892
|
+
.reply(200, schemaObj);
|
|
893
|
+
|
|
894
|
+
let expected = await schemaHandler
|
|
895
|
+
.createSchema("PUTRequest", schema)
|
|
896
|
+
.catch((err) => {
|
|
897
|
+
expect(err).to.be.undefined;
|
|
679
898
|
});
|
|
680
899
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
900
|
+
expect(expected).to.be.equal("#/components/schemas/PUTRequest");
|
|
901
|
+
expect(schemaHandler.openAPI.components.schemas.PUTRequest).to.be.eql(
|
|
902
|
+
schemaObj
|
|
903
|
+
);
|
|
904
|
+
});
|
|
684
905
|
|
|
685
|
-
|
|
686
|
-
|
|
906
|
+
it(`should throw an error when a schema as a URL can not be resolved correctly`, async function () {
|
|
907
|
+
Object.assign(
|
|
908
|
+
mockServerless.service.custom.documentation,
|
|
909
|
+
modelsDocument
|
|
910
|
+
);
|
|
911
|
+
const schemaHandler = new SchemaHandler(mockServerless, openAPI, logger);
|
|
687
912
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
.reply(404)
|
|
913
|
+
await schemaHandler.addModelsToOpenAPI();
|
|
914
|
+
const schema = "https://google.com/build/LicensedMember.json";
|
|
691
915
|
|
|
692
|
-
|
|
693
|
-
.catch(err => {
|
|
694
|
-
expect(err).to.not.undefined
|
|
695
|
-
})
|
|
916
|
+
nock("https://google.com").get("/build/LicensedMember.json").reply(404);
|
|
696
917
|
|
|
697
|
-
|
|
918
|
+
let expected = await schemaHandler
|
|
919
|
+
.createSchema("PUTRequest", schema)
|
|
920
|
+
.catch((err) => {
|
|
921
|
+
expect(err).to.not.undefined;
|
|
698
922
|
});
|
|
923
|
+
|
|
924
|
+
expect(expected).to.be.undefined;
|
|
699
925
|
});
|
|
926
|
+
});
|
|
700
927
|
});
|