serverless-openapi-documenter 0.0.21 → 0.2.2

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.
package/README.md CHANGED
@@ -82,19 +82,19 @@ Options:
82
82
  | path[path].[operation].servers[].description | functions.functions.[http OR httpApi].documentation.servers.description |
83
83
  | path[path].[operation].servers[].url | functions.functions.[http OR httpApi].documentation.servers.url |
84
84
  | path[path].[operation].deprecated | functions.functions.[http OR httpApi].documentation.deprecated |
85
- | path[path].[operation].parameters | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params |
86
- | path[path].[operation].parameters.name | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.name |
87
- | path[path].[operation].parameters.in | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params |
88
- | path[path].[operation].parameters.description | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.description |
89
- | path[path].[operation].parameters.required | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.required |
90
- | path[path].[operation].parameters.deprecated | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.deprecated |
91
- | path[path].[operation].parameters.allowEmptyValue | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.allowEmptyValue |
92
- | path[path].[operation].parameters.style | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.style |
93
- | path[path].[operation].parameters.explode | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.explode |
94
- | path[path].[operation].parameters.allowReserved | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.allowReserved |
95
- | path[path].[operation].parameters.schema | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.schema |
96
- | path[path].[operation].parameters.example | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.example |
97
- | path[path].[operation].parameters.examples | functions.functions.[http OR httpApi].documentation.[path|query|cookie|header]Params.examples |
85
+ | path[path].[operation].parameters | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params |
86
+ | path[path].[operation].parameters.name | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.name |
87
+ | path[path].[operation].parameters.in | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params |
88
+ | path[path].[operation].parameters.description | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.description |
89
+ | path[path].[operation].parameters.required | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.required |
90
+ | path[path].[operation].parameters.deprecated | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.deprecated |
91
+ | path[path].[operation].parameters.allowEmptyValue | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.allowEmptyValue |
92
+ | path[path].[operation].parameters.style | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.style |
93
+ | path[path].[operation].parameters.explode | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.explode |
94
+ | path[path].[operation].parameters.allowReserved | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.allowReserved |
95
+ | path[path].[operation].parameters.schema | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.schema |
96
+ | path[path].[operation].parameters.example | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.example |
97
+ | path[path].[operation].parameters.examples | functions.functions.[http OR httpApi].documentation.[path/query/cookie/header]Params.examples |
98
98
  | path[path].[operation].requestBody | functions.functions.[http OR httpApi].documentation.requestBody |
99
99
  | path[path].[operation].requestBody.description | functions.functions.[http OR httpApi].documentation.requestBody.description |
100
100
  | path[path].[operation].requestBody.required | functions.functions.[http OR httpApi].documentation.requestBody.required |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "serverless-openapi-documenter",
3
- "version": "0.0.21",
3
+ "version": "0.2.2",
4
4
  "description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -31,7 +31,7 @@
31
31
  "@apidevtools/json-schema-ref-parser": "^9.0.9",
32
32
  "chalk": "^4.1.2",
33
33
  "js-yaml": "^4.1.0",
34
- "json-schema-for-openapi": "^0.2.0",
34
+ "json-schema-for-openapi": "^0.2.1",
35
35
  "oas-validator": "^5.0.8",
36
36
  "openapi-to-postmanv2": "^4.1.0",
37
37
  "swagger2openapi": "^7.0.8",
@@ -396,48 +396,41 @@ class DefinitionGenerator {
396
396
  }
397
397
  }
398
398
 
399
- if (typeof schema !== 'string' && Object.keys(schema).length > 0) {
400
- const convertedSchema = SchemaConvertor.convert(schema)
399
+ const deReferencedSchema = await $RefParser.dereference(schema, this.refParserOptions)
400
+ .catch(err => {
401
+ console.error(err)
402
+ throw err
403
+ })
401
404
 
402
- let schemaName = name
403
- if (this.schemaIDs.includes(schemaName))
404
- schemaName = `${name}-${uuid()}`
405
405
 
406
- this.schemaIDs.push(schemaName)
406
+ const convertedSchema = SchemaConvertor.convert(deReferencedSchema)
407
+ let schemaName = name
408
+ if (this.schemaIDs.includes(schemaName))
409
+ schemaName = `${name}-${uuid()}`
407
410
 
408
- for (const key of Object.keys(convertedSchema.schemas)) {
409
- if (key === 'main' || key.split('-')[0] === 'main') {
410
- let ref = `#/components/schemas/`
411
+ this.schemaIDs.push(schemaName)
411
412
 
412
- if (this.openAPI?.components?.schemas?.[name]) {
413
- if (JSON.stringify(convertedSchema.schemas[key]) === JSON.stringify(this.openAPI.components.schemas[name])) {
414
- return `${ref}${name}`
415
- }
413
+ for (const key of Object.keys(convertedSchema.schemas)) {
414
+ if (key === 'main' || key.split('-')[0] === 'main') {
415
+ let ref = `#/components/schemas/`
416
+
417
+ if (this.openAPI?.components?.schemas?.[name]) {
418
+ if (JSON.stringify(convertedSchema.schemas[key]) === JSON.stringify(this.openAPI.components.schemas[name])) {
419
+ return `${ref}${name}`
416
420
  }
421
+ }
417
422
 
418
- addToComponents(convertedSchema.schemas[key], schemaName)
419
- return `${ref}${schemaName}`
420
- } else {
421
- if (this.openAPI?.components?.schemas?.[key]) {
422
- if (JSON.stringify(convertedSchema.schemas[key]) !== JSON.stringify(this.openAPI.components.schemas[key])) {
423
- addToComponents(convertedSchema.schemas[key], key)
424
- }
425
- } else {
423
+ addToComponents(convertedSchema.schemas[key], schemaName)
424
+ return `${ref}${schemaName}`
425
+ } else {
426
+ if (this.openAPI?.components?.schemas?.[key]) {
427
+ if (JSON.stringify(convertedSchema.schemas[key]) !== JSON.stringify(this.openAPI.components.schemas[key])) {
426
428
  addToComponents(convertedSchema.schemas[key], key)
427
429
  }
430
+ } else {
431
+ addToComponents(convertedSchema.schemas[key], key)
428
432
  }
429
433
  }
430
- } else {
431
- const combinedSchema = await $RefParser.dereference(schema, this.refParserOptions)
432
- .catch(err => {
433
- console.error(err)
434
- throw err
435
- })
436
-
437
- return await this.schemaCreator(combinedSchema, name)
438
- .catch(err => {
439
- throw err
440
- })
441
434
  }
442
435
  }
443
436
 
@@ -270,7 +270,7 @@ describe('DefinitionGenerator', () => {
270
270
  })
271
271
 
272
272
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
273
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
273
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
274
274
  expect(expected).to.equal('#/components/schemas/PutRequest')
275
275
  });
276
276
 
@@ -311,7 +311,7 @@ describe('DefinitionGenerator', () => {
311
311
  })
312
312
 
313
313
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
314
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
314
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
315
315
  expect(expected).to.equal('#/components/schemas/PutRequest')
316
316
 
317
317
  expected = await definitionGenerator.schemaCreator(complexSchema, 'PutRequest')
@@ -320,7 +320,7 @@ describe('DefinitionGenerator', () => {
320
320
  })
321
321
 
322
322
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
323
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
323
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
324
324
  expect(expected).to.equal('#/components/schemas/PutRequest')
325
325
  });
