apidoc-mock
Advanced tools
Comparing version 4.0.6 to 4.0.7
@@ -6,4 +6,21 @@ # Changelog | ||
## [4.0.6](https://github.com/cdcabrera/apidoc-mock/compare/1f64114b597da92f303f8bbb55b6d25574ccacee...1779e2183a83ac140454b59a424f964d67e1f9e7) (2022-11-05) | ||
## [4.0.7](https://github.com/cdcabrera/apidoc-mock/compare/4cb87ab9c6400b8946c3a063f0de1d494675b80c...6cd550af6653ff85af1a462e2335f63da52da566) (2023-01-05) | ||
### Code Refactoring | ||
* **build,parseApi** minor syntax updates ([#190](https://github.com/cdcabrera/apidoc-mock/pull/190)) ([331b0a0](https://github.com/cdcabrera/apidoc-mock/commit/331b0a066dd3d8b7aaf24a592941f9a11f0a1af6)) | ||
### Builds | ||
* **deps-dev** bump eslint from 8.26.0 to 8.31.0 ([#205](https://github.com/cdcabrera/apidoc-mock/pull/205)) ([6cd550a](https://github.com/cdcabrera/apidoc-mock/commit/6cd550af6653ff85af1a462e2335f63da52da566)) | ||
* **deps-dev** eslint-plugin-jest from 27.1.6 to 27.2.0 ([#203](https://github.com/cdcabrera/apidoc-mock/pull/203)) ([ae96f0e](https://github.com/cdcabrera/apidoc-mock/commit/ae96f0e33a339857a6ecf56d9253e8902c83c09b)) | ||
* **deps-dev** npm-check-updates from 16.6.0 to 16.6.2 ([#206](https://github.com/cdcabrera/apidoc-mock/pull/206)) ([623a530](https://github.com/cdcabrera/apidoc-mock/commit/623a5309ca918b63d10ae7a4cba9f6fca18e663f)) | ||
* **deps-dev** changelog-light from 0.2.2 to 0.2.3 ([#204](https://github.com/cdcabrera/apidoc-mock/pull/204)) ([58321a9](https://github.com/cdcabrera/apidoc-mock/commit/58321a9cc3c25b543a2c9f4c2059a375a989946c)) | ||
* **deps-dev** npm-check-updates from 16.3.16 to 16.6.0 ([#201](https://github.com/cdcabrera/apidoc-mock/pull/201)) ([4b622f9](https://github.com/cdcabrera/apidoc-mock/commit/4b622f9753d8b3e1344347ee3fef8007bcdcafac)) | ||
* **deps-dev** bump prettier from 2.7.1 to 2.8.1 ([#199](https://github.com/cdcabrera/apidoc-mock/pull/199)) ([2253fe8](https://github.com/cdcabrera/apidoc-mock/commit/2253fe83aac4e27fa72f7b08cbab2689fd4d368a)) | ||
* **deps-dev** bump jest from 29.2.2 to 29.3.1 ([#194](https://github.com/cdcabrera/apidoc-mock/pull/194)) ([d6dc629](https://github.com/cdcabrera/apidoc-mock/commit/d6dc629867d603edf77fc06364e423f2eae08724)) | ||
* **deps-dev** eslint-plugin-jest from 27.1.4 to 27.1.6 ([#195](https://github.com/cdcabrera/apidoc-mock/pull/195)) ([9bf0cdb](https://github.com/cdcabrera/apidoc-mock/commit/9bf0cdb0cf2342a4118fc931d60345006f9851f9)) | ||
* **deps-dev** eslint-plugin-jsdoc from 39.6.2 to 39.6.4 ([#196](https://github.com/cdcabrera/apidoc-mock/pull/196)) ([77bf5b6](https://github.com/cdcabrera/apidoc-mock/commit/77bf5b6c6c904bee2bfee480ed1c30aeb808b559)) | ||
## [4.0.6](https://github.com/cdcabrera/apidoc-mock/compare/1f64114b597da92f303f8bbb55b6d25574ccacee...1779e2183a83ac140454b59a424f964d67e1f9e7) (2022-11-05) | ||
### Chores | ||
@@ -10,0 +27,0 @@ * **build** npm updates ([#191](https://github.com/cdcabrera/apidoc-mock/pull/191)) ([1779e21](https://github.com/cdcabrera/apidoc-mock/commit/1779e2183a83ac140454b59a424f964d67e1f9e7)) |
{ | ||
"name": "apidoc-mock", | ||
"version": "4.0.6", | ||
"version": "4.0.7", | ||
"description": "Create a mock server from apiDoc comments.", | ||
@@ -70,16 +70,16 @@ "author": "cdcabrera", | ||
"devDependencies": { | ||
"changelog-light": "^0.2.2", | ||
"eslint": "^8.26.0", | ||
"changelog-light": "^0.2.3", | ||
"eslint": "^8.31.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-babel": "^5.3.1", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^27.1.4", | ||
"eslint-plugin-jsdoc": "^39.6.2", | ||
"eslint-plugin-jest": "^27.2.0", | ||
"eslint-plugin-jsdoc": "^39.6.4", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^4.2.1", | ||
"jest": "^29.2.2", | ||
"jest": "^29.3.1", | ||
"nodemon": "^2.0.20", | ||
"npm-check-updates": "^16.3.16", | ||
"npm-check-updates": "^16.6.2", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^2.7.1" | ||
"prettier": "^2.8.1" | ||
}, | ||
@@ -86,0 +86,0 @@ "resolutions": { |
@@ -47,9 +47,10 @@ const { logger } = require('../logger/configLogger'); | ||
apiJson.forEach(value => { | ||
apiJson.forEach((value = {}) => { | ||
const { error = {}, header, success = {}, type, url } = value; | ||
try { | ||
const successExamples = (value.success && value.success.examples) || []; | ||
const errorExamples = (value.error && value.error.examples) || []; | ||
const successExamples = success?.examples || []; | ||
const errorExamples = error?.examples || []; | ||
const mockSettings = parseCustomMockSettings(value); | ||
const successObjects = parseStatus(successExamples, 'success', value.type, value.url); | ||
const errorObjects = parseStatus(errorExamples, 'error', value.type, value.url); | ||
const successObjects = parseStatus(successExamples, 'success', type, url); | ||
const errorObjects = parseStatus(errorExamples, 'error', type, url); | ||
const authExample = parseAuthExample(errorObjects); | ||
@@ -65,4 +66,4 @@ const exampleObjects = successObjects.concat(errorObjects); | ||
appResponses.push({ | ||
type: value.type, | ||
url: value.url, | ||
type, | ||
url, | ||
callback: (request, response) => { | ||
@@ -78,36 +79,30 @@ if (mockSettings.reload) { | ||
if (httpStatus < 500) { | ||
if (value.header && value.header.fields.Header && value.header.fields.Header.length) { | ||
for (let i = 0; i < value.header.fields.Header.length; i++) { | ||
const headerValue = value.header.fields.Header[i]; | ||
if (httpStatus < 500 && Array.isArray(header?.fields?.Header)) { | ||
header?.fields?.Header?.forEach(headerValue => { | ||
if ( | ||
!headerValue.optional && | ||
headerValue.field && | ||
/authorization/i.test(headerValue.field) | ||
) { | ||
const authorization = request.get('authorization'); | ||
if ( | ||
!headerValue.optional && | ||
headerValue.field && | ||
/authorization/i.test(headerValue.field) | ||
) { | ||
const authorization = request.get('authorization'); | ||
if (!authorization) { | ||
const authObj = parseContentAndType(authExample.content, authExample.type); | ||
if (!authorization) { | ||
const authObj = parseContentAndType(authExample.content, authExample.type); | ||
response.append('WWW-Authenticate', 'Spoof response'); | ||
response.status(401); | ||
response.set('Content-Type', authObj.type); | ||
response.append('WWW-Authenticate', 'Spoof response'); | ||
response.status(401); | ||
response.set('Content-Type', authObj.type); | ||
if (mockSettings.delay > 0) { | ||
logger.info(`waiting\t:401 :${type} :${url}`); | ||
} | ||
if (mockSettings.delay > 0) { | ||
logger.info(`waiting\t:401 :${value.type} :${value.url}`); | ||
} | ||
setTimeout(() => { | ||
logger.info(`response\t:401 :${type} :${url}`); | ||
setTimeout(() => { | ||
logger.info(`response\t:401 :${value.type} :${value.url}`); | ||
response.end(authObj.content || 'Authorization Required'); | ||
}, mockSettings.delay || 0); | ||
return; | ||
} | ||
response.end(authObj.content || 'Authorization Required'); | ||
}, mockSettings.delay || 0); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
@@ -119,7 +114,7 @@ | ||
if (mockSettings.delay > 0) { | ||
logger.info(`waiting\t:${httpStatus} :${value.type} :${value.url}`); | ||
logger.info(`waiting\t:${httpStatus} :${type} :${url}`); | ||
} | ||
setTimeout(() => { | ||
logger.info(`response\t:${httpStatus} :${value.type} :${value.url}`); | ||
logger.info(`response\t:${httpStatus} :${type} :${url}`); | ||
@@ -126,0 +121,0 @@ response.send(content); |
@@ -92,49 +92,47 @@ const { logger } = require('../logger/configLogger'); | ||
*/ | ||
const parseCustomMockSettings = ({ mock = null }) => { | ||
const parseCustomMockSettings = ({ mock = null } = {}) => { | ||
const settings = {}; | ||
if (mock && mock.settings && mock.settings.length) { | ||
mock.settings.forEach(val => { | ||
const keys = Object.keys(val); | ||
const key = keys[0] || ''; | ||
mock?.settings?.forEach(val => { | ||
const keys = Object.keys(val); | ||
const key = keys[0] || ''; | ||
switch (key.toLowerCase()) { | ||
case 'delay': | ||
case 'delayresponse': | ||
settings.delay = Number.parseInt(val[key], 10); | ||
switch (key.toLowerCase()) { | ||
case 'delay': | ||
case 'delayresponse': | ||
settings.delay = Number.parseInt(val[key], 10); | ||
if (Number.isNaN(settings.delay)) { | ||
settings.delay = 1000; | ||
} | ||
if (Number.isNaN(settings.delay)) { | ||
settings.delay = 1000; | ||
} | ||
break; | ||
case 'force': | ||
case 'forcestatus': | ||
case 'forcedstatus': | ||
settings.forceStatus = Number.parseInt(val[key], 10); | ||
break; | ||
case 'force': | ||
case 'forcestatus': | ||
case 'forcedstatus': | ||
settings.forceStatus = Number.parseInt(val[key], 10); | ||
if (Number.isNaN(settings.forceStatus)) { | ||
settings.forceStatus = 200; | ||
} | ||
if (Number.isNaN(settings.forceStatus)) { | ||
settings.forceStatus = 200; | ||
} | ||
break; | ||
case 'response': | ||
settings.response = 'response'; | ||
break; | ||
case 'random': | ||
case 'randomresponse': | ||
settings.response = 'response'; | ||
settings.reload = true; | ||
break; | ||
case 'randomsuccess': | ||
settings.response = 'success'; | ||
settings.reload = true; | ||
break; | ||
case 'randomerror': | ||
settings.response = 'error'; | ||
settings.reload = true; | ||
break; | ||
} | ||
}); | ||
} | ||
break; | ||
case 'response': | ||
settings.response = 'response'; | ||
break; | ||
case 'random': | ||
case 'randomresponse': | ||
settings.response = 'response'; | ||
settings.reload = true; | ||
break; | ||
case 'randomsuccess': | ||
settings.response = 'success'; | ||
settings.reload = true; | ||
break; | ||
case 'randomerror': | ||
settings.response = 'error'; | ||
settings.reload = true; | ||
break; | ||
} | ||
}); | ||
@@ -141,0 +139,0 @@ return settings; |
@@ -13,3 +13,3 @@ const fs = require('fs'); | ||
*/ | ||
const buildDocs = ({ apiDocsConfig = null, apiJsonFile = null }) => { | ||
const buildDocs = ({ apiDocsConfig = null, apiJsonFile = null } = {}) => { | ||
let result; | ||
@@ -16,0 +16,0 @@ |
@@ -76,3 +76,3 @@ const fs = require('fs'); | ||
*/ | ||
const apiDocMock = ({ port = 8000, dataPath, docsPath = '.docs' }) => { | ||
const apiDocMock = ({ port = 8000, dataPath, docsPath = '.docs' } = {}) => { | ||
const apiJson = setupDocs(dataPath, docsPath); | ||
@@ -79,0 +79,0 @@ let server = null; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
42873
582