Skip to content

Commit

Permalink
Merge pull request #70 from pmcelhaney/json-schema-faker
Browse files Browse the repository at this point in the history
tools.randomFromSchema()
  • Loading branch information
pmcelhaney committed Jul 12, 2022
2 parents 39ec7e4 + ab38cb2 commit e7907b6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tricky-bikes-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"counterfact": minor
---

add a tools.randomFromSchema(schema: JSONSchema) function
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@
"eslint": "8.18.0",
"eslint-config-hardcore": "24.5.0",
"eslint-formatter-github-annotations": "0.1.0",
"husky": "8.0.1",
"jest": "28.1.2",
"koa": "2.13.4",
"husky": "8.0.1",
"nodemon": "2.0.18",
"stryker-cli": "1.0.2",
"supertest": "6.2.3"
},
"dependencies": {
"chokidar": "^3.5.3"
"chokidar": "^3.5.3",
"json-schema-faker": "^0.5.0-rcv.44"
}
}
6 changes: 6 additions & 0 deletions src/tools.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import JSONSchemaFaker from "json-schema-faker";

export class Tools {
constructor({ headers = {} } = {}) {
this.headers = headers;
Expand Down Expand Up @@ -25,4 +27,8 @@ export class Tools {
);
});
}

randomFromSchema(schema) {
return JSONSchemaFaker.generate(schema);
}
}
6 changes: 6 additions & 0 deletions test/tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,10 @@ describe("tools", () => {
expect(tools.accepts(contentType)).toBe(false);
}
);

it("randomFromSchema() returns a value (the implementation is in a third party library)", () => {
const tools = new Tools();

expect(typeof tools.randomFromSchema({ type: "integer" })).toBe("number");
});
});
41 changes: 40 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3357,6 +3357,11 @@ call-bind@^1.0.0, call-bind@^1.0.2:
function-bind "^1.1.1"
get-intrinsic "^1.0.2"

call-me-maybe@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/call-me-maybe/-/call-me-maybe-1.0.1.tgz#26d208ea89e37b5cbde60250a15f031c16a4d66b"
integrity sha512-wCyFsDQkKPwwF8BDwOiWNx/9K45L/hvggQiDbve+viMNMQnWhrlYIuBk09offfwCRtCO9P6XwUttufzU11WCVw==

callsites@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/callsites/-/callsites-3.1.0.tgz#b3630abd8943432f54b3f0519238e33cd7df2f73"
Expand Down Expand Up @@ -5079,6 +5084,11 @@ format-io@^2.0.0:
dependencies:
currify "^4.0.0"

format-util@^1.0.3:
version "1.0.5"
resolved "https://registry.yarnpkg.com/format-util/-/format-util-1.0.5.tgz#1ffb450c8a03e7bccffe40643180918cc297d271"
integrity sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg==

formidable@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/formidable/-/formidable-2.0.1.tgz#4310bc7965d185536f9565184dee74fbb75557ff"
Expand Down Expand Up @@ -6414,7 +6424,7 @@ js-types@^1.0.0:
resolved "https://registry.yarnpkg.com/js-types/-/js-types-1.0.0.tgz#d242e6494ed572ad3c92809fc8bed7f7687cbf03"
integrity sha1-0kLmSU7Vcq08koCfyL7X92h8vwM=

js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.6.1:
js-yaml@^3.12.1, js-yaml@^3.13.0, js-yaml@^3.13.1, js-yaml@^3.6.1:
version "3.14.1"
resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.14.1.tgz#dae812fdb3825fa306609a8717383c50c36a0537"
integrity sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==
Expand Down Expand Up @@ -6449,6 +6459,23 @@ json-parse-even-better-errors@^2.3.0:
resolved "https://registry.yarnpkg.com/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz#7c47805a94319928e05777405dc12e1f7a4ee02d"
integrity sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==

json-schema-faker@^0.5.0-rcv.44:
version "0.5.0-rcv.44"
resolved "https://registry.yarnpkg.com/json-schema-faker/-/json-schema-faker-0.5.0-rcv.44.tgz#dca9b8f3a844c0426cf4c581cc8d7f4428f29f90"
integrity sha512-MbDxYFsPXTVMawW1Y6zEU7QhfwsT+ZJ2d+LI8n57Y8+Xw1Cdx1hITgsFTLNOJ1lDMHZqWeXGGgMbc1hW0BGisg==
dependencies:
json-schema-ref-parser "^6.1.0"
jsonpath-plus "^5.1.0"

json-schema-ref-parser@^6.1.0:
version "6.1.0"
resolved "https://registry.yarnpkg.com/json-schema-ref-parser/-/json-schema-ref-parser-6.1.0.tgz#30af34aeab5bee0431da805dac0eb21b574bf63d"
integrity sha512-pXe9H1m6IgIpXmE5JSb8epilNTGsmTb2iPohAXpOdhqGFbQjNeHHsZxU+C8w6T81GZxSPFLeUoqDJmzxx5IGuw==
dependencies:
call-me-maybe "^1.0.1"
js-yaml "^3.12.1"
ono "^4.0.11"

json-schema-traverse@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz#69f6a87d9513ab8bb8fe63bdb0979c448e684660"
Expand Down Expand Up @@ -6497,6 +6524,11 @@ jsonfile@^6.0.1:
optionalDependencies:
graceful-fs "^4.1.6"

jsonpath-plus@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/jsonpath-plus/-/jsonpath-plus-5.1.0.tgz#2fc4b2e461950626c98525425a3a3518b85af6c3"
integrity sha512-890w2Pjtj0iswAxalRlt2kHthi6HKrXEfZcn+ZNZptv7F3rUGIeDuZo+C+h4vXBHLEsVjJrHeCm35nYeZLzSBQ==

"jsx-ast-utils@^2.4.1 || ^3.0.0", jsx-ast-utils@^3.2.1, jsx-ast-utils@^3.2.2:
version "3.2.2"
resolved "https://registry.yarnpkg.com/jsx-ast-utils/-/jsx-ast-utils-3.2.2.tgz#6ab1e52c71dfc0c0707008a91729a9491fe9f76c"
Expand Down Expand Up @@ -7571,6 +7603,13 @@ only@~0.0.2:
resolved "https://registry.yarnpkg.com/only/-/only-0.0.2.tgz#2afde84d03e50b9a8edc444e30610a70295edfb4"
integrity sha1-Kv3oTQPlC5qO3EROMGEKcCle37Q=

ono@^4.0.11:
version "4.0.11"
resolved "https://registry.yarnpkg.com/ono/-/ono-4.0.11.tgz#c7f4209b3e396e8a44ef43b9cedc7f5d791d221d"
integrity sha512-jQ31cORBFE6td25deYeD80wxKBMj+zBmHTrVxnc6CKhx8gho6ipmWM5zj/oeoqioZ99yqBls9Z/9Nss7J26G2g==
dependencies:
format-util "^1.0.3"

optionator@^0.9.1:
version "0.9.1"
resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.9.1.tgz#4f236a6373dae0566a6d43e1326674f50c291499"
Expand Down

0 comments on commit e7907b6

Please sign in to comment.