326
326
 
@@ -361,7 +361,7 @@ describe('DefinitionGenerator', () => {
361
361
  })
362
362
 
363
363
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
364
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
364
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
365
365
  expect(expected).to.equal('#/components/schemas/PutRequest')
366
366
 
367
367
  complexSchema.properties.cheese = {
@@ -374,7 +374,7 @@ describe('DefinitionGenerator', () => {
374
374
  })
375
375
 
376
376
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
377
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
377
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
378
378
 
379
379
  let newSchemaStr = expected.split('/')
380
380
  expect(v4.test(newSchemaStr[newSchemaStr.length-1].split('PutRequest-')[1])).to.be.true
@@ -401,7 +401,7 @@ describe('DefinitionGenerator', () => {
401
401
  })
402
402
 
403
403
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
404
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
404
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
405
405
  expect(definitionGenerator.openAPI.components.schemas).to.have.property(newSchemaStr[newSchemaStr.length-1])
406
406
  newSchemaStr = expected.split('/')
407
407
  expect(v4.test(newSchemaStr[newSchemaStr.length-1].split('PutRequest-')[1])).to.be.true
@@ -445,7 +445,7 @@ describe('DefinitionGenerator', () => {
445
445
  })
446
446
 
447
447
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
448
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
448
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
449
449
  expect(expected).to.equal('#/components/schemas/PutRequest')
450
450
 
451
451
  expected = await definitionGenerator.schemaCreator(complexSchema, 'ContactPutRequest')
@@ -454,74 +454,10 @@ describe('DefinitionGenerator', () => {
454
454
  })
455
455
 
456
456
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
457
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
457
+ expect(definitionGenerator.openAPI.components.schemas).to.not.have.property('error')
458
458
  expect(definitionGenerator.openAPI.components.schemas).to.have.property('ContactPutRequest')
459
459
  expect(expected).to.equal('#/components/schemas/ContactPutRequest')
460
460
  });
461
-
462
- it('should not create an object that already references schemas in components', async function() {
463
- const simpleSchema = {
464
- "$schema": "http://json-schema.org/draft-04/schema#",
465
- "title": "JSON API Schema",
466
- "description": "This is a blah blah for responses in the JSON API format. For more, see http://jsonapi.org",
467
- "type": "object",
468
- "properties": {
469
- "meta": {
470
- "type": "string",
471
-
472
- }
473
- }
474
- }
475
- const definitionGenerator = new DefinitionGenerator(mockServerless)
476
- let expected = await definitionGenerator.schemaCreator(simpleSchema, 'meta')
477
- .catch((err) => {
478
- console.error(err)
479
- })
480
-
481
- expect(expected).to.equal('#/components/schemas/meta')
482
-
483
- const complexSchema = {
484
- "$schema": "http://json-schema.org/draft-04/schema#",
485
- "title": "JSON API Schema",
486
- "description": "This is a blah blah for responses in the JSON API format. For more, see http://jsonapi.org",
487
- "type": "object",
488
- "required": [
489
- "errors"
490
- ],
491
- "properties": {
492
- "errors": {
493
- "type": "array",
494
- "items": {
495
- "$ref": "#/definitions/error"
496
- },
497
- "uniqueItems": true
498
- },
499
- "meta": {
500
- "$ref": "#/definitions/meta"
501
- }
502
- },
503
- "definitions": {
504
- "error": {
505
- "type": "object",
506
- "properties": {
507
- "id": {
508
- "description": "A unique identifier for this particular occurrence of the problem.",
509
- "type": "string"
510
- }
511
- }
512
- }
513
- }
514
- }
515
-
516
- expected = await definitionGenerator.schemaCreator(complexSchema, 'PutRequest')
517
- .catch((err) => {
518
- console.error(err)
519
- })
520
-
521
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('PutRequest')
522
- expect(definitionGenerator.openAPI.components.schemas).to.have.property('error')
523
- expect(expected).to.equal('#/components/schemas/PutRequest')
524
- });
525
461
  });
526
462
 
527
463
  describe('schemas that are urls', () => {