@@ -169,152 +169,222 @@ describe("DefinitionGenerator", () => {
169169 // expect(definitionGenerator.openAPI.info).to.deep.equal(mockServerless.service.custom.documentation)
170170 } ) ;
171171
172- it ( "should use the service name when documentation title has not been supplied" , function ( ) {
173- delete mockServerless . service . custom . documentation . title ;
174- const definitionGenerator = new DefinitionGenerator (
175- mockServerless ,
176- logger
177- ) ;
178- definitionGenerator . createInfo ( ) ;
172+ describe ( `info` , function ( ) {
173+ it ( "should use the service name when documentation title has not been supplied" , function ( ) {
174+ delete mockServerless . service . custom . documentation . title ;
175+ const definitionGenerator = new DefinitionGenerator (
176+ mockServerless ,
177+ logger
178+ ) ;
179+ definitionGenerator . createInfo ( ) ;
179180
180- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
181- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
182- expect ( definitionGenerator . openAPI . info . title ) . to . be . equal (
183- mockServerless . service . service
184- ) ;
185- } ) ;
181+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
182+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
183+ expect ( definitionGenerator . openAPI . info . title ) . to . be . equal (
184+ mockServerless . service . service
185+ ) ;
186+ } ) ;
186187
187- it ( "should use the service name when documentation description has not been supplied" , function ( ) {
188- delete mockServerless . service . custom . documentation . description ;
189- const definitionGenerator = new DefinitionGenerator (
190- mockServerless ,
191- logger
192- ) ;
193- definitionGenerator . createInfo ( ) ;
188+ it ( "should use the service name when documentation description has not been supplied" , function ( ) {
189+ delete mockServerless . service . custom . documentation . description ;
190+ const definitionGenerator = new DefinitionGenerator (
191+ mockServerless ,
192+ logger
193+ ) ;
194+ definitionGenerator . createInfo ( ) ;
194195
195- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
196- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
197- expect ( definitionGenerator . openAPI . info . description ) . to . be . equal ( "" ) ;
198- } ) ;
196+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
197+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
198+ expect ( definitionGenerator . openAPI . info . description ) . to . be . equal ( "" ) ;
199+ } ) ;
199200
200- it ( "should use an empty string when documentation description has not been supplied" , function ( ) {
201- delete mockServerless . service . custom . documentation . description ;
202- const definitionGenerator = new DefinitionGenerator (
203- mockServerless ,
204- logger
205- ) ;
206- definitionGenerator . createInfo ( ) ;
201+ it ( "should use an empty string when documentation description has not been supplied" , function ( ) {
202+ delete mockServerless . service . custom . documentation . description ;
203+ const definitionGenerator = new DefinitionGenerator (
204+ mockServerless ,
205+ logger
206+ ) ;
207+ definitionGenerator . createInfo ( ) ;
207208
208- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
209- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
210- expect ( definitionGenerator . openAPI . info . description ) . to . be . equal ( "" ) ;
211- } ) ;
209+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
210+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
211+ expect ( definitionGenerator . openAPI . info . description ) . to . be . equal ( "" ) ;
212+ } ) ;
212213
213- it ( "should generate a uuid for version when documentation version has not been supplied" , function ( ) {
214- delete mockServerless . service . custom . documentation . version ;
214+ it ( "should generate a uuid for version when documentation version has not been supplied" , function ( ) {
215+ delete mockServerless . service . custom . documentation . version ;
215216
216- const definitionGenerator = new DefinitionGenerator (
217- mockServerless ,
218- logger
219- ) ;
220- definitionGenerator . createInfo ( ) ;
217+ const definitionGenerator = new DefinitionGenerator (
218+ mockServerless ,
219+ logger
220+ ) ;
221+ definitionGenerator . createInfo ( ) ;
221222
222- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
223- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
224- expect ( v4 . test ( definitionGenerator . openAPI . info . version ) ) . to . be . true ;
223+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
224+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
225+ expect ( v4 . test ( definitionGenerator . openAPI . info . version ) ) . to . be . true ;
226+ } ) ;
225227 } ) ;
226228
227- it ( "should assign a contact Object when a contact object is included" , function ( ) {
228- mockServerless . service . custom . documentation . contact = {
229- name : "John" ,
230- url : "http://example.com" ,
231- email : "john@example.com" ,
232- } ;
233- const definitionGenerator = new DefinitionGenerator (
234- mockServerless ,
235- logger
236- ) ;
237- definitionGenerator . createInfo ( ) ;
229+ describe ( `termsOfService` , function ( ) {
230+ it ( `should add a termsOfService when specified` , function ( ) {
231+ mockServerless . service . custom . documentation . termsOfService = 'https://example.com/ToS'
232+ const definitionGenerator = new DefinitionGenerator (
233+ mockServerless ,
234+ logger
235+ ) ;
236+ definitionGenerator . createInfo ( ) ;
238237
239- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
240- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
241- expect ( definitionGenerator . openAPI . info ) . to . have . property ( "contact" ) ;
242- expect ( definitionGenerator . openAPI . info . contact ) . to . be . an ( "object" ) ;
243- expect ( definitionGenerator . openAPI . info . contact . name ) . to . be . an ( "string" ) ;
238+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
239+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
240+ expect ( definitionGenerator . openAPI . info ) . to . have . property ( "termsOfService" ) ;
241+ expect ( definitionGenerator . openAPI . info . termsOfService ) . to . be . an ( "string" ) ;
242+ expect ( definitionGenerator . openAPI . info . termsOfService ) . to . be . equal ( 'https://example.com/ToS' )
243+ } ) ;
244244 } ) ;
245245
246- it ( "should only assign a contact url if one is provided" , function ( ) {
247- mockServerless . service . custom . documentation . contact = {
248- name : "John" ,
249- email : "john@example.com" ,
250- } ;
251- const definitionGenerator = new DefinitionGenerator (
252- mockServerless ,
253- logger
254- ) ;
255- definitionGenerator . createInfo ( ) ;
246+ describe ( `contact` , function ( ) {
247+ it ( "should assign a contact Object when a contact object is included" , function ( ) {
248+ mockServerless . service . custom . documentation . contact = {
249+ name : "John" ,
250+ url : "http://example.com" ,
251+ email : "john@example.com" ,
252+ } ;
253+ const definitionGenerator = new DefinitionGenerator (
254+ mockServerless ,
255+ logger
256+ ) ;
257+ definitionGenerator . createInfo ( ) ;
256258
257- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
258- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
259- expect ( definitionGenerator . openAPI . info ) . to . have . property ( "contact" ) ;
260- expect ( definitionGenerator . openAPI . info . contact ) . to . be . an ( "object" ) ;
261- expect ( definitionGenerator . openAPI . info . contact . name ) . to . be . an ( "string" ) ;
262- expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
263- "url"
264- ) ;
265- } ) ;
259+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
260+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
261+ expect ( definitionGenerator . openAPI . info ) . to . have . property ( "contact" ) ;
262+ expect ( definitionGenerator . openAPI . info . contact ) . to . be . an ( "object" ) ;
263+ expect ( definitionGenerator . openAPI . info . contact ) . to . have . property ( "name" ) ;
264+ expect ( definitionGenerator . openAPI . info . contact ) . to . have . property ( "url" ) ;
265+ expect ( definitionGenerator . openAPI . info . contact ) . to . have . property ( "email" ) ;
266+ expect ( definitionGenerator . openAPI . info . contact . name ) . to . be . an ( "string" ) ;
267+ expect ( definitionGenerator . openAPI . info . contact . url ) . to . be . an ( "string" ) ;
268+ expect ( definitionGenerator . openAPI . info . contact . email ) . to . be . an ( "string" ) ;
269+ } ) ;
266270
267- it ( "should assign a license Object when a license object is included with a name " , function ( ) {
268- mockServerless . service . custom . documentation . license = {
269- name : "Apache 2.0 " ,
270- url : "https://www.apache.org/licenses/LICENSE-2.0.html " ,
271- } ;
272- const definitionGenerator = new DefinitionGenerator (
273- mockServerless ,
274- logger
275- ) ;
276- definitionGenerator . createInfo ( ) ;
271+ it ( "should only assign a contact url if one is provided " , function ( ) {
272+ mockServerless . service . custom . documentation . contact = {
273+ name : "John " ,
274+ email : "john@example.com " ,
275+ } ;
276+ const definitionGenerator = new DefinitionGenerator (
277+ mockServerless ,
278+ logger
279+ ) ;
280+ definitionGenerator . createInfo ( ) ;
277281
278- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
279- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
280- expect ( definitionGenerator . openAPI . info ) . to . have . property ( "license" ) ;
281- expect ( definitionGenerator . openAPI . info . license ) . to . be . an ( "object" ) ;
282- expect ( definitionGenerator . openAPI . info . license . name ) . to . be . an ( "string" ) ;
282+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
283+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
284+ expect ( definitionGenerator . openAPI . info ) . to . have . property ( "contact" ) ;
285+ expect ( definitionGenerator . openAPI . info . contact ) . to . be . an ( "object" ) ;
286+ expect ( definitionGenerator . openAPI . info . contact . name ) . to . be . an ( "string" ) ;
287+ expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
288+ "url"
289+ ) ;
290+ } ) ;
291+
292+ it ( "should only assign a contact email if one is provided" , function ( ) {
293+ mockServerless . service . custom . documentation . contact = {
294+ name : "John" ,
295+ } ;
296+ const definitionGenerator = new DefinitionGenerator (
297+ mockServerless ,
298+ logger
299+ ) ;
300+ definitionGenerator . createInfo ( ) ;
301+
302+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
303+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
304+ expect ( definitionGenerator . openAPI . info ) . to . have . property ( "contact" ) ;
305+ expect ( definitionGenerator . openAPI . info . contact ) . to . be . an ( "object" ) ;
306+ expect ( definitionGenerator . openAPI . info . contact . name ) . to . be . an ( "string" ) ;
307+ expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
308+ "url"
309+ ) ;
310+ expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
311+ "email"
312+ ) ;
313+ } ) ;
314+
315+ it ( "should only assign a contact name if one is provided" , function ( ) {
316+ mockServerless . service . custom . documentation . contact = { } ;
317+ const definitionGenerator = new DefinitionGenerator (
318+ mockServerless ,
319+ logger
320+ ) ;
321+ definitionGenerator . createInfo ( ) ;
322+
323+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
324+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
325+ expect ( definitionGenerator . openAPI . info ) . to . have . property ( "contact" ) ;
326+ expect ( definitionGenerator . openAPI . info . contact ) . to . be . an ( "object" ) ;
327+ expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
328+ "url"
329+ ) ;
330+ expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
331+ "email"
332+ ) ;
333+ expect ( definitionGenerator . openAPI . info . contact ) . to . not . have . property (
334+ "name"
335+ ) ;
336+ } ) ;
283337 } ) ;
284338
285- it ( "should not assign a license Object when a license object is included without a name" , function ( ) {
286- mockServerless . service . custom . documentation . license = {
287- url : "https://www.apache.org/licenses/LICENSE-2.0.html" ,
288- } ;
289- const definitionGenerator = new DefinitionGenerator (
290- mockServerless ,
291- logger
292- ) ;
293- definitionGenerator . createInfo ( ) ;
339+ describe ( `license` , function ( ) {
340+ it ( "should assign a license Object when a license object is included with a name" , function ( ) {
341+ mockServerless . service . custom . documentation . license = {
342+ name : "Apache 2.0" ,
343+ url : "https://www.apache.org/licenses/LICENSE-2.0.html" ,
344+ } ;
345+ const definitionGenerator = new DefinitionGenerator (
346+ mockServerless ,
347+ logger
348+ ) ;
349+ definitionGenerator . createInfo ( ) ;
294350
295- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
296- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
297- expect ( definitionGenerator . openAPI . info ) . to . not . have . property ( "license" ) ;
351+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
352+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
353+ expect ( definitionGenerator . openAPI . info ) . to . have . property ( "license" ) ;
354+ expect ( definitionGenerator . openAPI . info . license ) . to . be . an ( "object" ) ;
355+ expect ( definitionGenerator . openAPI . info . license . name ) . to . be . an ( "string" ) ;
356+ } ) ;
357+
358+ it ( "should not assign a license Object when a license object is included without a name" , function ( ) {
359+ mockServerless . service . custom . documentation . license = {
360+ url : "https://www.apache.org/licenses/LICENSE-2.0.html" ,
361+ } ;
362+ const definitionGenerator = new DefinitionGenerator (
363+ mockServerless ,
364+ logger
365+ ) ;
366+ definitionGenerator . createInfo ( ) ;
367+
368+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
369+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
370+ expect ( definitionGenerator . openAPI . info ) . to . not . have . property ( "license" ) ;
371+ } ) ;
298372 } ) ;
299373
300- it ( "should only assign a contact url if one is provided" , function ( ) {
301- mockServerless . service . custom . documentation . license = {
302- name : "John" ,
303- } ;
304- const definitionGenerator = new DefinitionGenerator (
305- mockServerless ,
306- logger
307- ) ;
308- definitionGenerator . createInfo ( ) ;
374+ describe ( `x-tagGroups` , function ( ) {
375+ it ( `should add a x-tagGroups when specified` , function ( ) {
376+ mockServerless . service . custom . documentation [ 'x-tagGroups' ] = [ { name : 'John' } ]
377+ const definitionGenerator = new DefinitionGenerator (
378+ mockServerless ,
379+ logger
380+ ) ;
381+ definitionGenerator . createInfo ( ) ;
309382
310- expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
311- expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
312- expect ( definitionGenerator . openAPI . info ) . to . have . property ( "license" ) ;
313- expect ( definitionGenerator . openAPI . info . license ) . to . be . an ( "object" ) ;
314- expect ( definitionGenerator . openAPI . info . license . name ) . to . be . an ( "string" ) ;
315- expect ( definitionGenerator . openAPI . info . license ) . to . not . have . property (
316- "url"
317- ) ;
383+ expect ( definitionGenerator . openAPI ) . to . be . an ( "object" ) ;
384+ expect ( definitionGenerator . openAPI . info ) . to . be . an ( "object" ) ;
385+ expect ( definitionGenerator . openAPI ) . to . have . property ( "x-tagGroups" ) ;
386+ expect ( definitionGenerator . openAPI [ 'x-tagGroups' ] ) . to . be . an ( "array" ) ;
387+ } ) ;
318388 } ) ;
319389
320390 it ( "should assign specification extension fields when included" , function ( ) {
0 commit comments