serverless-openapi-documenter 0.0.40 → 0.0.42
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 +1 -1
- package/package.json +8 -3
- package/src/definitionGenerator.js +9 -3
- package/test/unit/definitionGenerator.spec.js +51 -29
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
This will generate an OpenAPI V3 (up to v3.0.3) file for you from your serverless file. It can optionally generate a Postman Collection V2 from the OpenAPI file for you too.
|
|
17
|
+
This will generate an OpenAPI V3 (up to v3.0.3) file for you from your serverless file. It can optionally generate a [Postman Collection V2](https://github.com/postmanlabs/openapi-to-postman) from the OpenAPI file for you too.
|
|
18
18
|
|
|
19
19
|
Originally based off of: https://github.com/temando/serverless-openapi-documentation
|
|
20
20
|
|
package/package.json
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "serverless-openapi-documenter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"description": "Generate OpenAPI v3 documentation and Postman Collections from your Serverless Config",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"serverless",
|
|
8
8
|
"serverless2",
|
|
9
9
|
"serverless3",
|
|
10
|
+
"serverless framework",
|
|
11
|
+
"serverless framework plugin",
|
|
12
|
+
"serverless plugin",
|
|
10
13
|
"openAPI",
|
|
11
14
|
"openAPIv3",
|
|
12
15
|
"openAPI3",
|
|
13
16
|
"PostmanCollections",
|
|
14
|
-
"Postman-Collections"
|
|
17
|
+
"Postman-Collections",
|
|
18
|
+
"Postman Collections"
|
|
15
19
|
],
|
|
16
20
|
"scripts": {
|
|
17
21
|
"test": "mocha --config './test/.mocharc.js'"
|
|
@@ -34,7 +38,7 @@
|
|
|
34
38
|
"json-schema-for-openapi": "^0.3.1",
|
|
35
39
|
"lodash.isequal": "^4.5.0",
|
|
36
40
|
"oas-validator": "^5.0.8",
|
|
37
|
-
"openapi-to-postmanv2": "^4.
|
|
41
|
+
"openapi-to-postmanv2": "^4.6.0",
|
|
38
42
|
"swagger2openapi": "^7.0.8",
|
|
39
43
|
"uuid": "^9.0.0"
|
|
40
44
|
},
|
|
@@ -44,6 +48,7 @@
|
|
|
44
48
|
"devDependencies": {
|
|
45
49
|
"chai": "^4.3.7",
|
|
46
50
|
"mocha": "^10.2.0",
|
|
51
|
+
"nock": "^13.2.9",
|
|
47
52
|
"sinon": "^15.0.0"
|
|
48
53
|
}
|
|
49
54
|
}
|
|
@@ -461,15 +461,21 @@ class DefinitionGenerator {
|
|
|
461
461
|
}
|
|
462
462
|
|
|
463
463
|
async dereferenceSchema(schema) {
|
|
464
|
-
let
|
|
464
|
+
let originalSchema = await $RefParser.bundle(schema, this.refParserOptions)
|
|
465
|
+
.catch(err => {
|
|
466
|
+
console.error(err)
|
|
467
|
+
throw err
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
let deReferencedSchema = await $RefParser.dereference(originalSchema, this.refParserOptions)
|
|
465
471
|
.catch(err => {
|
|
466
472
|
console.error(err)
|
|
467
473
|
throw err
|
|
468
474
|
})
|
|
469
475
|
|
|
470
476
|
// deal with schemas that have been de-referenced poorly: naive
|
|
471
|
-
if (deReferencedSchema
|
|
472
|
-
const oldRef =
|
|
477
|
+
if (deReferencedSchema?.$ref === '#') {
|
|
478
|
+
const oldRef = originalSchema.$ref
|
|
473
479
|
const path = oldRef.split('/')
|
|
474
480
|
|
|
475
481
|
const pathTitle = path[path.length-1]
|
|
@@ -4,6 +4,7 @@ const fs = require('fs').promises
|
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const sinon = require('sinon')
|
|
6
6
|
const $RefParser = require("@apidevtools/json-schema-ref-parser")
|
|
7
|
+
const nock = require('nock')
|
|
7
8
|
const expect = require('chai').expect
|
|
8
9
|
|
|
9
10
|
const serverlessMock = require('../helpers/serverless')
|
|
@@ -948,10 +949,13 @@ describe('DefinitionGenerator', () => {
|
|
|
948
949
|
|
|
949
950
|
describe('schemas that are urls', () => {
|
|
950
951
|
it('should attempt to download a schema and convert it', async function() {
|
|
951
|
-
const simpleSchema = 'https
|
|
952
|
+
const simpleSchema = 'https://google.com/build/LicensedMember.json'
|
|
952
953
|
const LicensedMemberJSON = require('../json/complex.json')
|
|
953
954
|
|
|
954
|
-
const
|
|
955
|
+
const scope = nock('https://google.com')
|
|
956
|
+
.get('/build/LicensedMember.json')
|
|
957
|
+
.reply(200, LicensedMemberJSON)
|
|
958
|
+
|
|
955
959
|
const definitionGenerator = new DefinitionGenerator(mockServerless)
|
|
956
960
|
const expected = await definitionGenerator.schemaCreator(simpleSchema, 'LicensedMember')
|
|
957
961
|
.catch((err) => {
|
|
@@ -963,28 +967,16 @@ describe('DefinitionGenerator', () => {
|
|
|
963
967
|
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties).to.have.property('template')
|
|
964
968
|
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties).to.have.property('database')
|
|
965
969
|
expect(expected).to.equal('#/components/schemas/LicensedMember')
|
|
966
|
-
|
|
967
|
-
stub.restore()
|
|
968
970
|
});
|
|
969
971
|
|
|
970
972
|
it('should take a mix of schemas', async function() {
|
|
971
|
-
const complexSchema = 'https
|
|
973
|
+
const complexSchema = 'https://google.com/build/LicensedMember.json'
|
|
972
974
|
const LicensedMemberJSON = require('../json/complex.json')
|
|
973
975
|
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
.
|
|
977
|
-
|
|
978
|
-
type: "object",
|
|
979
|
-
properties: {
|
|
980
|
-
UUID: {
|
|
981
|
-
$ref: "#/definitions/log"
|
|
982
|
-
},
|
|
983
|
-
name: {
|
|
984
|
-
type: "string"
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
})
|
|
976
|
+
const scope = nock('https://google.com')
|
|
977
|
+
.get('/build/LicensedMember.json')
|
|
978
|
+
.reply(200, LicensedMemberJSON)
|
|
979
|
+
|
|
988
980
|
const definitionGenerator = new DefinitionGenerator(mockServerless)
|
|
989
981
|
let expected = await definitionGenerator.schemaCreator(complexSchema, 'LicensedMember')
|
|
990
982
|
.catch((err) => {
|
|
@@ -1007,35 +999,65 @@ describe('DefinitionGenerator', () => {
|
|
|
1007
999
|
|
|
1008
1000
|
expected = await definitionGenerator.schemaCreator(simpleSchema, 'simpleSchema')
|
|
1009
1001
|
.catch((err) => {
|
|
1002
|
+
expect(err).to.be.an('error')
|
|
1010
1003
|
console.error(err)
|
|
1011
1004
|
})
|
|
1012
1005
|
|
|
1006
|
+
expect(expected).to.be.undefined
|
|
1013
1007
|
expect(definitionGenerator.openAPI.components.schemas).to.have.property('LicensedMember')
|
|
1014
1008
|
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties).to.have.property('log')
|
|
1015
1009
|
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties).to.have.property('template')
|
|
1016
1010
|
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties).to.have.property('database')
|
|
1017
|
-
expect(definitionGenerator.openAPI.components.schemas).to.have.property('simpleSchema')
|
|
1018
|
-
expect(definitionGenerator.openAPI.components.schemas.simpleSchema.properties).to.have.property('UUID')
|
|
1019
|
-
expect(definitionGenerator.openAPI.components.schemas.simpleSchema.properties).to.have.property('name')
|
|
1020
|
-
expect(expected).to.equal('#/components/schemas/simpleSchema')
|
|
1021
|
-
|
|
1022
|
-
stub.restore()
|
|
1023
1011
|
});
|
|
1024
1012
|
|
|
1025
1013
|
it('should throw an error when a url can not be resolved', async function() {
|
|
1026
|
-
const simpleSchema = 'https
|
|
1014
|
+
const simpleSchema = 'https://google.com/build/LicensedMember.json'
|
|
1015
|
+
|
|
1016
|
+
const scope = nock('https://google.com')
|
|
1017
|
+
.get('/build/LicensedMember.json')
|
|
1018
|
+
.reply(404)
|
|
1027
1019
|
|
|
1028
|
-
const stub = sinon.stub($RefParser, 'dereference').rejects(new Error())
|
|
1029
1020
|
const definitionGenerator = new DefinitionGenerator(mockServerless)
|
|
1030
1021
|
const expected = await definitionGenerator.schemaCreator(simpleSchema, 'simpleSchema')
|
|
1031
1022
|
.catch((err) => {
|
|
1032
|
-
console.error(err)
|
|
1033
1023
|
expect(err).to.be.an('error')
|
|
1034
1024
|
})
|
|
1035
1025
|
|
|
1036
1026
|
expect(expected).to.be.undefined
|
|
1027
|
+
});
|
|
1037
1028
|
|
|
1038
|
-
|
|
1029
|
+
it('should handle a poorly dereferenced schema', async function() {
|
|
1030
|
+
const simpleSchema = 'https://google.com/build/LicensedMember.json'
|
|
1031
|
+
|
|
1032
|
+
const externalSchema = {
|
|
1033
|
+
$schema: 'http://json-schema.org/draft-04/schema#',
|
|
1034
|
+
title: 'JSON API Schema',
|
|
1035
|
+
$ref: '#/definitions/Error',
|
|
1036
|
+
definitions: {
|
|
1037
|
+
Error: {
|
|
1038
|
+
type: 'string'
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
const scope = nock('https://google.com')
|
|
1044
|
+
.get('/build/LicensedMember.json')
|
|
1045
|
+
.reply(200, externalSchema)
|
|
1046
|
+
|
|
1047
|
+
|
|
1048
|
+
const definitionGenerator = new DefinitionGenerator(mockServerless)
|
|
1049
|
+
const expected = await definitionGenerator.schemaCreator(simpleSchema, 'LicensedMember')
|
|
1050
|
+
.catch((err) => {
|
|
1051
|
+
console.error(err)
|
|
1052
|
+
})
|
|
1053
|
+
|
|
1054
|
+
expect(definitionGenerator.openAPI.components.schemas).to.have.property('LicensedMember')
|
|
1055
|
+
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties).to.have.property('Error')
|
|
1056
|
+
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties.Error).to.have.property('type')
|
|
1057
|
+
expect(definitionGenerator.openAPI.components.schemas.LicensedMember.properties.Error.type).to.be.equal('string')
|
|
1058
|
+
expect(definitionGenerator.openAPI.components.schemas.LicensedMember).to.not.have.property('$schema')
|
|
1059
|
+
expect(definitionGenerator.openAPI.components.schemas.LicensedMember).to.not.have.property('$definitions')
|
|
1060
|
+
expect(expected).to.equal('#/components/schemas/LicensedMember')
|
|
1039
1061
|
});
|
|
1040
1062
|
});
|
|
1041
1063
|
});
|