serverless-openapi-documenter 0.0.97 → 0.0.101

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,629 +1,791 @@
1
- 'use strict'
2
-
3
- const fs = require('fs').promises
4
- const path = require('path')
5
- const expect = require('chai').expect
6
-
7
- const serverlessMock = require('../helpers/serverless')
8
- const modelsDocument = require('../models/models/models.json')
9
- const DefinitionGenerator = require('../../src/definitionGenerator')
10
-
11
- describe('DefinitionGenerator', () => {
12
- let mockServerless
13
- const v4 = new RegExp(/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i);
14
- beforeEach(function() {
15
- mockServerless = JSON.parse(JSON.stringify(serverlessMock))
16
- Object.assign(mockServerless.service.custom.documentation, modelsDocument)
1
+ "use strict";
2
+
3
+ const fs = require("fs").promises;
4
+ const path = require("path");
5
+ const expect = require("chai").expect;
6
+
7
+ const serverlessMock = require("../helpers/serverless");
8
+ const modelsDocument = require("../models/models/models.json");
9
+ const DefinitionGenerator = require("../../src/definitionGenerator");
10
+
11
+ describe("DefinitionGenerator", () => {
12
+ let mockServerless;
13
+ const v4 = new RegExp(
14
+ /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i
15
+ );
16
+
17
+ beforeEach(function () {
18
+ mockServerless = JSON.parse(JSON.stringify(serverlessMock));
19
+ Object.assign(mockServerless.service.custom.documentation, modelsDocument);
20
+ });
21
+
22
+ after(function () {
23
+ delete require
24
+ .cache[require.resolve(`${path.resolve("options")}/redocly.json`)];
25
+ });
26
+
27
+ describe("constructor", () => {
28
+ it("should return a definitionGenerator", function () {
29
+ const expected = new DefinitionGenerator(mockServerless, {});
30
+ expect(expected).to.be.an.instanceOf(DefinitionGenerator);
17
31
  });
18
32
 
19
- describe('constructor', () => {
20
- it('should return a definitionGenerator', function() {
21
- const expected = new DefinitionGenerator(mockServerless, {})
22
- expect(expected).to.be.an.instanceOf(DefinitionGenerator)
23
- });
24
-
25
- it('should default to version 3.0.0 of openAPI when openAPI version is not passed in', function() {
26
- const serverlessWithoutOpenAPIVersion = JSON.parse(JSON.stringify(mockServerless))
27
- delete serverlessWithoutOpenAPIVersion.processedInput;
28
- let expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
29
- expect(expected.version).to.be.equal('3.0.0')
30
-
31
- Object.assign(serverlessWithoutOpenAPIVersion, {processedInput: {}})
32
- expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
33
- expect(expected.version).to.be.equal('3.0.0')
34
-
35
- serverlessWithoutOpenAPIVersion.processedInput = {
36
- options: {}
37
- }
38
- expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
39
- expect(expected.version).to.be.equal('3.0.0')
40
-
41
- serverlessWithoutOpenAPIVersion.processedInput.options = {
42
- test: 'abc'
43
- }
44
-
45
- expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
46
- expect(expected.version).to.be.equal('3.0.0')
47
-
48
- serverlessWithoutOpenAPIVersion.processedInput.options = {
49
- openApiVersion: null
50
- }
51
-
52
- expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
53
- expect(expected.version).to.be.equal('3.0.0')
33
+ it("should default to version 3.0.0 of openAPI when openAPI version is not passed in", function () {
34
+ const serverlessWithoutOpenAPIVersion = JSON.parse(
35
+ JSON.stringify(mockServerless)
36
+ );
37
+ delete serverlessWithoutOpenAPIVersion.processedInput;
38
+ let expected = new DefinitionGenerator(
39
+ serverlessWithoutOpenAPIVersion,
40
+ {}
41
+ );
42
+ expect(expected.version).to.be.equal("3.0.0");
43
+
44
+ Object.assign(serverlessWithoutOpenAPIVersion, { processedInput: {} });
45
+ expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {});
46
+ expect(expected.version).to.be.equal("3.0.0");
47
+
48
+ serverlessWithoutOpenAPIVersion.processedInput = {
49
+ options: {},
50
+ };
51
+ expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {});
52
+ expect(expected.version).to.be.equal("3.0.0");
53
+
54
+ serverlessWithoutOpenAPIVersion.processedInput.options = {
55
+ test: "abc",
56
+ };
57
+
58
+ expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {});
59
+ expect(expected.version).to.be.equal("3.0.0");
60
+
61
+ serverlessWithoutOpenAPIVersion.processedInput.options = {
62
+ openApiVersion: null,
63
+ };
64
+
65
+ expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {});
66
+ expect(expected.version).to.be.equal("3.0.0");
67
+
68
+ serverlessWithoutOpenAPIVersion.processedInput.options = {
69
+ openApiVersion: undefined,
70
+ };
71
+
72
+ expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {});
73
+ expect(expected.version).to.be.equal("3.0.0");
74
+
75
+ serverlessWithoutOpenAPIVersion.processedInput.options = {
76
+ openapiVersion: undefined,
77
+ };
78
+
79
+ expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {});
80
+ expect(expected.version).to.be.equal("3.0.0");
81
+ });
54
82
 
55
- serverlessWithoutOpenAPIVersion.processedInput.options = {
56
- openApiVersion: undefined
57
- }
83
+ it("should respect the version of openAPI when passed in", function () {
84
+ const serverlessWithOpenAPIVersion = JSON.parse(
85
+ JSON.stringify(mockServerless)
86
+ );
87
+ serverlessWithOpenAPIVersion.processedInput.options.openApiVersion =
88
+ "3.0.2";
89
+ let expected = new DefinitionGenerator(serverlessWithOpenAPIVersion, {});
90
+ expect(expected.version).to.be.equal("3.0.2");
91
+
92
+ serverlessWithOpenAPIVersion.processedInput.options.openApiVersion =
93
+ "3.0.1";
94
+ expected = new DefinitionGenerator(serverlessWithOpenAPIVersion, {});
95
+ expect(expected.version).to.be.equal("3.0.1");
96
+ });
58
97
 
59
- expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
60
- expect(expected.version).to.be.equal('3.0.0')
98
+ it(`correctly resolves external redocly rules`, async function () {
99
+ await fs.mkdir(path.resolve("options")).catch((err) => {
100
+ console.error(err);
101
+ throw err;
102
+ });
103
+
104
+ await fs
105
+ .copyFile(
106
+ path.resolve("test/helpers/redocly.json"),
107
+ path.resolve("options/redocly.json")
108
+ )
109
+ .catch((err) => {
110
+ console.error(err);
111
+ throw err;
112
+ });
61
113
 
62
- serverlessWithoutOpenAPIVersion.processedInput.options = {
63
- openapiVersion: undefined
64
- }
114
+ const expected = new DefinitionGenerator(mockServerless, {});
65
115
 
66
- expected = new DefinitionGenerator(serverlessWithoutOpenAPIVersion, {})
67
- expect(expected.version).to.be.equal('3.0.0')
68
- });
116
+ expect(expected.REDOCLY_RULES).to.have.property(
117
+ "operation-2xx-response",
118
+ "warn"
119
+ );
69
120
 
70
- it('should respect the version of openAPI when passed in', function() {
71
- const serverlessWithOpenAPIVersion = JSON.parse(JSON.stringify(mockServerless))
72
- serverlessWithOpenAPIVersion.processedInput.options.openApiVersion = '3.0.2'
73
- let expected = new DefinitionGenerator(serverlessWithOpenAPIVersion, {})
74
- expect(expected.version).to.be.equal('3.0.2')
121
+ await fs.rm(path.resolve("options/redocly.json")).catch((err) => {
122
+ console.error(err);
123
+ throw err;
124
+ });
75
125
 
76
- serverlessWithOpenAPIVersion.processedInput.options.openApiVersion = '3.0.1'
77
- expected = new DefinitionGenerator(serverlessWithOpenAPIVersion, {})
78
- expect(expected.version).to.be.equal('3.0.1')
79
- });
126
+ await fs.rmdir(path.resolve("options")).catch((err) => {
127
+ console.error(err);
128
+ throw err;
129
+ });
80
130
  });
131
+ });
81
132
 
82
- describe('createInfo', () => {
83
- it('should create openAPI info object correctly', function() {
84
- const definitionGenerator = new DefinitionGenerator(mockServerless)
85
- definitionGenerator.createInfo()
133
+ describe("createInfo", () => {
134
+ it("should create openAPI info object correctly", function () {
135
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
136
+ definitionGenerator.createInfo();
86
137
 
87
- expect(definitionGenerator.openAPI).to.be.an('object')
88
- expect(definitionGenerator.openAPI.info).to.be.an('object')
89
- // expect(definitionGenerator.openAPI.info).to.deep.equal(mockServerless.service.custom.documentation)
90
- });
138
+ expect(definitionGenerator.openAPI).to.be.an("object");
139
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
140
+ // expect(definitionGenerator.openAPI.info).to.deep.equal(mockServerless.service.custom.documentation)
141
+ });
91
142
 
92
- it('should use the service name when documentation title has not been supplied', function() {
93
- delete mockServerless.service.custom.documentation.title
94
- const definitionGenerator = new DefinitionGenerator(mockServerless)
95
- definitionGenerator.createInfo()
143
+ it("should use the service name when documentation title has not been supplied", function () {
144
+ delete mockServerless.service.custom.documentation.title;
145
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
146
+ definitionGenerator.createInfo();
96
147
 
97
- expect(definitionGenerator.openAPI).to.be.an('object')
98
- expect(definitionGenerator.openAPI.info).to.be.an('object')
99
- expect(definitionGenerator.openAPI.info.title).to.be.equal(mockServerless.service.service)
100
- });
148
+ expect(definitionGenerator.openAPI).to.be.an("object");
149
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
150
+ expect(definitionGenerator.openAPI.info.title).to.be.equal(
151
+ mockServerless.service.service
152
+ );
153
+ });
101
154
 
102
- it('should use the service name when documentation description has not been supplied', function() {
103
- delete mockServerless.service.custom.documentation.description
104
- const definitionGenerator = new DefinitionGenerator(mockServerless)
105
- definitionGenerator.createInfo()
155
+ it("should use the service name when documentation description has not been supplied", function () {
156
+ delete mockServerless.service.custom.documentation.description;
157
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
158
+ definitionGenerator.createInfo();
106
159
 
107
- expect(definitionGenerator.openAPI).to.be.an('object')
108
- expect(definitionGenerator.openAPI.info).to.be.an('object')
109
- expect(definitionGenerator.openAPI.info.description).to.be.equal('')
110
- });
160
+ expect(definitionGenerator.openAPI).to.be.an("object");
161
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
162
+ expect(definitionGenerator.openAPI.info.description).to.be.equal("");
163
+ });
111
164
 
112
- it('should use an empty string when documentation description has not been supplied', function() {
113
- delete mockServerless.service.custom.documentation.description
114
- const definitionGenerator = new DefinitionGenerator(mockServerless)
115
- definitionGenerator.createInfo()
165
+ it("should use an empty string when documentation description has not been supplied", function () {
166
+ delete mockServerless.service.custom.documentation.description;
167
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
168
+ definitionGenerator.createInfo();
116
169
 
117
- expect(definitionGenerator.openAPI).to.be.an('object')
118
- expect(definitionGenerator.openAPI.info).to.be.an('object')
119
- expect(definitionGenerator.openAPI.info.description).to.be.equal('')
120
- });
170
+ expect(definitionGenerator.openAPI).to.be.an("object");
171
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
172
+ expect(definitionGenerator.openAPI.info.description).to.be.equal("");
173
+ });
121
174
 
122
- it('should generate a uuid for version when documentation version has not been supplied', function() {
123
- delete mockServerless.service.custom.documentation.version
175
+ it("should generate a uuid for version when documentation version has not been supplied", function () {
176
+ delete mockServerless.service.custom.documentation.version;
124
177
 
125
- const definitionGenerator = new DefinitionGenerator(mockServerless)
126
- definitionGenerator.createInfo()
178
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
179
+ definitionGenerator.createInfo();
127
180
 
128
- expect(definitionGenerator.openAPI).to.be.an('object')
129
- expect(definitionGenerator.openAPI.info).to.be.an('object')
130
- expect(v4.test(definitionGenerator.openAPI.info.version)).to.be.true
131
- });
181
+ expect(definitionGenerator.openAPI).to.be.an("object");
182
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
183
+ expect(v4.test(definitionGenerator.openAPI.info.version)).to.be.true;
184
+ });
132
185
 
133
- it('should assign a contact Object when a contact object is included', function() {
134
- mockServerless.service.custom.documentation.contact = {
135
- name: 'John',
136
- url: 'http://example.com',
137
- email: 'john@example.com'
138
- }
139
- const definitionGenerator = new DefinitionGenerator(mockServerless)
140
- definitionGenerator.createInfo()
141
-
142
- expect(definitionGenerator.openAPI).to.be.an('object')
143
- expect(definitionGenerator.openAPI.info).to.be.an('object')
144
- expect(definitionGenerator.openAPI.info).to.have.property('contact')
145
- expect(definitionGenerator.openAPI.info.contact).to.be.an('object')
146
- expect(definitionGenerator.openAPI.info.contact.name).to.be.an('string')
147
- });
186
+ it("should assign a contact Object when a contact object is included", function () {
187
+ mockServerless.service.custom.documentation.contact = {
188
+ name: "John",
189
+ url: "http://example.com",
190
+ email: "john@example.com",
191
+ };
192
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
193
+ definitionGenerator.createInfo();
194
+
195
+ expect(definitionGenerator.openAPI).to.be.an("object");
196
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
197
+ expect(definitionGenerator.openAPI.info).to.have.property("contact");
198
+ expect(definitionGenerator.openAPI.info.contact).to.be.an("object");
199
+ expect(definitionGenerator.openAPI.info.contact.name).to.be.an("string");
200
+ });
148
201
 
149
- it('should only assign a contact url if one is provided', function() {
150
- mockServerless.service.custom.documentation.contact = {
151
- name: 'John',
152
- email: 'john@example.com'
153
- }
154
- const definitionGenerator = new DefinitionGenerator(mockServerless)
155
- definitionGenerator.createInfo()
156
-
157
- expect(definitionGenerator.openAPI).to.be.an('object')
158
- expect(definitionGenerator.openAPI.info).to.be.an('object')
159
- expect(definitionGenerator.openAPI.info).to.have.property('contact')
160
- expect(definitionGenerator.openAPI.info.contact).to.be.an('object')
161
- expect(definitionGenerator.openAPI.info.contact.name).to.be.an('string')
162
- expect(definitionGenerator.openAPI.info.contact).to.not.have.property('url')
163
- });
202
+ it("should only assign a contact url if one is provided", function () {
203
+ mockServerless.service.custom.documentation.contact = {
204
+ name: "John",
205
+ email: "john@example.com",
206
+ };
207
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
208
+ definitionGenerator.createInfo();
209
+
210
+ expect(definitionGenerator.openAPI).to.be.an("object");
211
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
212
+ expect(definitionGenerator.openAPI.info).to.have.property("contact");
213
+ expect(definitionGenerator.openAPI.info.contact).to.be.an("object");
214
+ expect(definitionGenerator.openAPI.info.contact.name).to.be.an("string");
215
+ expect(definitionGenerator.openAPI.info.contact).to.not.have.property(
216
+ "url"
217
+ );
218
+ });
164
219
 
165
- it('should assign a license Object when a license object is included with a name', function() {
166
- mockServerless.service.custom.documentation.license = {
167
- name: 'Apache 2.0',
168
- url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
169
- }
170
- const definitionGenerator = new DefinitionGenerator(mockServerless)
171
- definitionGenerator.createInfo()
172
-
173
- expect(definitionGenerator.openAPI).to.be.an('object')
174
- expect(definitionGenerator.openAPI.info).to.be.an('object')
175
- expect(definitionGenerator.openAPI.info).to.have.property('license')
176
- expect(definitionGenerator.openAPI.info.license).to.be.an('object')
177
- expect(definitionGenerator.openAPI.info.license.name).to.be.an('string')
178
- });
220
+ it("should assign a license Object when a license object is included with a name", function () {
221
+ mockServerless.service.custom.documentation.license = {
222
+ name: "Apache 2.0",
223
+ url: "https://www.apache.org/licenses/LICENSE-2.0.html",
224
+ };
225
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
226
+ definitionGenerator.createInfo();
227
+
228
+ expect(definitionGenerator.openAPI).to.be.an("object");
229
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
230
+ expect(definitionGenerator.openAPI.info).to.have.property("license");
231
+ expect(definitionGenerator.openAPI.info.license).to.be.an("object");
232
+ expect(definitionGenerator.openAPI.info.license.name).to.be.an("string");
233
+ });
179
234
 
180
- it('should not assign a license Object when a license object is included without a name', function() {
181
- mockServerless.service.custom.documentation.license = {
182
- url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
183
- }
184
- const definitionGenerator = new DefinitionGenerator(mockServerless)
185
- definitionGenerator.createInfo()
235
+ it("should not assign a license Object when a license object is included without a name", function () {
236
+ mockServerless.service.custom.documentation.license = {
237
+ url: "https://www.apache.org/licenses/LICENSE-2.0.html",
238
+ };
239
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
240
+ definitionGenerator.createInfo();
186
241
 
187
- expect(definitionGenerator.openAPI).to.be.an('object')
188
- expect(definitionGenerator.openAPI.info).to.be.an('object')
189
- expect(definitionGenerator.openAPI.info).to.not.have.property('license')
190
- });
242
+ expect(definitionGenerator.openAPI).to.be.an("object");
243
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
244
+ expect(definitionGenerator.openAPI.info).to.not.have.property("license");
245
+ });
191
246
 
192
- it('should only assign a contact url if one is provided', function() {
193
- mockServerless.service.custom.documentation.license = {
194
- name: 'John',
195
- }
196
- const definitionGenerator = new DefinitionGenerator(mockServerless)
197
- definitionGenerator.createInfo()
198
-
199
- expect(definitionGenerator.openAPI).to.be.an('object')
200
- expect(definitionGenerator.openAPI.info).to.be.an('object')
201
- expect(definitionGenerator.openAPI.info).to.have.property('license')
202
- expect(definitionGenerator.openAPI.info.license).to.be.an('object')
203
- expect(definitionGenerator.openAPI.info.license.name).to.be.an('string')
204
- expect(definitionGenerator.openAPI.info.license).to.not.have.property('url')
205
- });
247
+ it("should only assign a contact url if one is provided", function () {
248
+ mockServerless.service.custom.documentation.license = {
249
+ name: "John",
250
+ };
251
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
252
+ definitionGenerator.createInfo();
253
+
254
+ expect(definitionGenerator.openAPI).to.be.an("object");
255
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
256
+ expect(definitionGenerator.openAPI.info).to.have.property("license");
257
+ expect(definitionGenerator.openAPI.info.license).to.be.an("object");
258
+ expect(definitionGenerator.openAPI.info.license.name).to.be.an("string");
259
+ expect(definitionGenerator.openAPI.info.license).to.not.have.property(
260
+ "url"
261
+ );
262
+ });
206
263
 
207
- it('should assign specification extension fields when included', function() {
208
- mockServerless.service.custom.documentation['x-field'] = 'john'
209
- const definitionGenerator = new DefinitionGenerator(mockServerless)
210
- definitionGenerator.createInfo()
264
+ it("should assign specification extension fields when included", function () {
265
+ mockServerless.service.custom.documentation["x-field"] = "john";
266
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
267
+ definitionGenerator.createInfo();
211
268
 
212
- expect(definitionGenerator.openAPI).to.be.an('object')
213
- expect(definitionGenerator.openAPI.info).to.be.an('object')
214
- expect(definitionGenerator.openAPI.info).to.have.property('x-field')
215
- expect(definitionGenerator.openAPI.info['x-field']).to.be.equal('john')
216
- });
269
+ expect(definitionGenerator.openAPI).to.be.an("object");
270
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
271
+ expect(definitionGenerator.openAPI.info).to.have.property("x-field");
272
+ expect(definitionGenerator.openAPI.info["x-field"]).to.be.equal("john");
273
+ });
217
274
 
218
- it('should ignore fields that do not conform to specifiction extension', function() {
219
- mockServerless.service.custom.documentation.otherField = 'john'
220
- const definitionGenerator = new DefinitionGenerator(mockServerless)
221
- definitionGenerator.createInfo()
275
+ it("should ignore fields that do not conform to specifiction extension", function () {
276
+ mockServerless.service.custom.documentation.otherField = "john";
277
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
278
+ definitionGenerator.createInfo();
222
279
 
223
- expect(definitionGenerator.openAPI).to.be.an('object')
224
- expect(definitionGenerator.openAPI.info).to.be.an('object')
225
- expect(definitionGenerator.openAPI.info).to.not.have.property('otherField')
226
- });
280
+ expect(definitionGenerator.openAPI).to.be.an("object");
281
+ expect(definitionGenerator.openAPI.info).to.be.an("object");
282
+ expect(definitionGenerator.openAPI.info).to.not.have.property(
283
+ "otherField"
284
+ );
285
+ });
286
+ });
287
+
288
+ describe("createSecuritySchemes", () => {
289
+ describe("API Keys", () => {
290
+ it("should add an API Key security scheme to components", function () {
291
+ mockServerless.service.custom.documentation.securitySchemes = {
292
+ api_key: {
293
+ type: "apiKey",
294
+ name: "Authorization",
295
+ in: "header",
296
+ },
297
+ };
298
+
299
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
300
+ definitionGenerator.createSecuritySchemes(
301
+ mockServerless.service.custom.documentation.securitySchemes
302
+ );
303
+
304
+ expect(definitionGenerator.openAPI).to.be.an("object");
305
+ expect(definitionGenerator.openAPI.components).to.be.an("object");
306
+ expect(definitionGenerator.openAPI.components).to.have.property(
307
+ "securitySchemes"
308
+ );
309
+ expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an(
310
+ "object"
311
+ );
312
+ expect(
313
+ definitionGenerator.openAPI.components.securitySchemes
314
+ ).to.have.property("api_key");
315
+ expect(
316
+ definitionGenerator.openAPI.components.securitySchemes.api_key
317
+ ).to.have.property("type");
318
+ expect(
319
+ definitionGenerator.openAPI.components.securitySchemes.api_key.type
320
+ ).to.be.equal("apiKey");
321
+ });
322
+
323
+ it("should throw an error when name is missing from an API Key scheme", function () {
324
+ mockServerless.service.custom.documentation.securitySchemes = {
325
+ api_key: {
326
+ type: "apiKey",
327
+ in: "header",
328
+ },
329
+ };
330
+
331
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
332
+ expect(() => {
333
+ definitionGenerator.createSecuritySchemes(
334
+ mockServerless.service.custom.documentation.securitySchemes
335
+ );
336
+ }).to.throw(
337
+ 'Security Scheme for "apiKey" requires the name of the header, query or cookie parameter to be used'
338
+ );
339
+ });
340
+
341
+ it("should throw an error when in is missing from an API Key scheme", function () {
342
+ mockServerless.service.custom.documentation.securitySchemes = {
343
+ api_key: {
344
+ type: "apiKey",
345
+ name: "Authorization",
346
+ },
347
+ };
348
+
349
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
350
+ expect(() => {
351
+ definitionGenerator.createSecuritySchemes(
352
+ mockServerless.service.custom.documentation.securitySchemes
353
+ );
354
+ }).to.throw(
355
+ 'Security Scheme for "apiKey" requires the location of the API key: header, query or cookie parameter'
356
+ );
357
+ });
227
358
  });
228
359
 
229
- describe('createSecuritySchemes', () => {
230
- describe('API Keys', () => {
231
- it('should add an API Key security scheme to components', function() {
232
- mockServerless.service.custom.documentation.securitySchemes = {
233
- 'api_key': {
234
- type: 'apiKey',
235
- name: 'Authorization',
236
- in: 'header'
237
- }
238
- }
239
-
240
- const definitionGenerator = new DefinitionGenerator(mockServerless)
241
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
242
-
243
- expect(definitionGenerator.openAPI).to.be.an('object')
244
- expect(definitionGenerator.openAPI.components).to.be.an('object')
245
- expect(definitionGenerator.openAPI.components).to.have.property('securitySchemes')
246
- expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an('object')
247
- expect(definitionGenerator.openAPI.components.securitySchemes).to.have.property('api_key')
248
- expect(definitionGenerator.openAPI.components.securitySchemes.api_key).to.have.property('type')
249
- expect(definitionGenerator.openAPI.components.securitySchemes.api_key.type).to.be.equal('apiKey')
250
- });
251
-
252
- it('should throw an error when name is missing from an API Key scheme', function() {
253
- mockServerless.service.custom.documentation.securitySchemes = {
254
- 'api_key': {
255
- type: 'apiKey',
256
- in: 'header'
257
- }
258
- }
259
-
260
- const definitionGenerator = new DefinitionGenerator(mockServerless)
261
- expect(() => {
262
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
263
- }).to.throw('Security Scheme for "apiKey" requires the name of the header, query or cookie parameter to be used')
264
- });
265
-
266
- it('should throw an error when in is missing from an API Key scheme', function() {
267
- mockServerless.service.custom.documentation.securitySchemes = {
268
- 'api_key': {
269
- type: 'apiKey',
270
- name: 'Authorization',
271
- }
272
- }
273
-
274
- const definitionGenerator = new DefinitionGenerator(mockServerless)
275
- expect(() => {
276
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
277
- }).to.throw('Security Scheme for "apiKey" requires the location of the API key: header, query or cookie parameter')
278
- });
279
- });
280
-
281
- describe('HTTP', () => {
282
- it('should add an HTTP security scheme to components', function() {
283
- mockServerless.service.custom.documentation.securitySchemes = {
284
- 'http_key': {
285
- type: 'http',
286
- scheme: 'basic'
287
- }
288
- }
289
-
290
- const definitionGenerator = new DefinitionGenerator(mockServerless)
291
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
292
-
293
- expect(definitionGenerator.openAPI).to.be.an('object')
294
- expect(definitionGenerator.openAPI.components).to.be.an('object')
295
- expect(definitionGenerator.openAPI.components).to.have.property('securitySchemes')
296
- expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an('object')
297
- expect(definitionGenerator.openAPI.components.securitySchemes).to.have.property('http_key')
298
- });
299
-
300
- it('should throw an error when scheme is missing from an HTTP scheme', function() {
301
- mockServerless.service.custom.documentation.securitySchemes = {
302
- 'http_key': {
303
- type: 'http',
304
- }
305
- }
306
-
307
- const definitionGenerator = new DefinitionGenerator(mockServerless)
308
- expect(() => {
309
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
310
- }).to.throw('Security Scheme for "http" requires scheme')
311
- });
312
- });
360
+ describe("HTTP", () => {
361
+ it("should add an HTTP security scheme to components", function () {
362
+ mockServerless.service.custom.documentation.securitySchemes = {
363
+ http_key: {
364
+ type: "http",
365
+ scheme: "basic",
366
+ },
367
+ };
368
+
369
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
370
+ definitionGenerator.createSecuritySchemes(
371
+ mockServerless.service.custom.documentation.securitySchemes
372
+ );
373
+
374
+ expect(definitionGenerator.openAPI).to.be.an("object");
375
+ expect(definitionGenerator.openAPI.components).to.be.an("object");
376
+ expect(definitionGenerator.openAPI.components).to.have.property(
377
+ "securitySchemes"
378
+ );
379
+ expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an(
380
+ "object"
381
+ );
382
+ expect(
383
+ definitionGenerator.openAPI.components.securitySchemes
384
+ ).to.have.property("http_key");
385
+ });
386
+
387
+ it("should throw an error when scheme is missing from an HTTP scheme", function () {
388
+ mockServerless.service.custom.documentation.securitySchemes = {
389
+ http_key: {
390
+ type: "http",
391
+ },
392
+ };
393
+
394
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
395
+ expect(() => {
396
+ definitionGenerator.createSecuritySchemes(
397
+ mockServerless.service.custom.documentation.securitySchemes
398
+ );
399
+ }).to.throw('Security Scheme for "http" requires scheme');
400
+ });
401
+ });
313
402
 
314
- describe('openIdConnect', () => {
315
- it('should add an openIdConnect security scheme to components', function() {
316
- mockServerless.service.custom.documentation.securitySchemes = {
317
- 'openIdConnect_key': {
318
- type: 'openIdConnect',
319
- openIdConnectUrl: 'http://example.com'
320
- }
321
- }
322
-
323
- const definitionGenerator = new DefinitionGenerator(mockServerless)
324
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
325
-
326
- expect(definitionGenerator.openAPI).to.be.an('object')
327
- expect(definitionGenerator.openAPI.components).to.be.an('object')
328
- expect(definitionGenerator.openAPI.components).to.have.property('securitySchemes')
329
- expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an('object')
330
- expect(definitionGenerator.openAPI.components.securitySchemes).to.have.property('openIdConnect_key')
331
- });
332
-
333
- it('should throw an error when openIdConnectUrl is missing from an openIdConnect scheme', function() {
334
- mockServerless.service.custom.documentation.securitySchemes = {
335
- 'openIdConnect_key': {
336
- type: 'openIdConnect',
337
- }
338
- }
339
-
340
- const definitionGenerator = new DefinitionGenerator(mockServerless)
341
- expect(() => {
342
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
343
- }).to.throw('Security Scheme for "openIdConnect" requires openIdConnectUrl')
344
- });
345
- });
403
+ describe("openIdConnect", () => {
404
+ it("should add an openIdConnect security scheme to components", function () {
405
+ mockServerless.service.custom.documentation.securitySchemes = {
406
+ openIdConnect_key: {
407
+ type: "openIdConnect",
408
+ openIdConnectUrl: "http://example.com",
409
+ },
410
+ };
411
+
412
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
413
+ definitionGenerator.createSecuritySchemes(
414
+ mockServerless.service.custom.documentation.securitySchemes
415
+ );
416
+
417
+ expect(definitionGenerator.openAPI).to.be.an("object");
418
+ expect(definitionGenerator.openAPI.components).to.be.an("object");
419
+ expect(definitionGenerator.openAPI.components).to.have.property(
420
+ "securitySchemes"
421
+ );
422
+ expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an(
423
+ "object"
424
+ );
425
+ expect(
426
+ definitionGenerator.openAPI.components.securitySchemes
427
+ ).to.have.property("openIdConnect_key");
428
+ });
429
+
430
+ it("should throw an error when openIdConnectUrl is missing from an openIdConnect scheme", function () {
431
+ mockServerless.service.custom.documentation.securitySchemes = {
432
+ openIdConnect_key: {
433
+ type: "openIdConnect",
434
+ },
435
+ };
436
+
437
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
438
+ expect(() => {
439
+ definitionGenerator.createSecuritySchemes(
440
+ mockServerless.service.custom.documentation.securitySchemes
441
+ );
442
+ }).to.throw(
443
+ 'Security Scheme for "openIdConnect" requires openIdConnectUrl'
444
+ );
445
+ });
446
+ });
346
447
 
347
- describe('oauth2', () => {
348
- it('should add an oauth2 security scheme to components', function() {
349
- mockServerless.service.custom.documentation.securitySchemes = {
350
- 'oAuth2_key': {
351
- type: 'oauth2',
352
- flows: {
353
- implicit: {
354
- authorizationUrl: 'http://example.org/api/oauth/dialog',
355
- scopes: {
356
- 'write:pets': 'modify pets in your account',
357
- 'read:pets': 'read your pets'
358
- }
359
- }
360
- }
361
- }
362
- }
363
-
364
- const definitionGenerator = new DefinitionGenerator(mockServerless)
365
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
366
-
367
- expect(definitionGenerator.openAPI).to.be.an('object')
368
- expect(definitionGenerator.openAPI.components).to.be.an('object')
369
- expect(definitionGenerator.openAPI.components).to.have.property('securitySchemes')
370
- expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an('object')
371
- expect(definitionGenerator.openAPI.components.securitySchemes).to.have.property('oAuth2_key')
372
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key).to.be.an('object')
373
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key).to.have.property('type')
374
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key).to.have.property('flows')
375
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key.flows).to.be.an('object')
376
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key.flows).to.have.property('implicit')
377
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key.flows.implicit).to.be.an('object')
378
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key.flows.implicit).to.have.property('scopes')
379
- expect(definitionGenerator.openAPI.components.securitySchemes.oAuth2_key.flows.implicit.scopes).to.be.an('object')
380
- });
381
-
382
- it('should throw an error when flows is missing from an oauth2 scheme', function() {
383
- mockServerless.service.custom.documentation.securitySchemes = {
384
- 'oAuth2_key': {
385
- type: 'oauth2',
386
- }
387
- }
388
-
389
- const definitionGenerator = new DefinitionGenerator(mockServerless)
390
- expect(() => {
391
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
392
- }).to.throw('Security Scheme for "oauth2" requires flows')
393
- });
394
-
395
- it('should throw an error when authorizationUrl is missing from an oauth2 implicit flow scheme', function() {
396
- mockServerless.service.custom.documentation.securitySchemes = {
397
- 'oAuth2_key': {
398
- type: 'oauth2',
399
- flows: {
400
- implicit: {
401
- scopes: {
402
- 'write:pets': 'modify pets in your account',
403
- 'read:pets': 'read your pets'
404
- }
405
- }
406
- }
407
- }
408
- }
409
-
410
- const definitionGenerator = new DefinitionGenerator(mockServerless)
411
- expect(() => {
412
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
413
- }).to.throw('oAuth2 implicit flow requires an authorizationUrl')
414
- });
415
-
416
- it('should throw an error when authorizationUrl is missing from an oauth2 authorizationCode flow scheme', function() {
417
- mockServerless.service.custom.documentation.securitySchemes = {
418
- 'oAuth2_key': {
419
- type: 'oauth2',
420
- flows: {
421
- authorizationCode: {
422
- tokenUrl: 'http://example.com',
423
- scopes: {
424
- 'write:pets': 'modify pets in your account',
425
- 'read:pets': 'read your pets'
426
- }
427
- }
428
- }
429
- }
430
- }
431
-
432
- const definitionGenerator = new DefinitionGenerator(mockServerless)
433
- expect(() => {
434
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
435
- }).to.throw('oAuth2 authorizationCode flow requires an authorizationUrl')
436
- });
437
-
438
- it('should throw an error when tokenUrl is missing from an oauth2 authorizationCode flow scheme', function() {
439
- mockServerless.service.custom.documentation.securitySchemes = {
440
- 'oAuth2_key': {
441
- type: 'oauth2',
442
- flows: {
443
- authorizationCode: {
444
- authorizationUrl: 'http://example.org/api/oauth/dialog',
445
- scopes: {
446
- 'write:pets': 'modify pets in your account',
447
- 'read:pets': 'read your pets'
448
- }
449
- }
450
- }
451
- }
452
- }
453
-
454
- const definitionGenerator = new DefinitionGenerator(mockServerless)
455
- expect(() => {
456
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
457
- }).to.throw('oAuth2 authorizationCode flow requires a tokenUrl')
458
- });
459
-
460
- it('should throw an error when tokenUrl is missing from an oauth2 password flow scheme', function() {
461
- mockServerless.service.custom.documentation.securitySchemes = {
462
- 'oAuth2_key': {
463
- type: 'oauth2',
464
- flows: {
465
- password: {
466
- scopes: {
467
- 'write:pets': 'modify pets in your account',
468
- 'read:pets': 'read your pets'
469
- }
470
- }
471
- }
472
- }
473
- }
474
-
475
- const definitionGenerator = new DefinitionGenerator(mockServerless)
476
- expect(() => {
477
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
478
- }).to.throw('oAuth2 password flow requires a tokenUrl')
479
- });
480
-
481
- it('should throw an error when tokenUrl is missing from an oauth2 clientCredentials flow scheme', function() {
482
- mockServerless.service.custom.documentation.securitySchemes = {
483
- 'oAuth2_key': {
484
- type: 'oauth2',
485
- flows: {
486
- clientCredentials: {
487
- scopes: {
488
- 'write:pets': 'modify pets in your account',
489
- 'read:pets': 'read your pets'
490
- }
491
- }
492
- }
493
- }
494
- }
495
-
496
- const definitionGenerator = new DefinitionGenerator(mockServerless)
497
- expect(() => {
498
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
499
- }).to.throw('oAuth2 clientCredentials flow requires a tokenUrl')
500
- });
501
-
502
- it('should throw an error when scopes is missing from an oauth2 clientCredentials flow scheme', function() {
503
- mockServerless.service.custom.documentation.securitySchemes = {
504
- 'oAuth2_key': {
505
- type: 'oauth2',
506
- flows: {
507
- clientCredentials: {
508
- tokenUrl: 'http://example.com',
509
- }
510
- }
511
- }
512
- }
513
-
514
- const definitionGenerator = new DefinitionGenerator(mockServerless)
515
- expect(() => {
516
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
517
- }).to.throw('oAuth2 clientCredentials flow requires scopes')
518
- });
519
-
520
- it('should throw an error when scopes is missing from an oauth2 authorizationCode flow scheme', function() {
521
- mockServerless.service.custom.documentation.securitySchemes = {
522
- 'oAuth2_key': {
523
- type: 'oauth2',
524
- flows: {
525
- authorizationCode: {
526
- tokenUrl: 'http://example.com',
527
- authorizationUrl: 'http://example.org/api/oauth/dialog',
528
- }
529
- }
530
- }
531
- }
532
-
533
- const definitionGenerator = new DefinitionGenerator(mockServerless)
534
- expect(() => {
535
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
536
- }).to.throw('oAuth2 authorizationCode flow requires scopes')
537
- });
538
-
539
- it('should throw an error when scopes is missing from an oauth2 password flow scheme', function() {
540
- mockServerless.service.custom.documentation.securitySchemes = {
541
- 'oAuth2_key': {
542
- type: 'oauth2',
543
- flows: {
544
- password: {
545
- tokenUrl: 'http://example.com',
546
- }
547
- }
548
- }
549
- }
550
-
551
- const definitionGenerator = new DefinitionGenerator(mockServerless)
552
- expect(() => {
553
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
554
- }).to.throw('oAuth2 password flow requires scopes')
555
- });
556
-
557
- it('should throw an error when scopes is missing from an oauth2 implicit flow scheme', function() {
558
- mockServerless.service.custom.documentation.securitySchemes = {
559
- 'oAuth2_key': {
560
- type: 'oauth2',
561
- flows: {
562
- implicit: {
563
- authorizationUrl: 'http://example.org/api/oauth/dialog',
564
- }
565
- }
566
- }
567
- }
568
-
569
- const definitionGenerator = new DefinitionGenerator(mockServerless)
570
- expect(() => {
571
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
572
- }).to.throw('oAuth2 implicit flow requires scopes')
573
- });
574
- });
448
+ describe("oauth2", () => {
449
+ it("should add an oauth2 security scheme to components", function () {
450
+ mockServerless.service.custom.documentation.securitySchemes = {
451
+ oAuth2_key: {
452
+ type: "oauth2",
453
+ flows: {
454
+ implicit: {
455
+ authorizationUrl: "http://example.org/api/oauth/dialog",
456
+ scopes: {
457
+ "write:pets": "modify pets in your account",
458
+ "read:pets": "read your pets",
459
+ },
460
+ },
461
+ },
462
+ },
463
+ };
464
+
465
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
466
+ definitionGenerator.createSecuritySchemes(
467
+ mockServerless.service.custom.documentation.securitySchemes
468
+ );
469
+
470
+ expect(definitionGenerator.openAPI).to.be.an("object");
471
+ expect(definitionGenerator.openAPI.components).to.be.an("object");
472
+ expect(definitionGenerator.openAPI.components).to.have.property(
473
+ "securitySchemes"
474
+ );
475
+ expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an(
476
+ "object"
477
+ );
478
+ expect(
479
+ definitionGenerator.openAPI.components.securitySchemes
480
+ ).to.have.property("oAuth2_key");
481
+ expect(
482
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
483
+ ).to.be.an("object");
484
+ expect(
485
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
486
+ ).to.have.property("type");
487
+ expect(
488
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
489
+ ).to.have.property("flows");
490
+ expect(
491
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
492
+ .flows
493
+ ).to.be.an("object");
494
+ expect(
495
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
496
+ .flows
497
+ ).to.have.property("implicit");
498
+ expect(
499
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
500
+ .flows.implicit
501
+ ).to.be.an("object");
502
+ expect(
503
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
504
+ .flows.implicit
505
+ ).to.have.property("scopes");
506
+ expect(
507
+ definitionGenerator.openAPI.components.securitySchemes.oAuth2_key
508
+ .flows.implicit.scopes
509
+ ).to.be.an("object");
510
+ });
511
+
512
+ it("should throw an error when flows is missing from an oauth2 scheme", function () {
513
+ mockServerless.service.custom.documentation.securitySchemes = {
514
+ oAuth2_key: {
515
+ type: "oauth2",
516
+ },
517
+ };
518
+
519
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
520
+ expect(() => {
521
+ definitionGenerator.createSecuritySchemes(
522
+ mockServerless.service.custom.documentation.securitySchemes
523
+ );
524
+ }).to.throw('Security Scheme for "oauth2" requires flows');
525
+ });
526
+
527
+ it("should throw an error when authorizationUrl is missing from an oauth2 implicit flow scheme", function () {
528
+ mockServerless.service.custom.documentation.securitySchemes = {
529
+ oAuth2_key: {
530
+ type: "oauth2",
531
+ flows: {
532
+ implicit: {
533
+ scopes: {
534
+ "write:pets": "modify pets in your account",
535
+ "read:pets": "read your pets",
536
+ },
537
+ },
538
+ },
539
+ },
540
+ };
541
+
542
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
543
+ expect(() => {
544
+ definitionGenerator.createSecuritySchemes(
545
+ mockServerless.service.custom.documentation.securitySchemes
546
+ );
547
+ }).to.throw("oAuth2 implicit flow requires an authorizationUrl");
548
+ });
549
+
550
+ it("should throw an error when authorizationUrl is missing from an oauth2 authorizationCode flow scheme", function () {
551
+ mockServerless.service.custom.documentation.securitySchemes = {
552
+ oAuth2_key: {
553
+ type: "oauth2",
554
+ flows: {
555
+ authorizationCode: {
556
+ tokenUrl: "http://example.com",
557
+ scopes: {
558
+ "write:pets": "modify pets in your account",
559
+ "read:pets": "read your pets",
560
+ },
561
+ },
562
+ },
563
+ },
564
+ };
565
+
566
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
567
+ expect(() => {
568
+ definitionGenerator.createSecuritySchemes(
569
+ mockServerless.service.custom.documentation.securitySchemes
570
+ );
571
+ }).to.throw(
572
+ "oAuth2 authorizationCode flow requires an authorizationUrl"
573
+ );
574
+ });
575
+
576
+ it("should throw an error when tokenUrl is missing from an oauth2 authorizationCode flow scheme", function () {
577
+ mockServerless.service.custom.documentation.securitySchemes = {
578
+ oAuth2_key: {
579
+ type: "oauth2",
580
+ flows: {
581
+ authorizationCode: {
582
+ authorizationUrl: "http://example.org/api/oauth/dialog",
583
+ scopes: {
584
+ "write:pets": "modify pets in your account",
585
+ "read:pets": "read your pets",
586
+ },
587
+ },
588
+ },
589
+ },
590
+ };
591
+
592
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
593
+ expect(() => {
594
+ definitionGenerator.createSecuritySchemes(
595
+ mockServerless.service.custom.documentation.securitySchemes
596
+ );
597
+ }).to.throw("oAuth2 authorizationCode flow requires a tokenUrl");
598
+ });
599
+
600
+ it("should throw an error when tokenUrl is missing from an oauth2 password flow scheme", function () {
601
+ mockServerless.service.custom.documentation.securitySchemes = {
602
+ oAuth2_key: {
603
+ type: "oauth2",
604
+ flows: {
605
+ password: {
606
+ scopes: {
607
+ "write:pets": "modify pets in your account",
608
+ "read:pets": "read your pets",
609
+ },
610
+ },
611
+ },
612
+ },
613
+ };
614
+
615
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
616
+ expect(() => {
617
+ definitionGenerator.createSecuritySchemes(
618
+ mockServerless.service.custom.documentation.securitySchemes
619
+ );
620
+ }).to.throw("oAuth2 password flow requires a tokenUrl");
621
+ });
622
+
623
+ it("should throw an error when tokenUrl is missing from an oauth2 clientCredentials flow scheme", function () {
624
+ mockServerless.service.custom.documentation.securitySchemes = {
625
+ oAuth2_key: {
626
+ type: "oauth2",
627
+ flows: {
628
+ clientCredentials: {
629
+ scopes: {
630
+ "write:pets": "modify pets in your account",
631
+ "read:pets": "read your pets",
632
+ },
633
+ },
634
+ },
635
+ },
636
+ };
637
+
638
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
639
+ expect(() => {
640
+ definitionGenerator.createSecuritySchemes(
641
+ mockServerless.service.custom.documentation.securitySchemes
642
+ );
643
+ }).to.throw("oAuth2 clientCredentials flow requires a tokenUrl");
644
+ });
645
+
646
+ it("should throw an error when scopes is missing from an oauth2 clientCredentials flow scheme", function () {
647
+ mockServerless.service.custom.documentation.securitySchemes = {
648
+ oAuth2_key: {
649
+ type: "oauth2",
650
+ flows: {
651
+ clientCredentials: {
652
+ tokenUrl: "http://example.com",
653
+ },
654
+ },
655
+ },
656
+ };
657
+
658
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
659
+ expect(() => {
660
+ definitionGenerator.createSecuritySchemes(
661
+ mockServerless.service.custom.documentation.securitySchemes
662
+ );
663
+ }).to.throw("oAuth2 clientCredentials flow requires scopes");
664
+ });
665
+
666
+ it("should throw an error when scopes is missing from an oauth2 authorizationCode flow scheme", function () {
667
+ mockServerless.service.custom.documentation.securitySchemes = {
668
+ oAuth2_key: {
669
+ type: "oauth2",
670
+ flows: {
671
+ authorizationCode: {
672
+ tokenUrl: "http://example.com",
673
+ authorizationUrl: "http://example.org/api/oauth/dialog",
674
+ },
675
+ },
676
+ },
677
+ };
678
+
679
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
680
+ expect(() => {
681
+ definitionGenerator.createSecuritySchemes(
682
+ mockServerless.service.custom.documentation.securitySchemes
683
+ );
684
+ }).to.throw("oAuth2 authorizationCode flow requires scopes");
685
+ });
686
+
687
+ it("should throw an error when scopes is missing from an oauth2 password flow scheme", function () {
688
+ mockServerless.service.custom.documentation.securitySchemes = {
689
+ oAuth2_key: {
690
+ type: "oauth2",
691
+ flows: {
692
+ password: {
693
+ tokenUrl: "http://example.com",
694
+ },
695
+ },
696
+ },
697
+ };
698
+
699
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
700
+ expect(() => {
701
+ definitionGenerator.createSecuritySchemes(
702
+ mockServerless.service.custom.documentation.securitySchemes
703
+ );
704
+ }).to.throw("oAuth2 password flow requires scopes");
705
+ });
706
+
707
+ it("should throw an error when scopes is missing from an oauth2 implicit flow scheme", function () {
708
+ mockServerless.service.custom.documentation.securitySchemes = {
709
+ oAuth2_key: {
710
+ type: "oauth2",
711
+ flows: {
712
+ implicit: {
713
+ authorizationUrl: "http://example.org/api/oauth/dialog",
714
+ },
715
+ },
716
+ },
717
+ };
718
+
719
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
720
+ expect(() => {
721
+ definitionGenerator.createSecuritySchemes(
722
+ mockServerless.service.custom.documentation.securitySchemes
723
+ );
724
+ }).to.throw("oAuth2 implicit flow requires scopes");
725
+ });
726
+ });
575
727
 
576
- describe('Multiple Schemes', () => {
577
- it('should add an oauth2 and an apiKey security scheme to components', function() {
578
- mockServerless.service.custom.documentation.securitySchemes = {
579
- 'oAuth2_key': {
580
- type: 'oauth2',
581
- flows: {
582
- implicit: {
583
- authorizationUrl: 'http://example.org/api/oauth/dialog',
584
- scopes: {
585
- 'write:pets': 'modify pets in your account',
586
- 'read:pets': 'read your pets'
587
- }
588
- }
589
- }
590
- },
591
- 'api_key': {
592
- type: 'apiKey',
593
- name: 'Authorization',
594
- in: 'header'
595
- }
596
- }
597
-
598
- const definitionGenerator = new DefinitionGenerator(mockServerless)
599
- definitionGenerator.createSecuritySchemes(mockServerless.service.custom.documentation.securitySchemes)
600
- expect(definitionGenerator.openAPI).to.be.an('object')
601
- expect(definitionGenerator.openAPI.components).to.be.an('object')
602
- expect(definitionGenerator.openAPI.components).to.have.property('securitySchemes')
603
- expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an('object')
604
- expect(definitionGenerator.openAPI.components.securitySchemes).to.have.property('oAuth2_key')
605
- expect(definitionGenerator.openAPI.components.securitySchemes).to.have.property('api_key')
606
- });
607
- });
728
+ describe("Multiple Schemes", () => {
729
+ it("should add an oauth2 and an apiKey security scheme to components", function () {
730
+ mockServerless.service.custom.documentation.securitySchemes = {
731
+ oAuth2_key: {
732
+ type: "oauth2",
733
+ flows: {
734
+ implicit: {
735
+ authorizationUrl: "http://example.org/api/oauth/dialog",
736
+ scopes: {
737
+ "write:pets": "modify pets in your account",
738
+ "read:pets": "read your pets",
739
+ },
740
+ },
741
+ },
742
+ },
743
+ api_key: {
744
+ type: "apiKey",
745
+ name: "Authorization",
746
+ in: "header",
747
+ },
748
+ };
749
+
750
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
751
+ definitionGenerator.createSecuritySchemes(
752
+ mockServerless.service.custom.documentation.securitySchemes
753
+ );
754
+ expect(definitionGenerator.openAPI).to.be.an("object");
755
+ expect(definitionGenerator.openAPI.components).to.be.an("object");
756
+ expect(definitionGenerator.openAPI.components).to.have.property(
757
+ "securitySchemes"
758
+ );
759
+ expect(definitionGenerator.openAPI.components.securitySchemes).to.be.an(
760
+ "object"
761
+ );
762
+ expect(
763
+ definitionGenerator.openAPI.components.securitySchemes
764
+ ).to.have.property("oAuth2_key");
765
+ expect(
766
+ definitionGenerator.openAPI.components.securitySchemes
767
+ ).to.have.property("api_key");
768
+ });
608
769
  });
770
+ });
609
771
 
