open-api-mocker
Advanced tools
Comparing version 1.11.1 to 2.0.0
'use strict'; | ||
const logger = require('lllog')(); | ||
const faker = require('faker'); | ||
const getFakerLocale = require('../utils/get-faker-locale'); | ||
faker.setLocale(getFakerLocale()); | ||
const faker = getFakerLocale(); | ||
@@ -13,3 +12,4 @@ class ResponseGenerator { | ||
if(typeof schemaResponse.example !== 'undefined' || (schemaResponse.examples && Object.values(schemaResponse.examples).length)) { | ||
if((typeof schemaResponse.example !== 'undefined' && !schemaResponse['x-faker']) || | ||
(schemaResponse.examples && Object.values(schemaResponse.examples).length)) { | ||
const bestExample = this.getBestExample(schemaResponse, preferredExampleName); | ||
@@ -37,4 +37,3 @@ if(bestExample !== undefined) | ||
static generateByEnum(enumOptions) { | ||
const randomIndex = Math.floor(Math.random() * enumOptions.length); | ||
return enumOptions[randomIndex]; | ||
return faker.helpers.arrayElement(enumOptions); | ||
} | ||
@@ -101,3 +100,3 @@ | ||
if(fakerString.match(/\{\{.+\}\}/)) | ||
return faker.fake(fakerString); | ||
return faker.helpers.fake(fakerString); | ||
@@ -104,0 +103,0 @@ const fakerRegex = /^(?<namespace>\w+)\.(?<method>\w+)(?:\((?<argsString>.*)\))?$/.exec( |
'use strict'; | ||
const faker = require('faker'); | ||
const { allFakers } = require('@faker-js/faker'); | ||
@@ -22,2 +22,5 @@ const DEFAULT_LOCALE = 'en'; | ||
/** | ||
* @returns {import('@faker-js/faker').Faker} | ||
*/ | ||
const getFakerLocale = (userLocaleParser = parseUserLocale) => { | ||
@@ -27,14 +30,14 @@ | ||
if(faker.locales[userLocale]) | ||
return userLocale; | ||
if(allFakers[userLocale]) | ||
return allFakers[userLocale]; | ||
if(userLocale.includes('_')) { | ||
const [baseUserLocale] = userLocale.split('_'); | ||
if(faker.locales[baseUserLocale]) | ||
return baseUserLocale; | ||
if(allFakers[baseUserLocale]) | ||
return allFakers[baseUserLocale]; | ||
} | ||
return DEFAULT_LOCALE; | ||
return allFakers[DEFAULT_LOCALE]; | ||
}; | ||
module.exports = getFakerLocale; |
{ | ||
"name": "open-api-mocker", | ||
"version": "1.11.1", | ||
"version": "2.0.0", | ||
"description": "A mock server based in Open API Specification", | ||
@@ -13,3 +13,4 @@ "main": "lib/open-api-mocker.js", | ||
"coverage:ci": "nyc --reporter=lcov mocha --recursive tests/", | ||
"coverage": "nyc npm test" | ||
"coverage": "nyc npm test", | ||
"prepare": "husky install" | ||
}, | ||
@@ -30,28 +31,29 @@ "files": [ | ||
"devDependencies": { | ||
"eslint": "^7.32.0", | ||
"eslint-config-airbnb-base": "^14.2.1", | ||
"eslint-plugin-import": "^2.24.2", | ||
"husky": "^4.3.8", | ||
"mocha": "^9.1.2", | ||
"eslint": "^8.41.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-import": "^2.27.5", | ||
"husky": "^8.0.3", | ||
"lint-staged": "^13.2.2", | ||
"mocha": "^10.2.0", | ||
"mock-require": "^3.0.3", | ||
"nyc": "^15.1.0", | ||
"sinon": "^11.1.2" | ||
"sinon": "^15.1.0" | ||
}, | ||
"dependencies": { | ||
"@faker-js/faker": "^8.0.2", | ||
"ajv": "^6.12.6", | ||
"ajv-openapi": "^2.0.0", | ||
"body-parser": "^1.19.0", | ||
"chokidar": "^3.5.2", | ||
"body-parser": "^1.20.2", | ||
"chokidar": "^3.5.3", | ||
"colors": "^1.4.0", | ||
"cookie-parser": "^1.4.5", | ||
"cookie-parser": "^1.4.6", | ||
"cors": "^2.8.5", | ||
"express": "^4.17.1", | ||
"faker": "^5.5.3", | ||
"express": "^4.18.2", | ||
"js-yaml": "^4.1.0", | ||
"json-refs": "^3.0.15", | ||
"lllog": "^1.1.2", | ||
"micro-memoize": "^4.0.9", | ||
"micro-memoize": "^4.1.2", | ||
"parse-prefer-header": "^1.0.0", | ||
"superstruct": "^0.6.2", | ||
"yargs": "^16.2.0" | ||
"yargs": "^17.7.2" | ||
}, | ||
@@ -58,0 +60,0 @@ "directories": { |
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
1609
56595
9
58
+ Added@faker-js/faker@^8.0.2
+ Added@faker-js/faker@8.4.1(transitive)
+ Addedcall-bind@1.0.8(transitive)
+ Addedcall-bound@1.0.2(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddunder-proto@1.0.0(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)
- Removedfaker@^5.5.3
- Removedcall-bound@1.0.3(transitive)
- Removedcliui@7.0.4(transitive)
- Removeddunder-proto@1.0.1(transitive)
- Removedfaker@5.5.3(transitive)
- Removedyargs@16.2.0(transitive)
- Removedyargs-parser@20.2.9(transitive)
Updatedbody-parser@^1.20.2
Updatedchokidar@^3.5.3
Updatedcookie-parser@^1.4.6
Updatedexpress@^4.18.2
Updatedmicro-memoize@^4.1.2
Updatedyargs@^17.7.2