@kravc/dos 1.8.8 → 1.8.9
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/package.json +3 -2
- package/specs/Documents.yaml +1 -0
- package/specs/Enums.yaml +1 -0
- package/specs/Operations.yaml +1 -0
- package/specs/Parameters.yaml +1 -0
- package/specs/Scenarios.yaml +1 -0
- package/specs/Schemas.yaml +1 -0
- package/src/Service.spec.js +8 -0
- package/src/helpers/specMiddleware.js +30 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kravc/dos",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9",
|
|
4
4
|
"description": "Convention-based, easy-to-use library for building API-driven serverless services.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Service",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"pluralize": "^8.0.0",
|
|
34
34
|
"ulid": "^2.3.0",
|
|
35
35
|
"uuid": "^9.0.1",
|
|
36
|
-
"z-schema": "^6.0.1"
|
|
36
|
+
"z-schema": "^6.0.1",
|
|
37
|
+
"read-yaml-file": "^2.1.0"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@eslint/eslintrc": "^3.2.0",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/specs/Enums.yaml
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
[]
|
package/src/Service.spec.js
CHANGED
|
@@ -289,6 +289,14 @@ describe('Service', () => {
|
|
|
289
289
|
const body = JSON.parse(response.body)
|
|
290
290
|
expect(body.swagger).to.exist
|
|
291
291
|
|
|
292
|
+
response = await lambdaFunction({ path: '/Documents.yaml', httpMethod: 'GET' })
|
|
293
|
+
response = await lambdaFunction({ path: '/Enums.yaml', httpMethod: 'GET' })
|
|
294
|
+
response = await lambdaFunction({ path: '/Operations.yaml', httpMethod: 'GET' })
|
|
295
|
+
response = await lambdaFunction({ path: '/Parameters.yaml', httpMethod: 'GET' })
|
|
296
|
+
response = await lambdaFunction({ path: '/Schenarios.yaml', httpMethod: 'GET' })
|
|
297
|
+
response = await lambdaFunction({ path: '/Schemas.yaml', httpMethod: 'GET' })
|
|
298
|
+
expect(response.statusCode).to.eql(200)
|
|
299
|
+
|
|
292
300
|
process.env.NODE_APP_INSTANCE = undefined
|
|
293
301
|
})
|
|
294
302
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { resolve }
|
|
3
|
+
const { resolve } = require('path')
|
|
4
|
+
const readYamlFile = require('read-yaml-file')
|
|
4
5
|
const { readFileSync } = require('fs')
|
|
5
6
|
|
|
6
7
|
const SWAGGER_UI_TEMPLATE_PATH = resolve(__dirname, '../../assets/index.html')
|
|
@@ -46,6 +47,34 @@ const specMiddleware = (service, context) => {
|
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
const readFileJson = httpPath => {
|
|
51
|
+
const fileName = httpPath.replace('/', '')
|
|
52
|
+
const source = readYamlFile.sync(`${ROOT_PATH}/specs/${fileName}`)
|
|
53
|
+
|
|
54
|
+
return JSON.stringify(source, null, 2)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const isComposer = [
|
|
58
|
+
'/Enums.yaml',
|
|
59
|
+
'/Schemas.yaml',
|
|
60
|
+
'/Documents.yaml',
|
|
61
|
+
'/Scenarios.yaml',
|
|
62
|
+
'/Operations.yaml',
|
|
63
|
+
'/Parameters.yaml'
|
|
64
|
+
].includes(httpPath)
|
|
65
|
+
|
|
66
|
+
const shouldReturnComposerSpecs = isComposer && isDevelopment()
|
|
67
|
+
|
|
68
|
+
if (shouldReturnComposerSpecs) {
|
|
69
|
+
return {
|
|
70
|
+
headers: {
|
|
71
|
+
'Content-Type': 'application/json; charset=utf-8'
|
|
72
|
+
},
|
|
73
|
+
statusCode: 200,
|
|
74
|
+
body: readFileJson(httpPath),
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
49
78
|
return null
|
|
50
79
|
}
|
|
51
80
|
|