610
- describe('createTags', () => {
611
- it('should add tags to the openAPI object correctly', function() {
612
- mockServerless.service.custom.documentation.tags = [{name: 'tag1'}]
772
+ describe("createTags", () => {
773
+ it("should add tags to the openAPI object correctly", function () {
774
+ mockServerless.service.custom.documentation.tags = [{ name: "tag1" }];
613
775
 
614
- const definitionGenerator = new DefinitionGenerator(mockServerless)
615
- definitionGenerator.createTags()
776
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
777
+ definitionGenerator.createTags();
616
778
 
617
- expect(definitionGenerator.openAPI).to.be.an('object')
618
- expect(definitionGenerator.openAPI.tags).to.be.an('array')
619
- expect(definitionGenerator.openAPI.tags[0].name).to.be.equal('tag1')
620
- });
779
+ expect(definitionGenerator.openAPI).to.be.an("object");
780
+ expect(definitionGenerator.openAPI.tags).to.be.an("array");
781
+ expect(definitionGenerator.openAPI.tags[0].name).to.be.equal("tag1");
782
+ });
621
783
 
622
- it('should not add tags when they are not defined', function() {
623
- const definitionGenerator = new DefinitionGenerator(mockServerless)
624
- expect(() => {
625
- definitionGenerator.createTags()
626
- }).to.throw()
627
- });
784
+ it("should not add tags when they are not defined", function () {
785
+ const definitionGenerator = new DefinitionGenerator(mockServerless);
786
+ expect(() => {
787
+ definitionGenerator.createTags();
788
+ }).to.throw();
628
789
  });
790
+ });
629
791
  });