├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── FUNDING.yml ├── issue_template.md └── workflows │ ├── release.yml │ └── testing.yml ├── .gitignore ├── .npmignore ├── CHANGELOG ├── CONTRIBUTORS ├── LICENSE ├── Makefile ├── README.md ├── bin └── gen.cjs ├── docs ├── DEPRECATED.md ├── README.md ├── TESTING.md └── USAGE.md ├── index.d.cts ├── index.d.ts ├── index.html ├── logo ├── JSF_logo.png ├── JSF_logo_BW.png ├── favicon │ ├── favicon.ico │ ├── favicon05.gif │ ├── favicon05.jpg │ ├── favicon05.png │ └── favicon05.psd ├── logo.svg ├── logo_alpha_300dpi.png ├── logo_alt_colors.png ├── other │ ├── save-button-small.png │ └── save-button.png └── typescript-logo.png ├── main.js ├── package.json ├── patch.js ├── public ├── CNAME ├── favicon.ico ├── v1 │ ├── bundle.css │ ├── bundle.js │ ├── favicon.ico │ ├── index.html │ ├── vendor.css │ └── vendor.js ├── v2 │ ├── css │ │ └── app.css │ ├── favicon.ico │ ├── img │ │ ├── favicon.ico │ │ └── logo.svg │ ├── index.html │ ├── js │ │ └── app.js │ └── vendor │ │ ├── ace-builds │ │ └── src-min │ │ │ ├── ace.js │ │ │ ├── mode-json.js │ │ │ ├── theme-github.js │ │ │ └── worker-json.js │ │ └── ractive │ │ └── ractive.runtime.min.js └── v3 │ ├── css │ └── app.css │ ├── img │ ├── favicon.ico │ └── logo.svg │ ├── index.html │ ├── js │ └── app.js │ └── vendor │ ├── Faker │ └── build │ │ └── build │ │ └── faker.js │ ├── ace-builds │ └── src-min │ │ ├── ace.js │ │ ├── mode-json.js │ │ ├── mode-yaml.js │ │ ├── theme-github.js │ │ └── worker-json.js │ ├── chance │ └── dist │ │ └── chance.min.js │ ├── vue │ └── dist │ │ └── vue.runtime.js │ └── yaml.js │ └── dist │ └── yaml.js ├── src ├── lib │ ├── api │ │ ├── defaults.mjs │ │ ├── format.mjs │ │ └── option.mjs │ ├── class │ │ ├── Container.mjs │ │ ├── OptionRegistry.mjs │ │ └── Registry.mjs │ ├── core │ │ ├── buildResolveSchema.mjs │ │ ├── constants.mjs │ │ ├── error.mjs │ │ ├── infer.mjs │ │ ├── random.mjs │ │ ├── run.mjs │ │ ├── traverse.mjs │ │ └── utils.mjs │ ├── generators │ │ ├── boolean.mjs │ │ ├── coreFormat.mjs │ │ ├── date.mjs │ │ ├── dateTime.mjs │ │ ├── ipv4.mjs │ │ ├── null.mjs │ │ ├── thunk.mjs │ │ ├── time.mjs │ │ └── words.mjs │ ├── index.mjs │ ├── main.mjs │ ├── renderers │ │ ├── index.mjs │ │ ├── js.mjs │ │ └── yaml.mjs │ ├── types │ │ ├── array.mjs │ │ ├── boolean.mjs │ │ ├── index.mjs │ │ ├── integer.mjs │ │ ├── null.mjs │ │ ├── number.mjs │ │ ├── object.mjs │ │ └── string.mjs │ └── vendor.mjs ├── main.cjs.js ├── main.iife.js ├── main.mjs ├── shared.js └── web │ ├── css │ ├── _base │ │ ├── components │ │ │ ├── Ace.less │ │ │ ├── Tabs.less │ │ │ └── Toolbar.less │ │ ├── elements.less │ │ ├── layout.less │ │ ├── reset.less │ │ └── vars.less │ └── app.css │ ├── img │ └── sprites │ │ ├── gear.svg │ │ ├── github.svg │ │ ├── logo.svg │ │ ├── logo_only.svg │ │ └── plus.svg │ ├── index.pug │ └── js │ ├── app.js │ └── lib │ ├── Ace.svelte │ ├── Auth.svelte │ ├── Editor.svelte │ ├── Gists.svelte │ ├── Icon.svelte │ ├── Modal.svelte │ ├── Opts.svelte │ ├── Save.svelte │ ├── Toggle.svelte │ ├── gists.js │ └── util.js └── tests ├── .eslintrc ├── e2e └── vite.test.mjs ├── external-ref-files └── issue-571-external-ref.json ├── integration ├── _deps_check.mjs ├── commonjs.test.mjs ├── esmodules.test.mjs └── umdwrapper.test.mjs ├── pending ├── issue-658.json ├── issue-740.json ├── issue-742.json ├── issue-749.json ├── issue-772.json ├── issue-775.json └── issue-783.json ├── schema ├── core │ ├── define │ │ └── autoIncrement.json │ ├── dependencies.json │ ├── extend │ │ ├── chance-extend.mjs │ │ ├── chance.json │ │ ├── faker-extend.mjs │ │ ├── faker.json │ │ └── mockjs-extend.mjs │ ├── formats.json │ ├── formats │ │ └── semver.mjs │ ├── issues │ │ ├── all-of-one-of-all-of-nested-overlap-with-additional-props.json │ │ ├── all-of-one-of-all-of-nested-overlap.json │ │ ├── all-of-one-of-all-of-nested.json │ │ ├── all-of-one-of-nested.json │ │ ├── allOf.json │ │ ├── anonymous.json │ │ ├── chance-and-faker.json │ │ ├── chance.json │ │ ├── cleanup.json │ │ ├── errors.json │ │ ├── format.json │ │ ├── inferred.json │ │ ├── issue-115.json │ │ ├── issue-158.json │ │ ├── issue-171.json │ │ ├── issue-193.json │ │ ├── issue-224.json │ │ ├── issue-238.json │ │ ├── issue-252.json │ │ ├── issue-258.json │ │ ├── issue-274.json │ │ ├── issue-304.json │ │ ├── issue-329.json │ │ ├── issue-331.json │ │ ├── issue-336.json │ │ ├── issue-345.json │ │ ├── issue-369.json │ │ ├── issue-379.json │ │ ├── issue-386.json │ │ ├── issue-400.json │ │ ├── issue-405.json │ │ ├── issue-416.json │ │ ├── issue-419.json │ │ ├── issue-425.json │ │ ├── issue-427.json │ │ ├── issue-442.json │ │ ├── issue-443.json │ │ ├── issue-444.json │ │ ├── issue-446.json │ │ ├── issue-453.json │ │ ├── issue-455.json │ │ ├── issue-456.json │ │ ├── issue-458.json │ │ ├── issue-467.json │ │ ├── issue-470.json │ │ ├── issue-486.json │ │ ├── issue-489.json │ │ ├── issue-494.json │ │ ├── issue-498.json │ │ ├── issue-502.json │ │ ├── issue-504.json │ │ ├── issue-506.json │ │ ├── issue-508.json │ │ ├── issue-509.json │ │ ├── issue-510.json │ │ ├── issue-514.json │ │ ├── issue-529.json │ │ ├── issue-530.json │ │ ├── issue-539.json │ │ ├── issue-540.json │ │ ├── issue-558.json │ │ ├── issue-559.json │ │ ├── issue-565.json │ │ ├── issue-567.json │ │ ├── issue-568.json │ │ ├── issue-569.json │ │ ├── issue-57.json │ │ ├── issue-571.json │ │ ├── issue-584.json │ │ ├── issue-585.json │ │ ├── issue-586.json │ │ ├── issue-587.json │ │ ├── issue-592.json │ │ ├── issue-595.json │ │ ├── issue-601.json │ │ ├── issue-603.json │ │ ├── issue-610.json │ │ ├── issue-620.json │ │ ├── issue-622.json │ │ ├── issue-624.json │ │ ├── issue-625.json │ │ ├── issue-635.json │ │ ├── issue-642.json │ │ ├── issue-644.json │ │ ├── issue-687.json │ │ ├── issue-690.json │ │ ├── issue-693.json │ │ ├── issue-713.json │ │ ├── issue-715.json │ │ ├── issue-747.json │ │ ├── issue-749.json │ │ ├── nested-refs.json │ │ ├── number-min-greater-than-max.json │ │ ├── number-min-max.json │ │ └── reserved.json │ ├── jsonpath.json │ ├── keywords.json │ ├── option │ │ ├── alwaysFakeOptionals.json │ │ ├── alwaysFakeOptionalsNoAdditional.json │ │ ├── defaultInvalidTypeProduct.json │ │ ├── failOnInvalidType.json │ │ ├── falsy-defaults.json │ │ ├── ignoreProperties.json │ │ ├── ignoreProperties.mjs │ │ ├── minMaxDateTime.json │ │ ├── optionalsProbability.json │ │ ├── pruneProperties.json │ │ ├── random.json │ │ ├── refDepth.json │ │ ├── useDefaultValue.json │ │ └── useExamplesValue.json │ ├── primitives.json │ ├── references.json │ ├── refs │ │ ├── allOf.json │ │ └── sync.json │ ├── typecast │ │ ├── chance │ │ │ ├── bool.json │ │ │ └── year.json │ │ └── faker │ │ │ ├── address-latitude-longitude.json │ │ │ └── finance-amount.json │ └── types │ │ ├── array.json │ │ ├── integer.json │ │ ├── not.json │ │ ├── object.json │ │ └── string.json ├── helpers.mjs ├── main.spec.mjs └── validator.mjs └── unit ├── core ├── buildResolveSchema.test.mjs ├── infer.spec.mjs ├── randomGeneration.spec.mjs ├── traverse.spec.mjs └── utils.spec.mjs ├── generators ├── boolean.spec.mjs ├── ipv4.spec.mjs ├── null.spec.mjs └── number.spec.mjs └── renderers └── yaml.spec.mjs /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | [*.md] 7 | trim_trailing_whitespace = false 8 | 9 | [*.js] 10 | trim_trailing_whitespace = true 11 | 12 | # Unix-style newlines with a newline ending every file 13 | [*] 14 | indent_style = space 15 | indent_size = 2 16 | end_of_line = lf 17 | charset = utf-8 18 | insert_final_newline = true 19 | 20 | [{Makefile,todo}] 21 | indent_style = tab 22 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | src/web 2 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "browser": true 5 | }, 6 | "extends": "airbnb-base", 7 | "plugins": [ 8 | "svelte3" 9 | ], 10 | "overrides": [ 11 | { 12 | "files": ["*.svelte"], 13 | "processor": "svelte3/svelte3" 14 | } 15 | ], 16 | "parserOptions": { 17 | "ecmaVersion": 2021, 18 | "sourceType": "module" 19 | }, 20 | "rules" : { 21 | "max-len": ["error", { 22 | "code": 150 23 | }], 24 | "arrow-parens": ["error", "as-needed"], 25 | "indent": 0, 26 | "strict": 0, 27 | "prefer-const": 0, 28 | "no-console": 0, 29 | "no-labels": 0, 30 | "no-unused-labels": 0, 31 | "no-restricted-syntax": 0, 32 | "no-multi-assign": 0, 33 | "prefer-destructuring": 0, 34 | "function-paren-newline": 0, 35 | "global-require": 0, 36 | "prefer-spread": 0, 37 | "prefer-rest-params": 0, 38 | "prefer-arrow-callback": 0, 39 | "arrow-body-style": 0, 40 | "object-curly-newline": 0, 41 | "no-restricted-globals": 0, 42 | "consistent-return": 0, 43 | "no-param-reassign": 0, 44 | "no-underscore-dangle": 0, 45 | "no-multiple-empty-lines": 0, 46 | "import/first": 0, 47 | "import/extensions": 0, 48 | "import/no-unresolved": 0, 49 | "import/no-dynamic-require": 0, 50 | "import/no-mutable-exports": 0, 51 | "import/no-extraneous-dependencies": 0, 52 | "import/prefer-default-export": 0 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | lib/** -diff 2 | dist/** -diff binary 3 | locale/* -diff 4 | package-lock.json -diff 5 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | We welcome contributions to the project! :beer: 2 | 3 | ## Bug submission 4 | 5 | If you are submitting a bug report, please include the following: 6 | 7 | 1. the JSON Schema content that fails: go to [the demo page](http://json-schema-faker.js.org/), paste the schema into the textarea on the left, click `Generate example`, and then copy the resulting URL from the browser address bar and paste it here. This will make it easier for us to reproduce and fix the bug. Thank you in advance! :beer: Otherwise please paste the schema inline in your bug report. 8 | 2. the result you got 9 | 3. the result you expected 10 | 11 | ## Issues & Pull-requests 12 | 13 | * When submitting *bug reports*, *paste your schema example* whenever possible. This will save us from having to ask you for it later. 14 | * When submitting *Pull Requests (PRs)*, you should request to merge your changes into our `develop` branch. 15 | * Our approach to testing is described in [docs/TESTING.md](/docs/TESTING.md). 16 | * PRs without specs will not be merged anytime soon! 17 | 18 | ## Releasing new versions 19 | 20 | * Create a new entry in the [CHANGELOG](/CHANGELOG) file, 21 | * Re-build and re-release the online demo, see [`json-schema-faker` gh-pages branch](https://github.com/json-schema-faker/json-schema-faker/tree/gh-pages). 22 | 23 | ## Development tasks 24 | 25 | * `npm run dev` — Run the tests and watch (preferred during development) 26 | * `npm run lint` — Run eslint on all sources 27 | * `npm run test:unit` — Run unit tests 28 | * `npm run test:schema` — Run schema tests 29 | * `npm run cover` — Run istanbul + jasmine-node 30 | * `npm run cover:up` — Upload to coveralls (CI only) 31 | * `npm run dist` — Prepare all assets with locales for CDN support 32 | * `npm test` — Run all the tests 33 | 34 | ### Upcoming 35 | 36 | * `npm run tsc` — Compile TypeScript to JavaScript (via commonJS) 37 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8MXLRJ7QQXGYY&source=url 2 | open_collective: json-schema-faker 3 | github: pateketrueke 4 | ko-fi: pateketrueke 5 | -------------------------------------------------------------------------------- /.github/issue_template.md: -------------------------------------------------------------------------------- 1 | If you are reporting a bug, please include the following: 2 | 3 | 1. the JSON Schema content that fails - preferably using http://json-schema-faker.js.org/ (paste the schema, click `Generate example` and then copy and paste the resulting URL from the browser address bar) 4 | 2. the result you got 5 | 3. the result you expected 6 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | Release: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@v2 13 | with: 14 | persist-credentials: false 15 | fetch-depth: 0 16 | - name: Create version 17 | run: | 18 | git config user.name github-actions 19 | git config user.email github-actions@github.com 20 | 21 | make publish release 22 | env: 23 | USE_RELEASE_VERSION: ${{ secrets.RELEASE_VERSION }} 24 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} 25 | - name: Push changes 26 | uses: ad-m/github-push-action@master 27 | with: 28 | github_token: ${{ secrets.GITHUB_TOKEN }} 29 | branch: ${{ github.ref }} 30 | tags: true 31 | - name: Publish version 32 | run: npm publish 33 | - name: Update website 34 | run: make clean web deploy 35 | -------------------------------------------------------------------------------- /.github/workflows/testing.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - develop 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | test: 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: actions/checkout@v2 16 | - run: | 17 | make ci CODECOV_TOKEN=${{ secrets.CODECOV_TOKEN }} 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | 3 | # IDEs 4 | .idea 5 | .vscode 6 | cache.json 7 | 8 | *~ 9 | *.log 10 | *.tgz 11 | *.todo 12 | .nyc_output 13 | .DS_Store 14 | dist 15 | build 16 | coverage 17 | generated 18 | node_modules 19 | package-lock.json 20 | 21 | ### Vim ### 22 | # swap 23 | [._]*.s[a-v][a-z] 24 | [._]*.sw[a-p] 25 | [._]s[a-v][a-z] 26 | [._]sw[a-p] 27 | # session 28 | Session.vim 29 | # temporary 30 | .netrwhist 31 | *~ 32 | # auto-generated tag files 33 | tags 34 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .* 2 | *~ 3 | *.log 4 | *.tgz 5 | *.json 6 | .DS_Store 7 | build-dist.js 8 | bower.json 9 | tslint.json 10 | /ts 11 | /docs 12 | /spec 13 | /build 14 | /package 15 | /reports 16 | /coverage 17 | /generated 18 | /node_modules 19 | /logo 20 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | 652 Alvaro Cabrera 2 | 165 Tomasz Ducin 3 | 4 Nathan Broadbent 4 | 4 Jonathan Montane 5 | 4 Jeremy Whitlock 6 | 2 DrHinke <0xBADBAC0N@users.noreply.github.com> 7 | 2 Greg Venech 8 | 2 Peter Dave Hello 9 | 2 Peter Waldschmidt 10 | 2 Arjan van der Leden 11 | 1 Pavan Kumar Sunkara 12 | 1 Raynos 13 | 1 omerts 14 | 1 Alex Lockwood 15 | 1 oprogramador 16 | 1 Andre Steenveld 17 | 1 Bitdeli Chef 18 | 1 Bobby Brennan 19 | 1 C. Corey Capel 20 | 1 Clément VILLAIN 21 | 1 Everett Griffiths 22 | 1 Felipe Cardona 23 | 1 Javier Cejudo 24 | 1 Jeremy Pridemore 25 | 1 Jonathan Montane 26 | 1 Kyle Fuller 27 | 1 Manuel de la Torre 28 | 1 Micha Moskovic 29 | 1 Máté Farkas 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-2021 Alvaro Cabrera 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # current working directory 2 | PWD=$(shell pwd) 3 | 4 | # defaults 5 | src := dist 6 | target := gh-pages 7 | message := Release: $(shell date) 8 | 9 | # environment vars 10 | PORT ?= 8080 11 | NODE_ENV ?= development 12 | VERSION ?= $(shell cat package.json | jq .version | xargs) 13 | 14 | ifneq ($(wildcard .env),) 15 | include .env 16 | endif 17 | 18 | # export vars 19 | .EXPORT_ALL_VARIABLES: 20 | 21 | # targets 22 | .PHONY: ? deps purge web clean deploy 23 | 24 | # utils 25 | define iif 26 | @(($(1) > /dev/null 2>&1) && printf "\r* $(2)\n") || printf "\r* $(3)\n" 27 | endef 28 | 29 | # display all targets-with-help in this file 30 | ?: Makefile 31 | @awk -F':.*?##' '/^[a-z\\%!:-]+:.*##/{gsub("%","*",$$1);gsub("\\\\",":*",$$1);printf "\033[36m%8s\033[0m %s\n",$$1,$$2}' $< 32 | 33 | ci: clean deps 34 | @npm test 35 | @npm run test:e2e 36 | @npm run test:integration 37 | ifneq ($(CI),) 38 | @npm run codecov 39 | endif 40 | 41 | lib: deps ## Build library output only 42 | @npm run build -- -fymain -yshared 43 | 44 | dev: deps ## Watch and start development server 45 | @npm run watch 46 | 47 | test: deps ## Run tests like if we're in CI ;-) 48 | @npm run test:schema 49 | 50 | build: deps ## Build scripts for dist 51 | @npm run build 52 | 53 | watch: deps ## Build scripts for dist 54 | @npm run build -- -xweb --watch 55 | 56 | web: deps ## Build artifact for production envs 57 | @(git worktree remove $(src) --force > /dev/null 2>&1) || true 58 | @git worktree add $(src) $(target) 59 | @cd $(src) && rm -rf * 60 | @cp -r public/* $(src) 61 | @npm run build 62 | 63 | clean: ## Remove cache and generated artifacts 64 | @$(call iif,rm -r $(src),Built artifacts were deleted,Artifacts already deleted) 65 | @$(call iif,unlink cache.json,Cache file was deleted,Cache file already deleted) 66 | 67 | deploy: ## Push built artifacts to github! 68 | @cd $(src) && rm -rf js/lib lib 69 | @cd $(src) && git add . && git commit -m "$(message)" 70 | @git push origin $(target) -f 71 | 72 | deps: ## Check for installed dependencies 73 | @(((ls node_modules | grep .) > /dev/null 2>&1) || npm i) || true 74 | 75 | prune: clean ## Remove all from node_modules/* 76 | @printf "\r* Removing all dependencies... " 77 | @rm -rf node_modules/.{bin,cache} 78 | @rm -rf node_modules/* 79 | @echo "OK" 80 | 81 | publish: clean 82 | @make -s lib 83 | 84 | release: 85 | ifneq ($(CI),) 86 | @echo '//registry.npmjs.org/:_authToken=$(NODE_AUTH_TOKEN)' > .npmrc 87 | @npm version $(USE_RELEASE_VERSION) 88 | endif 89 | -------------------------------------------------------------------------------- /docs/DEPRECATED.md: -------------------------------------------------------------------------------- 1 | # Deprecation Notice 2 | 3 | ## Importing 4 | 5 | ### Don't use the default export 6 | 7 | CommonJS: 8 | 9 | ```js 10 | const JSONSchemaFaker = require("json-schema-faker"); 11 | ``` 12 | 13 | ESM: 14 | 15 | ```js 16 | import JSONSchemaFaker from "json-schema-faker"; 17 | ``` 18 | 19 | ### Do use the named export 20 | 21 | CommonJS: 22 | 23 | ```js 24 | const { JSONSchemaFaker } = require("json-schema-faker"); 25 | ``` 26 | 27 | ESM: 28 | 29 | ```js 30 | import { JSONSchemaFaker } from "json-schema-faker"; 31 | ``` 32 | 33 | ## API 34 | 35 | ### Don't call `JSONSchemaFaker` as a function 36 | 37 | This API is deprecated. 38 | 39 | ```js 40 | const data = JSONSchemaFaker(schema, refs, cwd); 41 | ``` 42 | 43 | ### Do call `.generate()` 44 | 45 | This code is equivalent to the previous snippet. 46 | 47 | ```js 48 | const data = JSONSchemaFaker.generate(schema, refs, cwd); 49 | ``` 50 | 51 | ### Do call `.resolve()` 52 | 53 | If possible, use `async` / `await` and `.resolve()` to generate data without blocking the thread. 54 | 55 | ```js 56 | const data = await JSONSchemaFaker.resolve(schema, refs, cwd); 57 | ``` 58 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Vite App 7 | 8 | 9 |
10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /logo/JSF_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/JSF_logo.png -------------------------------------------------------------------------------- /logo/JSF_logo_BW.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/JSF_logo_BW.png -------------------------------------------------------------------------------- /logo/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/favicon/favicon.ico -------------------------------------------------------------------------------- /logo/favicon/favicon05.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/favicon/favicon05.gif -------------------------------------------------------------------------------- /logo/favicon/favicon05.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/favicon/favicon05.jpg -------------------------------------------------------------------------------- /logo/favicon/favicon05.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/favicon/favicon05.png -------------------------------------------------------------------------------- /logo/favicon/favicon05.psd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/favicon/favicon05.psd -------------------------------------------------------------------------------- /logo/logo_alpha_300dpi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/logo_alpha_300dpi.png -------------------------------------------------------------------------------- /logo/logo_alt_colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/logo_alt_colors.png -------------------------------------------------------------------------------- /logo/other/save-button-small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/other/save-button-small.png -------------------------------------------------------------------------------- /logo/other/save-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/other/save-button.png -------------------------------------------------------------------------------- /logo/typescript-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/logo/typescript-logo.png -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | import { JSONSchemaFaker } from './dist/main.mjs'; 2 | 3 | document.querySelector('#app').innerHTML = ` 4 | const: ${JSONSchemaFaker.generate({ const: 42 })} 5 | `; 6 | -------------------------------------------------------------------------------- /patch.js: -------------------------------------------------------------------------------- 1 | import { writeFileSync, readFileSync } from 'fs'; 2 | 3 | let cjs = readFileSync('dist/main.cjs').toString(); 4 | cjs = cjs.replace(/module\.exports = Object\.assign/, '// $&'); 5 | 6 | writeFileSync('dist/main.cjs', cjs); 7 | writeFileSync('dist/index.cjs', 'module.exports = require("./main.cjs").default;\n'); 8 | 9 | // prefix was setting `location` and that caused redirections under browser-like environments 10 | // if you run this module on a browser-like environment that does not have `location` set it'll fail 11 | 12 | let vendor = readFileSync('dist/vendor.js').toString(); 13 | vendor = `!(()=>{${vendor}})()`; 14 | 15 | writeFileSync('dist/vendor.js', vendor); 16 | -------------------------------------------------------------------------------- /public/CNAME: -------------------------------------------------------------------------------- 1 | json-schema-faker.js.org 2 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/public/favicon.ico -------------------------------------------------------------------------------- /public/v1/bundle.css: -------------------------------------------------------------------------------- 1 | .spinner{display:inline-block;opacity:0;width:0;-webkit-transition:opacity .25s,width .25s;-moz-transition:opacity .25s,width .25s;-o-transition:opacity .25s,width .25s;transition:opacity .25s,width .25s}.has-spinner.active{cursor:progress}.has-spinner.active .spinner{opacity:1;width:auto}.has-spinner.btn-mini.active .spinner{width:10px}.has-spinner.btn-small.active .spinner{width:13px}.has-spinner.btn.active .spinner{width:16px}.has-spinner.btn-large.active .spinner{width:19px}body{padding-top:70px}.github-ribbon img{position:absolute;top:0;right:0;border:0;padding-top:50px}.row-centered{text-align:center}#input,#output{height:280px}.panel-body{padding:0}#message-box .alert{width:50%}.github-star{margin-top:12px} -------------------------------------------------------------------------------- /public/v1/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/public/v1/favicon.ico -------------------------------------------------------------------------------- /public/v2/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/public/v2/favicon.ico -------------------------------------------------------------------------------- /public/v2/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/public/v2/img/favicon.ico -------------------------------------------------------------------------------- /public/v2/vendor/ace-builds/src-min/theme-github.js: -------------------------------------------------------------------------------- 1 | define("ace/theme/github",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-github",t.cssText='.ace-github .ace_gutter {background: #e8e8e8;color: #AAA;}.ace-github {background: #fff;color: #000;}.ace-github .ace_keyword {font-weight: bold;}.ace-github .ace_string {color: #D14;}.ace-github .ace_variable.ace_class {color: teal;}.ace-github .ace_constant.ace_numeric {color: #099;}.ace-github .ace_constant.ace_buildin {color: #0086B3;}.ace-github .ace_support.ace_function {color: #0086B3;}.ace-github .ace_comment {color: #998;font-style: italic;}.ace-github .ace_variable.ace_language {color: #0086B3;}.ace-github .ace_paren {font-weight: bold;}.ace-github .ace_boolean {font-weight: bold;}.ace-github .ace_string.ace_regexp {color: #009926;font-weight: normal;}.ace-github .ace_variable.ace_instance {color: teal;}.ace-github .ace_constant.ace_language {font-weight: bold;}.ace-github .ace_cursor {color: black;}.ace-github.ace_focus .ace_marker-layer .ace_active-line {background: rgb(255, 255, 204);}.ace-github .ace_marker-layer .ace_active-line {background: rgb(245, 245, 245);}.ace-github .ace_marker-layer .ace_selection {background: rgb(181, 213, 255);}.ace-github.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px white;}.ace-github.ace_nobold .ace_line > span {font-weight: normal !important;}.ace-github .ace_marker-layer .ace_step {background: rgb(252, 255, 0);}.ace-github .ace_marker-layer .ace_stack {background: rgb(164, 229, 101);}.ace-github .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgb(192, 192, 192);}.ace-github .ace_gutter-active-line {background-color : rgba(0, 0, 0, 0.07);}.ace-github .ace_marker-layer .ace_selected-word {background: rgb(250, 250, 255);border: 1px solid rgb(200, 200, 250);}.ace-github .ace_invisible {color: #BFBFBF}.ace-github .ace_print-margin {width: 1px;background: #e8e8e8;}.ace-github .ace_indent-guide {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y;}';var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)}) -------------------------------------------------------------------------------- /public/v3/img/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/json-schema-faker/json-schema-faker/89a97aa89915ecfff4f4ca06a4e2909861871f0c/public/v3/img/favicon.ico -------------------------------------------------------------------------------- /public/v3/vendor/ace-builds/src-min/theme-github.js: -------------------------------------------------------------------------------- 1 | define("ace/theme/github",["require","exports","module","ace/lib/dom"],function(e,t,n){t.isDark=!1,t.cssClass="ace-github",t.cssText='.ace-github .ace_gutter {background: #e8e8e8;color: #AAA;}.ace-github {background: #fff;color: #000;}.ace-github .ace_keyword {font-weight: bold;}.ace-github .ace_string {color: #D14;}.ace-github .ace_variable.ace_class {color: teal;}.ace-github .ace_constant.ace_numeric {color: #099;}.ace-github .ace_constant.ace_buildin {color: #0086B3;}.ace-github .ace_support.ace_function {color: #0086B3;}.ace-github .ace_comment {color: #998;font-style: italic;}.ace-github .ace_variable.ace_language {color: #0086B3;}.ace-github .ace_paren {font-weight: bold;}.ace-github .ace_boolean {font-weight: bold;}.ace-github .ace_string.ace_regexp {color: #009926;font-weight: normal;}.ace-github .ace_variable.ace_instance {color: teal;}.ace-github .ace_constant.ace_language {font-weight: bold;}.ace-github .ace_cursor {color: black;}.ace-github.ace_focus .ace_marker-layer .ace_active-line {background: rgb(255, 255, 204);}.ace-github .ace_marker-layer .ace_active-line {background: rgb(245, 245, 245);}.ace-github .ace_marker-layer .ace_selection {background: rgb(181, 213, 255);}.ace-github.ace_multiselect .ace_selection.ace_start {box-shadow: 0 0 3px 0px white;}.ace-github.ace_nobold .ace_line > span {font-weight: normal !important;}.ace-github .ace_marker-layer .ace_step {background: rgb(252, 255, 0);}.ace-github .ace_marker-layer .ace_stack {background: rgb(164, 229, 101);}.ace-github .ace_marker-layer .ace_bracket {margin: -1px 0 0 -1px;border: 1px solid rgb(192, 192, 192);}.ace-github .ace_gutter-active-line {background-color : rgba(0, 0, 0, 0.07);}.ace-github .ace_marker-layer .ace_selected-word {background: rgb(250, 250, 255);border: 1px solid rgb(200, 200, 250);}.ace-github .ace_invisible {color: #BFBFBF}.ace-github .ace_print-margin {width: 1px;background: #e8e8e8;}.ace-github .ace_indent-guide {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAACCAYAAACZgbYnAAAAE0lEQVQImWP4////f4bLly//BwAmVgd1/w11/gAAAABJRU5ErkJggg==") right repeat-y;}';var r=e("../lib/dom");r.importCssString(t.cssText,t.cssClass)}); (function() { 2 | window.require(["ace/theme/github"], function(m) { 3 | if (typeof module == "object" && typeof exports == "object" && module) { 4 | module.exports = m; 5 | } 6 | }); 7 | })(); 8 | -------------------------------------------------------------------------------- /src/lib/api/defaults.mjs: -------------------------------------------------------------------------------- 1 | const defaults = {}; 2 | 3 | export default defaults; 4 | 5 | defaults.defaultInvalidTypeProduct = undefined; 6 | defaults.defaultRandExpMax = 10; 7 | defaults.maxRegexRetry = 100; 8 | 9 | defaults.pruneProperties = []; 10 | defaults.ignoreProperties = []; 11 | defaults.ignoreMissingRefs = false; 12 | defaults.failOnInvalidTypes = true; 13 | defaults.failOnInvalidFormat = true; 14 | 15 | defaults.alwaysFakeOptionals = false; 16 | defaults.optionalsProbability = null; 17 | defaults.fixedProbabilities = false; 18 | defaults.useExamplesValue = false; 19 | defaults.useDefaultValue = false; 20 | defaults.requiredOnly = false; 21 | defaults.omitNulls = false; 22 | 23 | defaults.minItems = 0; 24 | defaults.maxItems = null; 25 | defaults.minLength = 0; 26 | defaults.maxLength = null; 27 | 28 | defaults.resolveJsonPath = false; 29 | defaults.reuseProperties = false; 30 | defaults.fillProperties = true; 31 | defaults.sortProperties = false; 32 | defaults.replaceEmptyByRandomValue = false; 33 | 34 | defaults.random = Math.random; 35 | defaults.minDateTime = new Date('1889-12-31T00:00:00.000Z'); 36 | defaults.maxDateTime = new Date('1970-01-01T00:00:01.000Z'); 37 | 38 | defaults.renderTitle = true; 39 | defaults.renderDescription = true; 40 | defaults.renderComment = false; 41 | -------------------------------------------------------------------------------- /src/lib/api/format.mjs: -------------------------------------------------------------------------------- 1 | import Registry from '../class/Registry.mjs'; 2 | 3 | // instantiate 4 | const registry = new Registry(); 5 | 6 | /** 7 | * Custom format API 8 | * 9 | * @see https://github.com/json-schema-faker/json-schema-faker#custom-formats 10 | * @param nameOrFormatMap 11 | * @param callback 12 | * @returns {any} 13 | */ 14 | function formatAPI(nameOrFormatMap, callback) { 15 | if (typeof nameOrFormatMap === 'undefined') { 16 | return registry.list(); 17 | } 18 | 19 | if (typeof nameOrFormatMap === 'string') { 20 | if (typeof callback === 'function') { 21 | registry.register(nameOrFormatMap, callback); 22 | } else if (callback === null || callback === false) { 23 | registry.unregister(nameOrFormatMap); 24 | } else { 25 | return registry.get(nameOrFormatMap); 26 | } 27 | } else { 28 | registry.registerMany(nameOrFormatMap); 29 | } 30 | } 31 | 32 | export default formatAPI; 33 | -------------------------------------------------------------------------------- /src/lib/api/option.mjs: -------------------------------------------------------------------------------- 1 | import OptionRegistry from '../class/OptionRegistry.mjs'; 2 | 3 | // instantiate 4 | const registry = new OptionRegistry(); 5 | 6 | /** 7 | * Custom option API 8 | * 9 | * @param nameOrOptionMap 10 | * @returns {any} 11 | */ 12 | function optionAPI(nameOrOptionMap, optionalValue) { 13 | if (typeof nameOrOptionMap === 'string') { 14 | if (typeof optionalValue !== 'undefined') { 15 | return registry.register(nameOrOptionMap, optionalValue); 16 | } 17 | 18 | return registry.get(nameOrOptionMap); 19 | } 20 | 21 | return registry.registerMany(nameOrOptionMap); 22 | } 23 | 24 | optionAPI.getDefaults = () => registry.defaults; 25 | 26 | export default optionAPI; 27 | -------------------------------------------------------------------------------- /src/lib/class/OptionRegistry.mjs: -------------------------------------------------------------------------------- 1 | import Registry from './Registry.mjs'; 2 | import defaults from '../api/defaults.mjs'; 3 | 4 | /** 5 | * This class defines a registry for custom settings used within JSF. 6 | */ 7 | class OptionRegistry extends Registry { 8 | constructor() { 9 | super(); 10 | this.data = { ...defaults }; 11 | this._defaults = defaults; 12 | } 13 | 14 | get defaults() { 15 | return { ...this._defaults }; 16 | } 17 | } 18 | 19 | export default OptionRegistry; 20 | -------------------------------------------------------------------------------- /src/lib/class/Registry.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * This class defines a registry for custom formats used within JSF. 3 | */ 4 | class Registry { 5 | constructor() { 6 | // empty by default 7 | this.data = {}; 8 | } 9 | 10 | /** 11 | * Unregisters custom format(s) 12 | * @param name 13 | */ 14 | unregister(name) { 15 | if (!name) { 16 | this.data = {}; 17 | } else { 18 | delete this.data[name]; 19 | } 20 | } 21 | 22 | /** 23 | * Registers custom format 24 | */ 25 | register(name, callback) { 26 | this.data[name] = callback; 27 | } 28 | 29 | /** 30 | * Register many formats at one shot 31 | */ 32 | registerMany(formats) { 33 | Object.keys(formats).forEach(name => { 34 | this.data[name] = formats[name]; 35 | }); 36 | } 37 | 38 | /** 39 | * Returns element by registry key 40 | */ 41 | get(name) { 42 | const format = this.data[name]; 43 | 44 | return format; 45 | } 46 | 47 | /** 48 | * Returns the whole registry content 49 | */ 50 | list() { 51 | return this.data; 52 | } 53 | } 54 | 55 | export default Registry; 56 | -------------------------------------------------------------------------------- /src/lib/core/constants.mjs: -------------------------------------------------------------------------------- 1 | const ALLOWED_TYPES = ['integer', 'number', 'string', 'boolean']; 2 | const SCALAR_TYPES = ALLOWED_TYPES.concat(['null']); 3 | const ALL_TYPES = ['array', 'object'].concat(SCALAR_TYPES); 4 | 5 | const MOST_NEAR_DATETIME = 2524608000000; 6 | 7 | const MIN_INTEGER = -100000000; 8 | const MAX_INTEGER = 100000000; 9 | 10 | const MIN_NUMBER = -100; 11 | const MAX_NUMBER = 100; 12 | 13 | export default { 14 | ALLOWED_TYPES, 15 | SCALAR_TYPES, 16 | ALL_TYPES, 17 | MIN_NUMBER, 18 | MAX_NUMBER, 19 | MIN_INTEGER, 20 | MAX_INTEGER, 21 | MOST_NEAR_DATETIME, 22 | }; 23 | -------------------------------------------------------------------------------- /src/lib/core/error.mjs: -------------------------------------------------------------------------------- 1 | class ParseError extends Error { 2 | constructor(message, path) { 3 | super(); 4 | if (Error.captureStackTrace) { 5 | Error.captureStackTrace(this, this.constructor); 6 | } 7 | this.name = 'ParseError'; 8 | this.message = message; 9 | this.path = path; 10 | } 11 | } 12 | 13 | export default ParseError; 14 | -------------------------------------------------------------------------------- /src/lib/generators/boolean.mjs: -------------------------------------------------------------------------------- 1 | import optionAPI from '../api/option.mjs'; 2 | 3 | /** 4 | * Generates randomized boolean value. 5 | * 6 | * @returns {boolean} 7 | */ 8 | function booleanGenerator() { 9 | return optionAPI('random')() > 0.5; 10 | } 11 | 12 | export default booleanGenerator; 13 | -------------------------------------------------------------------------------- /src/lib/generators/coreFormat.mjs: -------------------------------------------------------------------------------- 1 | import random from '../core/random.mjs'; 2 | 3 | const FRAGMENT = '[a-zA-Z][a-zA-Z0-9+-.]*'; 4 | const URI_PATTERN = `https?://{hostname}(?:${FRAGMENT})+`; 5 | const PARAM_PATTERN = '(?:\\?([a-z]{1,7}(=\\w{1,5})?&){0,3})?'; 6 | 7 | /** 8 | * Predefined core formats 9 | * @type {[key: string]: string} 10 | */ 11 | const regexps = { 12 | email: '[a-zA-Z\\d][a-zA-Z\\d-]{1,13}[a-zA-Z\\d]@{hostname}', 13 | hostname: '[a-zA-Z]{1,33}\\.[a-z]{2,4}', 14 | ipv6: '[a-f\\d]{4}(:[a-f\\d]{4}){7}', 15 | uri: URI_PATTERN, 16 | slug: '[a-zA-Z\\d_-]+', 17 | 18 | // types from draft-0[67] (?) 19 | 'uri-reference': `${URI_PATTERN}${PARAM_PATTERN}`, 20 | 'uri-template': URI_PATTERN.replace('(?:', '(?:/\\{[a-z][:a-zA-Z0-9-]*\\}|'), 21 | 'json-pointer': `(/(?:${FRAGMENT.replace(']*', '/]*')}|~[01]))+`, 22 | 23 | // some types from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types (?) 24 | uuid: '^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$', 25 | 26 | duration: '^P(?!$)((\\d+Y)?(\\d+M)?(\\d+D)?(T(?=\\d)(\\d+H)?(\\d+M)?(\\d+S)?)?|(\\d+W)?)$', 27 | }; 28 | 29 | regexps.iri = regexps['uri-reference']; 30 | regexps['iri-reference'] = regexps['uri-reference']; 31 | 32 | regexps['idn-email'] = regexps.email; 33 | regexps['idn-hostname'] = regexps.hostname; 34 | 35 | const ALLOWED_FORMATS = new RegExp(`\\{(${Object.keys(regexps).join('|')})\\}`); 36 | 37 | /** 38 | * Generates randomized string basing on a built-in regex format 39 | * 40 | * @param coreFormat 41 | * @returns {string} 42 | */ 43 | function coreFormatGenerator(coreFormat) { 44 | return random.randexp(regexps[coreFormat]).replace(ALLOWED_FORMATS, (match, key) => { 45 | return random.randexp(regexps[key]); 46 | }); 47 | } 48 | 49 | export default coreFormatGenerator; 50 | -------------------------------------------------------------------------------- /src/lib/generators/date.mjs: -------------------------------------------------------------------------------- 1 | import dateTimeGenerator from './dateTime.mjs'; 2 | 3 | /** 4 | * Generates randomized date format string. 5 | * 6 | * @returns {string} 7 | */ 8 | function dateGenerator() { 9 | return dateTimeGenerator().slice(0, 10); 10 | } 11 | 12 | export default dateGenerator; 13 | -------------------------------------------------------------------------------- /src/lib/generators/dateTime.mjs: -------------------------------------------------------------------------------- 1 | import random from '../core/random.mjs'; 2 | 3 | /** 4 | * Generates randomized date time ISO format string. 5 | * 6 | * @returns {string} 7 | */ 8 | function dateTimeGenerator() { 9 | return random.date().toISOString(); 10 | } 11 | 12 | export default dateTimeGenerator; 13 | -------------------------------------------------------------------------------- /src/lib/generators/ipv4.mjs: -------------------------------------------------------------------------------- 1 | import random from '../core/random.mjs'; 2 | 3 | /** 4 | * Generates randomized ipv4 address. 5 | * 6 | * @returns {string} 7 | */ 8 | function ipv4Generator() { 9 | return [0, 0, 0, 0].map(() => { 10 | return random.number(0, 255); 11 | }).join('.'); 12 | } 13 | 14 | export default ipv4Generator; 15 | -------------------------------------------------------------------------------- /src/lib/generators/null.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Generates null value. 3 | * 4 | * @returns {null} 5 | */ 6 | function nullGenerator() { 7 | return null; 8 | } 9 | 10 | export default nullGenerator; 11 | -------------------------------------------------------------------------------- /src/lib/generators/thunk.mjs: -------------------------------------------------------------------------------- 1 | import words from './words.mjs'; 2 | import random from '../core/random.mjs'; 3 | 4 | /** 5 | * Helper function used by thunkGenerator to produce some words for the final result. 6 | * 7 | * @returns {string} 8 | */ 9 | function produce() { 10 | const length = random.number(1, 5); 11 | 12 | return words(length).join(' '); 13 | } 14 | 15 | /** 16 | * Generates randomized concatenated string based on words generator. 17 | * 18 | * @returns {string} 19 | */ 20 | function thunkGenerator(min = 0, max = 140) { 21 | const _min = Math.max(0, min); 22 | const _max = random.number(_min, max); 23 | 24 | let result = produce(); 25 | 26 | // append until length is reached 27 | while (result.length < _min) { 28 | result += produce(); 29 | } 30 | 31 | // cut if needed 32 | if (result.length > _max) { 33 | result = result.substr(0, _max); 34 | } 35 | 36 | return result; 37 | } 38 | 39 | export default thunkGenerator; 40 | -------------------------------------------------------------------------------- /src/lib/generators/time.mjs: -------------------------------------------------------------------------------- 1 | import dateTimeGenerator from './dateTime.mjs'; 2 | 3 | /** 4 | * Generates randomized time format string. 5 | * 6 | * @returns {string} 7 | */ 8 | function timeGenerator() { 9 | return dateTimeGenerator().slice(11); 10 | } 11 | 12 | export default timeGenerator; 13 | -------------------------------------------------------------------------------- /src/lib/generators/words.mjs: -------------------------------------------------------------------------------- 1 | import random from '../core/random.mjs'; 2 | 3 | const LIPSUM_WORDS = `Lorem ipsum dolor sit amet consectetur adipisicing elit sed do eiusmod tempor incididunt ut labore 4 | et dolore magna aliqua Ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea 5 | commodo consequat Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 6 | pariatur Excepteur sint occaecat cupidatat non proident sunt in culpa qui officia deserunt mollit anim id est 7 | laborum`.split(/\W/); 8 | 9 | /** 10 | * Generates randomized array of single lorem ipsum words. 11 | * 12 | * @param length 13 | * @returns {Array.} 14 | */ 15 | function wordsGenerator(length) { 16 | const words = random.shuffle(LIPSUM_WORDS); 17 | 18 | return words.slice(0, length); 19 | } 20 | 21 | export default wordsGenerator; 22 | -------------------------------------------------------------------------------- /src/lib/main.mjs: -------------------------------------------------------------------------------- 1 | import $RefParser from 'json-schema-ref-parser'; 2 | import { JSONPath } from 'jsonpath-plus'; 3 | 4 | import { setDependencies } from './vendor.mjs'; 5 | 6 | setDependencies({ $RefParser, JSONPath }); 7 | 8 | export { default, JSONSchemaFaker } from './index.mjs'; 9 | -------------------------------------------------------------------------------- /src/lib/renderers/index.mjs: -------------------------------------------------------------------------------- 1 | import renderJS from './js.mjs'; 2 | import renderYAML from './yaml.mjs'; 3 | 4 | export { 5 | renderJS, 6 | renderYAML, 7 | }; 8 | -------------------------------------------------------------------------------- /src/lib/renderers/js.mjs: -------------------------------------------------------------------------------- 1 | function renderJS(res) { 2 | return res.value; 3 | } 4 | 5 | export default renderJS; 6 | -------------------------------------------------------------------------------- /src/lib/renderers/yaml.mjs: -------------------------------------------------------------------------------- 1 | import yaml from 'yaml'; 2 | import { YAMLMap, YAMLSeq } from 'yaml/types'; 3 | import optionAPI from '../api/option.mjs'; 4 | 5 | function getIn(obj, path) { 6 | return path.reduce((v, k) => (k in v ? v[k] : {}), obj); 7 | } 8 | 9 | function addComments(context, path, commentNode, iterNode = commentNode) { 10 | const { title, description, comment } = getIn(context, path); 11 | const lines = []; 12 | 13 | if (optionAPI('renderTitle') && title) { 14 | lines.push(` ${title}`, ''); 15 | } 16 | if (optionAPI('renderDescription') && description) { 17 | lines.push(` ${description}`); 18 | } 19 | if (optionAPI('renderComment') && comment) { 20 | lines.push(` ${comment}`); 21 | } 22 | 23 | commentNode.commentBefore = lines.join('\n'); 24 | 25 | if (iterNode instanceof YAMLMap) { 26 | iterNode.items.forEach(n => { 27 | addComments(context, [...path, 'items', n.key.value], n.key, n.value); 28 | }); 29 | } else if (iterNode instanceof YAMLSeq) { 30 | iterNode.items.forEach((n, i) => { 31 | addComments(context, [...path, 'items', i], n); 32 | }); 33 | } 34 | } 35 | 36 | /** Render YAML string from the generated value and context 37 | * 38 | * @param value 39 | * @param context 40 | * @returns {string} 41 | */ 42 | function renderYAML({ value, context }) { 43 | const nodes = yaml.createNode(value); 44 | 45 | addComments(context, [], nodes); 46 | 47 | const doc = new yaml.Document(); 48 | doc.contents = nodes; 49 | 50 | return doc.toString(); 51 | } 52 | 53 | export default renderYAML; 54 | -------------------------------------------------------------------------------- /src/lib/types/boolean.mjs: -------------------------------------------------------------------------------- 1 | import booleanGenerator from '../generators/boolean.mjs'; 2 | 3 | const booleanType = booleanGenerator; 4 | 5 | export default booleanType; 6 | -------------------------------------------------------------------------------- /src/lib/types/index.mjs: -------------------------------------------------------------------------------- 1 | import _boolean from './boolean.mjs'; 2 | import _null from './null.mjs'; 3 | import _array from './array.mjs'; 4 | import _integer from './integer.mjs'; 5 | import _number from './number.mjs'; 6 | import _object from './object.mjs'; 7 | import _string from './string.mjs'; 8 | 9 | const typeMap = { 10 | boolean: _boolean, 11 | null: _null, 12 | array: _array, 13 | integer: _integer, 14 | number: _number, 15 | object: _object, 16 | string: _string, 17 | }; 18 | 19 | export default typeMap; 20 | -------------------------------------------------------------------------------- /src/lib/types/integer.mjs: -------------------------------------------------------------------------------- 1 | import number from './number.mjs'; 2 | 3 | // The `integer` type is just a wrapper for the `number` type. The `number` type 4 | // returns floating point numbers, and `integer` type truncates the fraction 5 | // part, leaving the result as an integer. 6 | 7 | function integerType(value) { 8 | return Math.floor(number({ ...value })); 9 | } 10 | 11 | export default integerType; 12 | -------------------------------------------------------------------------------- /src/lib/types/null.mjs: -------------------------------------------------------------------------------- 1 | import nullGenerator from '../generators/null.mjs'; 2 | 3 | const nullType = nullGenerator; 4 | 5 | export default nullType; 6 | -------------------------------------------------------------------------------- /src/lib/types/number.mjs: -------------------------------------------------------------------------------- 1 | import random from '../core/random.mjs'; 2 | import env from '../core/constants.mjs'; 3 | 4 | function numberType(value) { 5 | let min = (typeof value.minimum === 'undefined' || value.minimum === -Number.MAX_VALUE) 6 | ? env.MIN_INTEGER 7 | : value.minimum; 8 | let max = (typeof value.maximum === 'undefined' || value.maximum === Number.MAX_VALUE) 9 | ? env.MAX_INTEGER 10 | : value.maximum; 11 | 12 | if (min > max) { 13 | max = Number.MAX_SAFE_INTEGER; 14 | } 15 | 16 | const multipleOf = value.multipleOf; 17 | const decimals = multipleOf && String(multipleOf).match(/e-(\d)|\.(\d+)$/); 18 | 19 | if (decimals) { 20 | const number = ((Math.random() * random.number(0, 10)) + 1) * multipleOf; 21 | const truncate = decimals[1] || decimals[2].length; 22 | const result = parseFloat(number.toFixed(truncate)); 23 | const base = random.number(min, max - 1); 24 | 25 | if (!String(result).includes('.')) { 26 | return (base + result).toExponential(); 27 | } 28 | return base + result; 29 | } 30 | 31 | if (multipleOf) { 32 | max = Math.floor(max / multipleOf) * multipleOf; 33 | min = Math.ceil(min / multipleOf) * multipleOf; 34 | } 35 | 36 | if (value.exclusiveMinimum && min === value.minimum) { 37 | min += multipleOf || 1; 38 | } 39 | 40 | if (value.exclusiveMaximum && max === value.maximum) { 41 | max -= multipleOf || 1; 42 | } 43 | 44 | if (min > max) { 45 | return NaN; 46 | } 47 | 48 | if (multipleOf) { 49 | let base = random.number(Math.floor(min / multipleOf), Math.floor(max / multipleOf)) * multipleOf; 50 | 51 | while (base < min) { 52 | base += multipleOf; 53 | } 54 | 55 | return base; 56 | } 57 | 58 | return random.number(min, max, undefined, undefined, value.type !== 'integer'); 59 | } 60 | 61 | export default numberType; 62 | -------------------------------------------------------------------------------- /src/lib/types/string.mjs: -------------------------------------------------------------------------------- 1 | import thunk from '../generators/thunk.mjs'; 2 | import ipv4 from '../generators/ipv4.mjs'; 3 | import dateTime from '../generators/dateTime.mjs'; 4 | import date from '../generators/date.mjs'; 5 | import time from '../generators/time.mjs'; 6 | import coreFormat from '../generators/coreFormat.mjs'; 7 | import optionAPI from '../api/option.mjs'; 8 | import format from '../api/format.mjs'; 9 | import random from '../core/random.mjs'; 10 | import utils from '../core/utils.mjs'; 11 | 12 | function generateFormat(value, invalid) { 13 | const callback = format(value.format); 14 | 15 | if (typeof callback === 'function') { 16 | return callback(value); 17 | } 18 | 19 | switch (value.format) { 20 | case 'date-time': 21 | case 'datetime': 22 | return dateTime(); 23 | case 'date': 24 | return date(); 25 | case 'time': 26 | return time(); 27 | case 'ipv4': 28 | return ipv4(); 29 | case 'regex': 30 | // TODO: discuss 31 | return '.+?'; 32 | case 'email': 33 | case 'hostname': 34 | case 'ipv6': 35 | case 'uri': 36 | case 'uri-reference': 37 | case 'iri': 38 | case 'iri-reference': 39 | case 'idn-email': 40 | case 'idn-hostname': 41 | case 'json-pointer': 42 | case 'slug': 43 | case 'uri-template': 44 | case 'uuid': 45 | case 'duration': 46 | return coreFormat(value.format); 47 | default: 48 | if (typeof callback === 'undefined') { 49 | if (optionAPI('failOnInvalidFormat')) { 50 | throw new Error(`unknown registry key ${utils.short(value.format)}`); 51 | } else { 52 | return invalid(); 53 | } 54 | } 55 | 56 | throw new Error(`unsupported format '${value.format}'`); 57 | } 58 | } 59 | 60 | function stringType(value) { 61 | // here we need to force type to fix #467 62 | const output = utils.typecast('string', value, opts => { 63 | if (value.format) { 64 | return generateFormat(value, () => thunk(opts.minLength, opts.maxLength)); 65 | } 66 | 67 | if (value.pattern) { 68 | return random.randexp(value.pattern); 69 | } 70 | 71 | return thunk(opts.minLength, opts.maxLength); 72 | }); 73 | 74 | return output; 75 | } 76 | 77 | export default stringType; 78 | -------------------------------------------------------------------------------- /src/lib/vendor.mjs: -------------------------------------------------------------------------------- 1 | const DEPENDENCIES = {}; 2 | 3 | export const getDependencies = () => { 4 | return DEPENDENCIES; 5 | }; 6 | 7 | export const setDependencies = value => { 8 | Object.assign(DEPENDENCIES, value); 9 | }; 10 | -------------------------------------------------------------------------------- /src/main.cjs.js: -------------------------------------------------------------------------------- 1 | const jsf = require('./lib/main').default; 2 | 3 | module.exports = jsf; 4 | module.exports.JSONSchemaFaker = { ...jsf }; 5 | -------------------------------------------------------------------------------- /src/main.iife.js: -------------------------------------------------------------------------------- 1 | /** 2 | --- 3 | $name: JSONSchemaFaker 4 | $footer: 5 | js: | 6 | (function (root, factory) { 7 | if (typeof define === 'function' && define.amd) { 8 | define(factory); 9 | } else if (typeof module === 'object' && module.exports) { 10 | module.exports = factory(); 11 | } else { 12 | root.JSONSchemaFaker = factory(); 13 | } 14 | }(typeof self !== 'undefined' ? self : typeof window !== 'undefined' ? window : globalThis, () => JSONSchemaFaker)); 15 | --- 16 | */ 17 | 18 | const jsf = require('./shared'); 19 | 20 | /* global $RefParser, JSONPath */ 21 | if (typeof $RefParser !== 'undefined' && typeof JSONPath !== 'undefined') { 22 | jsf.setDependencies({ ...JSONPath, $RefParser }); 23 | } 24 | 25 | if (typeof window !== 'undefined') { 26 | window.JSONSchemaFaker = jsf.default; 27 | } 28 | 29 | module.exports = jsf.default; 30 | module.exports.JSONSchemaFaker = jsf.JSONSchemaFaker; 31 | -------------------------------------------------------------------------------- /src/main.mjs: -------------------------------------------------------------------------------- 1 | import './vendor.js'; 2 | 3 | import { setDependencies } from './shared.js'; 4 | 5 | /* global $RefParser, JSONPath */ 6 | if (typeof $RefParser !== 'undefined' && typeof JSONPath !== 'undefined') { 7 | setDependencies({ ...JSONPath, $RefParser }); 8 | } 9 | 10 | export { default, JSONSchemaFaker } from './shared.js'; 11 | -------------------------------------------------------------------------------- /src/shared.js: -------------------------------------------------------------------------------- 1 | export { setDependencies } from './lib/vendor.mjs'; 2 | export { default, JSONSchemaFaker } from './lib/index.mjs'; 3 | -------------------------------------------------------------------------------- /src/web/css/_base/components/Ace.less: -------------------------------------------------------------------------------- 1 | .Ace { 2 | z-index: 1; 3 | min-height: calc((100vh - 12em) / 2); 4 | 5 | &-wrapper { 6 | min-width: 50%; 7 | position: relative; 8 | 9 | + .Ace-wrapper { 10 | &::before { 11 | content: ' '; 12 | position: absolute; 13 | border-top: 1px solid @SILVER; 14 | left: 0; 15 | top: 0; 16 | width: 100%; 17 | z-index: 2; 18 | box-shadow: 0 0 3px rgba(0, 0, 0, .1); 19 | } 20 | 21 | @media screen and (min-width: 720px) { 22 | &::before { 23 | width: 0; 24 | height: 100%; 25 | border-top: 0; 26 | border-left: 1px solid @SILVER; 27 | } 28 | } 29 | } 30 | } 31 | 32 | ~ .abs { 33 | padding: @padding / 2; 34 | opacity: .5; 35 | z-index: 1; 36 | 37 | &:hover { 38 | opacity: 1; 39 | } 40 | 41 | .bu { 42 | background-color: @SILVER; 43 | } 44 | 45 | a { 46 | background-color: white; 47 | padding: @padding / 2; 48 | text-decoration: none; 49 | font-size: 13px; 50 | color: @GRAY; 51 | 52 | &.-on { 53 | color: @BLUE; 54 | } 55 | } 56 | 57 | .sp { 58 | &:first-child a { border-radius: @radius 0 0 @radius; } 59 | &:last-child a { border-radius: 0 @radius @radius 0; } 60 | } 61 | } 62 | 63 | @media screen and (min-width: 720px) { 64 | min-height: calc(100vh - 12em); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/web/css/_base/components/Tabs.less: -------------------------------------------------------------------------------- 1 | .Tabs { 2 | background-color: @SILVER; 3 | background-image: linear-gradient(@SILVER, #e8e8e8); 4 | 5 | > span { 6 | line-height: 1.3; 7 | color: @GRAY; 8 | 9 | .x-close { 10 | z-index: 1; 11 | cursor: pointer; 12 | position: relative; 13 | 14 | &:hover { 15 | color: @WHITE; 16 | 17 | &::before { 18 | background-color: @RED; 19 | position: absolute; 20 | content: ''; 21 | margin: auto; 22 | height: 24px; 23 | width: 24px; 24 | left: 0; 25 | top: 0; 26 | right: 0; 27 | bottom: 0; 28 | z-index: -1; 29 | border-radius: 3px; 30 | } 31 | } 32 | } 33 | 34 | > * { 35 | padding: (@padding / 2) @padding; 36 | background-color: inherit; 37 | color: inherit; 38 | border: 0; 39 | } 40 | 41 | &.sel { 42 | color: @BLUE; 43 | cursor: default; 44 | background: white; 45 | line-height: inherit; 46 | border-radius: 3px 3px 0 0; 47 | box-shadow: 0 -1px 3px rgba(0, 0, 0, .1); 48 | padding-right: 1px; 49 | 50 | button, input { 51 | line-height: inherit; 52 | } 53 | 54 | span { 55 | margin-top: 2px; 56 | margin-bottom: 2px; 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/web/css/_base/components/Toolbar.less: -------------------------------------------------------------------------------- 1 | .Toolbar { 2 | position: relative; 3 | } 4 | 5 | .jsf-about { 6 | .ar { 7 | .menu { 8 | right: 0; 9 | } 10 | } 11 | li { 12 | > .menu { 13 | display: none; 14 | position: absolute; 15 | padding: @padding; 16 | box-shadow: 0 1px 3px rgba(0, 0, 0, .2); 17 | background-color: rgba(255, 255, 255, .95); 18 | } 19 | 20 | &:hover > .menu { 21 | display: block; 22 | } 23 | 24 | li ~ li { margin-top: @margin / 2; } 25 | 26 | li:hover::before { 27 | color: @BLUE; 28 | } 29 | 30 | li::before { 31 | top: 4px; 32 | left: -5px; 33 | position: absolute; 34 | transition: all .3s; 35 | content: '⟀'; 36 | font-size: 15px; 37 | color: @border-color; 38 | transform: rotate(225deg); 39 | } 40 | 41 | li { 42 | white-space: nowrap; 43 | position: relative; 44 | padding-left: 10px; 45 | 46 | &.ni { 47 | padding-left: 0; 48 | &::before { content: ''; } 49 | } 50 | } 51 | 52 | a { 53 | text-decoration: none; 54 | color: @BLUE; 55 | 56 | &:hover { 57 | color: @TEAL; 58 | } 59 | } 60 | } 61 | 62 | p, h2, h3, h4 { 63 | margin-bottom: @margin; 64 | } 65 | } 66 | 67 | .github-ribbon { 68 | transform: rotate(40deg); 69 | background: @border-color; 70 | color: white; 71 | width: 200px; 72 | height: 30px; 73 | line-height: 30px; 74 | position: absolute; 75 | right: -50px; 76 | top: 35px; 77 | } 78 | -------------------------------------------------------------------------------- /src/web/css/_base/layout.less: -------------------------------------------------------------------------------- 1 | @keyframes flick { 2 | 0% { opacity: .5; } 3 | 50% { opacity: 1; } 4 | 100% { opacity: .5; } 5 | } 6 | 7 | @keyframes float { 8 | 0% { transform: translateY(0%) scale(0.9); } 9 | 50% { transform: translateY(-10px); } 10 | 100% { transform: translateY(0%) scale(0.9); } 11 | } 12 | 13 | body { 14 | overflow-x: hidden; 15 | } 16 | 17 | .float { 18 | animation: float 1.6s infinite; 19 | } 20 | 21 | .smoo-fence--overlay { 22 | z-index: 5 !important; 23 | .smoo-fence--wrapper { 24 | max-width: 540px; 25 | } 26 | } 27 | 28 | .loading-overlay { 29 | background-color: white; 30 | position: absolute; 31 | height: 100%; 32 | width: 100%; 33 | z-index: 3; 34 | display: flex; 35 | align-items: center; 36 | color: @GRAY; 37 | transition: opacity .5s; 38 | 39 | &.fade-out { 40 | pointer-events: none; 41 | opacity: 0; 42 | } 43 | } 44 | 45 | .debug { 46 | outline: 1px dashed red; 47 | * { outline: 1px dashed red; } 48 | } 49 | 50 | .-dis { 51 | position: relative; 52 | 53 | &::before, &::after { 54 | position: absolute; 55 | z-index: 5; 56 | bottom: 0; 57 | right: 0; 58 | left: 0; 59 | top: 0; 60 | } 61 | 62 | &::before { 63 | background-color: rgba(255, 255, 255, .7); 64 | animation: flick 1.6s infinite; 65 | content: ' '; 66 | } 67 | 68 | &::after { 69 | background-color: rgba(255, 255, 255, .9); 70 | content: 'Loading...'; 71 | margin: auto; 72 | width: 200px; 73 | height: 30px; 74 | line-height: 30px; 75 | text-align: center; 76 | border-radius: @radius; 77 | box-shadow: 1px 1px 1px rgba(0, 0, 0, .1); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/web/css/_base/reset.less: -------------------------------------------------------------------------------- 1 | * { 2 | margin: 0; 3 | padding: 0; 4 | line-height: 1; 5 | font-size: inherit; 6 | vertical-align: baseline; 7 | } 8 | 9 | iframe { 10 | border: 0; 11 | } 12 | 13 | html { 14 | box-sizing: border-box; 15 | font-size: @font-size; 16 | } 17 | 18 | *, 19 | *::before, 20 | *::after { 21 | box-sizing: border-box; 22 | } 23 | 24 | /* normalize */ 25 | html, body { 26 | width: 100%; 27 | height: 100%; 28 | } 29 | 30 | input, button, body { 31 | font-family: @font-family; 32 | color: @color; 33 | } 34 | 35 | ul, ol { 36 | list-style-position: inside; 37 | } 38 | 39 | /* typography */ 40 | h1 { font-size: @h1; } 41 | h2 { font-size: @h2; } 42 | h3 { font-size: @h3; } 43 | h4 { font-size: @h4; } 44 | h5 { font-size: @h5; } 45 | h6 { font-size: @h6; } 46 | 47 | /* tables */ 48 | table { 49 | border-collapse: separate; 50 | border-spacing: 0; 51 | max-width: 100%; 52 | width: 100%; 53 | } 54 | 55 | th { 56 | text-align: left; 57 | font-weight: bold; 58 | } 59 | 60 | th, 61 | td { 62 | line-height: inherit; 63 | padding: @padding @padding; 64 | } 65 | 66 | th { vertical-align: bottom; } 67 | td { vertical-align: top; } 68 | 69 | /* forms */ 70 | label { 71 | vertical-align: middle; 72 | } 73 | 74 | svg, img, input { 75 | max-width: 100%; 76 | background: transparent; 77 | } 78 | 79 | select, textarea { line-height: 1.75; } 80 | 81 | a, input, button, textarea { 82 | &:focus { 83 | outline: 0; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/web/css/_base/vars.less: -------------------------------------------------------------------------------- 1 | @NAVY: #001f3f; 2 | @BLUE: #0074D9; 3 | @AQUA: #7FDBFF; 4 | @TEAL: #39CCCC; 5 | @OLIVE: #3D9970; 6 | @GREEN: #2ECC40; 7 | @LIME: #01FF70; 8 | @YELLOW: #FFDC00; 9 | @ORANGE: #FF851B; 10 | @RED: #FF4136; 11 | @MAROON: #85144b; 12 | @FUCHSIA: #F012BE; 13 | @PURPLE: #B10DC9; 14 | @BLACK: #111111; 15 | @GRAY: #AAAAAA; 16 | @SILVER: #DDDDDD; 17 | @WHITE: #FFFFFF; 18 | 19 | @background-color: #FFFFFF; 20 | @shadow-color: rgba(0, 0, 0, .1); 21 | @border-color: #BDC3C7; 22 | @color: #34495E; 23 | 24 | @font-family: Dosis, Roboto, 'SF UI Text', 'Helvetica Neue', Helvetica, sans-serif; 25 | @font-size: 12pt; 26 | @padding: 12px; 27 | @margin: 12px; 28 | @radius: 3px; 29 | @action: 40px; 30 | 31 | @h1: @font-size * 3.5; 32 | @h2: @font-size * 2.7; 33 | @h3: @font-size * 2.1; 34 | @h4: @font-size * 1.7; 35 | @h5: @font-size * 1.4; 36 | @h6: @font-size * 1.1; 37 | -------------------------------------------------------------------------------- /src/web/css/app.css: -------------------------------------------------------------------------------- 1 | @import '_base/vars'; 2 | @import '_base/reset'; 3 | @import '_base/layout'; 4 | @import '_base/elements'; 5 | 6 | @import '_base/components/Ace'; 7 | @import '_base/components/Tabs'; 8 | @import '_base/components/Toolbar'; 9 | -------------------------------------------------------------------------------- /src/web/img/sprites/gear.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/web/img/sprites/github.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/web/img/sprites/plus.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/web/js/app.js: -------------------------------------------------------------------------------- 1 | import { auth } from './lib/gists'; 2 | 3 | import Auth from './lib/Auth.svelte'; 4 | import Editor from './lib/Editor.svelte'; 5 | 6 | function main() { 7 | if (typeof window.JSONSchemaFaker !== 'undefined') { 8 | JSONSchemaFaker.extend('faker', () => window.faker); 9 | JSONSchemaFaker.extend('chance', () => window.chance); 10 | } 11 | 12 | // initialize modules 13 | new Auth({ target: document.getElementById('auth') }); // eslint-disable-line 14 | new Editor({ target: document.getElementById('editor') }); // eslint-disable-line 15 | } 16 | 17 | function debug(msg) { 18 | document.querySelector('.loading-overlay .jsf-logo').classList.remove('float'); 19 | document.querySelector('.loading-overlay .tac').innerHTML = ` 20 |

${msg}

21 | 22 | `; 23 | } 24 | 25 | // handles authoentication through github-api 26 | if (window.location.search.includes('?code=')) { 27 | document.querySelector('.loading-overlay .tac').innerText = 'Authenticating...'; 28 | 29 | auth(window.location.search.split('?code=')[1], () => { 30 | const cleanUrl = window.location.href.split('?')[0]; 31 | 32 | window.history.replaceState(null, '', cleanUrl); 33 | 34 | if (window.opener) { 35 | window.close(); 36 | } 37 | }); 38 | } else if (window.location.search.includes('?error=')) { 39 | const message = window.location.search.split('error_description=')[1]; 40 | const error = message.split('&')[0].replace(/\+/g, ' '); 41 | 42 | debug(error); 43 | } else { 44 | setTimeout(() => { 45 | document.querySelector('.loading-overlay').classList.add('fade-out'); 46 | main(); 47 | }, 1260); 48 | } 49 | -------------------------------------------------------------------------------- /src/web/js/lib/Ace.svelte: -------------------------------------------------------------------------------- 1 | 44 | 45 |
46 |
47 | 48 |
49 | -------------------------------------------------------------------------------- /src/web/js/lib/Auth.svelte: -------------------------------------------------------------------------------- 1 | 39 | 40 |
    41 |
  • 42 | 43 | Options 44 | 45 |
  • 46 |
  • 47 | {#if $loggedIn} 48 | 49 | {$session.username} 50 | 51 | {:else} 52 | 53 | Share link? Log in 54 | 55 | {/if} 56 |
  • 57 |
58 | 59 | 60 | 61 | 62 | 63 | New project | 64 | Log out 65 | Save project... | 66 | Schemas | 67 | 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /src/web/js/lib/Gists.svelte: -------------------------------------------------------------------------------- 1 | 20 | 24 | {#if $loggedIn} 25 | {#if pending} 26 | Loading gists... 27 | {:else} 28 |
    29 | {#each filtered as item} 30 |
  1. 31 |
    32 | {item.description || item.id} 33 | 34 |
    35 | 42 |
  2. 43 | {/each} 44 |
45 | {/if} 46 | {/if} 47 | -------------------------------------------------------------------------------- /src/web/js/lib/Icon.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/web/js/lib/Modal.svelte: -------------------------------------------------------------------------------- 1 | 14 | 15 |
16 | 17 |
18 |
19 | -------------------------------------------------------------------------------- /src/web/js/lib/Save.svelte: -------------------------------------------------------------------------------- 1 | Not yet implemented... 2 | -------------------------------------------------------------------------------- /src/web/js/lib/Toggle.svelte: -------------------------------------------------------------------------------- 1 | 15 | 16 | 24 | -------------------------------------------------------------------------------- /src/web/js/lib/util.js: -------------------------------------------------------------------------------- 1 | export function debounce(ms, fn, ctx) { 2 | let t; 3 | return (...args) => { 4 | clearTimeout(t); 5 | t = setTimeout(() => { 6 | fn.apply(ctx, args); 7 | }, ms); 8 | }; 9 | } 10 | 11 | export function throttle(ms, fn, ctx) { 12 | ms = ms || 250; 13 | 14 | let last; 15 | let t; 16 | 17 | return (...args) => { 18 | const now = +new Date(); 19 | 20 | if (last && now < last + ms) { 21 | clearTimeout(t); 22 | t = setTimeout(() => { 23 | last = now; 24 | fn.apply(ctx, args); 25 | }, ms); 26 | } else { 27 | last = now; 28 | fn.apply(ctx, args); 29 | } 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /tests/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../.eslintrc", 3 | "env": { 4 | "mocha": true 5 | }, 6 | "plugins": [ 7 | "mocha" 8 | ], 9 | "rules": { 10 | "mocha/no-exclusive-tests": "error", 11 | "no-unused-expressions": 0 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/e2e/vite.test.mjs: -------------------------------------------------------------------------------- 1 | import { Selector } from 'testcafe'; 2 | 3 | /* global fixture */ 4 | 5 | fixture('Smoke Tests') 6 | .page('http://localhost:8080'); 7 | 8 | test('Should load as expected!', async t => { 9 | await t.expect(Selector('code').withText('const: 42').exists).ok(); 10 | }); 11 | -------------------------------------------------------------------------------- /tests/external-ref-files/issue-571-external-ref.json: -------------------------------------------------------------------------------- 1 | { 2 | "definitions": { 3 | "externalExample": { 4 | "type": "string" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tests/integration/_deps_check.mjs: -------------------------------------------------------------------------------- 1 | if (typeof location === 'undefined') { 2 | global.location = { href: '/' }; 3 | } 4 | 5 | export async function depsCheck(jsf) { 6 | const result = await jsf.resolve({ const: 42 }); 7 | 8 | jsf.option('resolveJsonPath', true); 9 | 10 | const data = await jsf.resolve({ 11 | type: 'object', 12 | properties: { 13 | value: { 14 | const: 42, 15 | }, 16 | other: { 17 | jsonPath: '$.value', 18 | }, 19 | }, 20 | required: [ 21 | 'value', 22 | 'other', 23 | ], 24 | }); 25 | 26 | return { result, data }; 27 | } 28 | -------------------------------------------------------------------------------- /tests/integration/commonjs.test.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import * as td from 'testdouble'; 3 | 4 | import jsf, { JSONSchemaFaker } from '../../dist/main.cjs'; 5 | import { depsCheck } from './_deps_check.mjs'; 6 | 7 | describe('CommonJS', () => { 8 | afterEach(() => { 9 | td.reset(); 10 | }); 11 | 12 | it('should work as expected with legacy default export', () => { 13 | expect(jsf).not.to.be.undefined; 14 | expect(jsf.VERSION).not.to.be.undefined; 15 | expect(jsf.generate).not.to.be.undefined; 16 | expect(jsf.generate({ const: 42 })).to.eql(42); 17 | }); 18 | 19 | it('should warn about deprecated access from default export', () => { 20 | td.replace(console, 'debug', td.func('console.debug')); 21 | 22 | expect(typeof jsf).to.eql('function'); 23 | expect(() => jsf({ const: 42 })).not.to.throw(); 24 | 25 | const fn = td.explain(console.debug); 26 | 27 | expect(fn.callCount).to.eql(1); 28 | expect(fn.calls[0].args[0]).to.contains('deprecated'); 29 | }); 30 | 31 | it('should work as expected with named export', () => { 32 | expect(JSONSchemaFaker).not.to.be.undefined; 33 | expect(JSONSchemaFaker.VERSION).not.to.be.undefined; 34 | expect(JSONSchemaFaker.generate).not.to.be.undefined; 35 | expect(JSONSchemaFaker.generate({ const: 42 })).to.eql(42); 36 | }); 37 | 38 | it('should load third-party dependencies', async () => { 39 | const { result, data } = await depsCheck(jsf); 40 | 41 | expect(result).to.eql(42); 42 | expect(data).to.eql({ value: 42, other: 42 }); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/integration/esmodules.test.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import * as td from 'testdouble'; 3 | 4 | import jsf, { JSONSchemaFaker } from '../../dist/main.mjs'; 5 | import { depsCheck } from './_deps_check.mjs'; 6 | 7 | describe('ES Module', () => { 8 | afterEach(() => { 9 | td.reset(); 10 | }); 11 | 12 | it('should work as expected with legacy default export', () => { 13 | expect(jsf).not.to.be.undefined; 14 | expect(jsf.VERSION).not.to.be.undefined; 15 | expect(jsf.generate).not.to.be.undefined; 16 | expect(jsf.generate({ const: 42 })).to.eql(42); 17 | }); 18 | 19 | it('should warn about deprecated access from default export', () => { 20 | td.replace(console, 'debug', td.func('console.debug')); 21 | 22 | expect(typeof jsf).to.eql('function'); 23 | expect(() => jsf({ const: 42 })).not.to.throw(); 24 | 25 | const fn = td.explain(console.debug); 26 | 27 | expect(fn.callCount).to.eql(1); 28 | expect(fn.calls[0].args[0]).to.contains('deprecated'); 29 | }); 30 | 31 | it('should work as expected with named export', () => { 32 | expect(JSONSchemaFaker).not.to.be.undefined; 33 | expect(JSONSchemaFaker.VERSION).not.to.be.undefined; 34 | expect(JSONSchemaFaker.generate).not.to.be.undefined; 35 | expect(JSONSchemaFaker.generate({ const: 42 })).to.eql(42); 36 | }); 37 | 38 | it('should load third-party dependencies', async () => { 39 | const { result, data } = await depsCheck(jsf); 40 | 41 | expect(result).to.eql(42); 42 | expect(data).to.eql({ value: 42, other: 42 }); 43 | }); 44 | }); 45 | -------------------------------------------------------------------------------- /tests/integration/umdwrapper.test.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import * as td from 'testdouble'; 3 | 4 | import '../../dist/bundle.js'; 5 | import { depsCheck } from './_deps_check.mjs'; 6 | 7 | /* global globalThis */ 8 | 9 | const jsf = globalThis.JSONSchemaFaker; 10 | 11 | describe('UMD Wrapper', () => { 12 | afterEach(() => { 13 | td.reset(); 14 | }); 15 | 16 | it('should work as expected with legacy default export', () => { 17 | expect(jsf).not.to.be.undefined; 18 | expect(jsf.VERSION).not.to.be.undefined; 19 | expect(jsf.generate).not.to.be.undefined; 20 | expect(jsf.generate({ const: 42 })).to.eql(42); 21 | }); 22 | 23 | it('should warn about deprecated access from default export', () => { 24 | td.replace(console, 'debug', td.func('console.debug')); 25 | 26 | expect(typeof jsf).to.eql('function'); 27 | expect(() => jsf({ const: 42 })).not.to.throw(); 28 | 29 | const fn = td.explain(console.debug); 30 | 31 | expect(fn.callCount).to.eql(1); 32 | expect(fn.calls[0].args[0]).to.contains('deprecated'); 33 | }); 34 | 35 | it('should work as expected with named export', () => { 36 | const { JSONSchemaFaker } = jsf; 37 | 38 | expect(JSONSchemaFaker).not.to.be.undefined; 39 | expect(JSONSchemaFaker.VERSION).not.to.be.undefined; 40 | expect(JSONSchemaFaker.generate).not.to.be.undefined; 41 | expect(JSONSchemaFaker.generate({ const: 42 })).to.eql(42); 42 | }); 43 | 44 | it('should load third-party dependencies', async () => { 45 | const { result, data } = await depsCheck(jsf); 46 | 47 | expect(result).to.eql(42); 48 | expect(data).to.eql({ value: 42, other: 42 }); 49 | }); 50 | }); 51 | 52 | -------------------------------------------------------------------------------- /tests/pending/issue-658.json: -------------------------------------------------------------------------------- 1 | { 2 | "$ref": "#/definitions/resultInfoType", 3 | "$schema": "http://json-schema.org/draft-07/schema#", 4 | "definitions": { 5 | "nameInfoType": { 6 | "additionalProperties": false, 7 | "properties": { 8 | "name": { 9 | "type": "string" 10 | } 11 | }, 12 | "required": [ 13 | "name" 14 | ], 15 | "type": "object" 16 | }, 17 | "dataInfoType": { 18 | "additionalProperties": false, 19 | "properties": { 20 | "requiredString": { 21 | "type": "string" 22 | }, 23 | "requiredNameInfoType": { 24 | "$ref": "#/definitions/nameInfoType" 25 | } 26 | }, 27 | "required": [ 28 | "requiredString", 29 | "requiredNameInfoType" 30 | ], 31 | "type": "object" 32 | }, 33 | "surveyInfoType": { 34 | "additionalProperties": false, 35 | "properties": { 36 | "data": { 37 | "$ref": "#/definitions/dataInfoType" 38 | } 39 | }, 40 | "required": [ 41 | "data" 42 | ], 43 | "type": "object" 44 | }, 45 | "resultInfoType": { 46 | "additionalProperties": false, 47 | "properties": { 48 | "nameInfoType": { 49 | "$ref": "#/definitions/nameInfoType" 50 | }, 51 | "surveyInfoType": { 52 | "$ref": "#/definitions/surveyInfoType" 53 | } 54 | }, 55 | "type": "object" 56 | }, 57 | "stepInfoType": { 58 | "additionalProperties": false, 59 | "properties": { 60 | "result": { 61 | "$ref": "#/definitions/resultInfoType" 62 | } 63 | }, 64 | "required": [], 65 | "type": "object" 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/pending/issue-740.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json-schema.org/draft-07/schema#", 3 | "$ref": "#/definitions/Test", 4 | "definitions": { 5 | "Test": { 6 | "type": "object", 7 | "properties": { 8 | "items": { 9 | "type": "array", 10 | "items": { 11 | "type": "object", 12 | "properties": { 13 | "value": { 14 | "type": "string" 15 | } 16 | }, 17 | "required": [ 18 | "value" 19 | ], 20 | "additionalProperties": false 21 | } 22 | }, 23 | "itemsById": { 24 | "type": "object", 25 | "additionalProperties": { 26 | "type": "object", 27 | "properties": { 28 | "value": { 29 | "type": "string" 30 | } 31 | }, 32 | "required": [ 33 | "value" 34 | ], 35 | "additionalProperties": false 36 | } 37 | } 38 | }, 39 | "required": [ 40 | "items", 41 | "itemsById" 42 | ], 43 | "additionalProperties": false 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /tests/pending/issue-742.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "array", 3 | "minItems": 5, 4 | "maxItems": 5, 5 | "items": { 6 | "type": "object", 7 | "properties": { 8 | "id": { 9 | "type": "integer", 10 | "minimum": 1, 11 | "autoIncrement": true, 12 | "initialOffset": 1 13 | } 14 | }, 15 | "required": [ 16 | "id" 17 | ] 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /tests/pending/issue-749.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": { 3 | "fields": { 4 | "type": "object", 5 | "additionalProperties": { 6 | "type": "string" 7 | } 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /tests/pending/issue-772.json: -------------------------------------------------------------------------------- 1 | { 2 | "allOf": [ 3 | { 4 | "anyOf": [ 5 | { 6 | "type": "object", 7 | "properties": { 8 | "a": { 9 | "type": "string" 10 | }, 11 | "b": { 12 | "type": "string" 13 | } 14 | }, 15 | "required": [ 16 | "a", 17 | "b" 18 | ], 19 | "additionalProperties": false 20 | }, 21 | { 22 | "type": "object", 23 | "properties": { 24 | "c": { 25 | "type": "string" 26 | }, 27 | "d": { 28 | "type": "string" 29 | } 30 | }, 31 | "required": [ 32 | "c", 33 | "d" 34 | ], 35 | "additionalProperties": false 36 | } 37 | ] 38 | }, 39 | { 40 | "type": "object", 41 | "properties": { 42 | "a": { 43 | "const": "azer" 44 | } 45 | }, 46 | "required": [ 47 | "a" 48 | ], 49 | "additionalProperties": true 50 | } 51 | ] 52 | } 53 | -------------------------------------------------------------------------------- /tests/pending/issue-775.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "https://example.com/schemas/customer", 3 | "type": "object", 4 | "properties": { 5 | "first_name": { 6 | "$ref": "#/$defs/name" 7 | }, 8 | "last_name": { 9 | "$ref": "#/$defs/name" 10 | }, 11 | "test": { 12 | "type": "object", 13 | "properties": { 14 | "test2": { 15 | "$ref": "#/$defs/name" 16 | } 17 | }, 18 | "required": [ 19 | "test2" 20 | ] 21 | } 22 | }, 23 | "required": [ 24 | "first_name", 25 | "last_name", 26 | "test" 27 | ], 28 | "$defs": { 29 | "name": { 30 | "type": "object", 31 | "properties": { 32 | "kek": { 33 | "type": "string" 34 | } 35 | }, 36 | "required": [ 37 | "kek" 38 | ] 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/pending/issue-783.json: -------------------------------------------------------------------------------- 1 | { 2 | "$id": "BuiltParameters", 3 | "title": "BuiltParameters", 4 | "description": "The schema of BuiltParameters", 5 | "type": "object", 6 | "properties": { 7 | "primitiveId": { 8 | "type": "string" 9 | }, 10 | "parameterId": { 11 | "type": "string" 12 | }, 13 | "parameterName": { 14 | "type": "string" 15 | }, 16 | "parameterType": { 17 | "type": "string", 18 | "enum": [ 19 | "GI", 20 | "GI2", 21 | "a" 22 | ] 23 | }, 24 | "parameterProperties": { 25 | "type": "object" 26 | } 27 | }, 28 | "additionalProperties": false, 29 | "required": [ 30 | "primitiveId", 31 | "parameterId", 32 | "parameterName", 33 | "parameterType" 34 | ], 35 | "dependencies": { 36 | "parameterType": { 37 | "oneOf": [ 38 | { 39 | "properties": { 40 | "parameterType": { 41 | "enum": [ 42 | "GI", 43 | "GI2" 44 | ] 45 | } 46 | }, 47 | "not": { 48 | "required": [ 49 | "parameterProperties" 50 | ] 51 | } 52 | }, 53 | { 54 | "not": { 55 | "properties": { 56 | "parameterType": { 57 | "enum": [ 58 | "GI", 59 | "GI2" 60 | ] 61 | } 62 | } 63 | }, 64 | "required": [ 65 | "parameterProperties" 66 | ] 67 | } 68 | ] 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/schema/core/define/autoIncrement.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "autoIncrement keyword", 4 | "tests": [ 5 | { 6 | "description": "should handle initialOffset", 7 | "schema": { 8 | "items": { 9 | "id": { 10 | "type": "integer", 11 | "autoIncrement": true, 12 | "initialOffset": 100001 13 | } 14 | }, 15 | "minItems": 3, 16 | "maxItems": 3 17 | }, 18 | "repeat": 1, 19 | "equal": [ 20 | { 21 | "id": 100001 22 | }, 23 | { 24 | "id": 100002 25 | }, 26 | { 27 | "id": 100003 28 | } 29 | ] 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /tests/schema/core/dependencies.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "dependencies support", 4 | "tests": [ 5 | { 6 | "description": "should handle property-dependencies", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "name": { 11 | "type": "string" 12 | }, 13 | "credit_card": { 14 | "type": "number" 15 | }, 16 | "billing_address": { 17 | "type": "string" 18 | } 19 | }, 20 | "required": [ 21 | "name" 22 | ], 23 | "dependencies": { 24 | "credit_card": [ 25 | "billing_address" 26 | ] 27 | } 28 | }, 29 | "valid": true, 30 | "set": { 31 | "alwaysFakeOptionals": true 32 | } 33 | }, 34 | { 35 | "description": "should handle schema-dependencies", 36 | "schema": { 37 | "type": "object", 38 | "properties": { 39 | "name": { 40 | "type": "string" 41 | }, 42 | "credit_card": { 43 | "type": "number" 44 | } 45 | }, 46 | "required": [ 47 | "name" 48 | ], 49 | "dependencies": { 50 | "credit_card": { 51 | "properties": { 52 | "billing_address": { 53 | "type": "string" 54 | } 55 | }, 56 | "required": [ 57 | "billing_address" 58 | ] 59 | } 60 | } 61 | }, 62 | "valid": true, 63 | "set": { 64 | "alwaysFakeOptionals": true 65 | } 66 | } 67 | ] 68 | } 69 | ] 70 | -------------------------------------------------------------------------------- /tests/schema/core/extend/chance-extend.mjs: -------------------------------------------------------------------------------- 1 | import Chance from 'chance'; 2 | 3 | export function extend() { 4 | const chance = new Chance(); 5 | 6 | chance.mixin({ 7 | user() { 8 | return { 9 | first: chance.first(), 10 | last: chance.last(), 11 | email: chance.email(), 12 | }; 13 | }, 14 | }); 15 | 16 | return chance; 17 | } 18 | 19 | export function register(jsf) { 20 | return jsf.extend('chance', this.extend); 21 | } 22 | -------------------------------------------------------------------------------- /tests/schema/core/extend/chance.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "chance extension", 4 | "tests": [ 5 | { 6 | "description": "should handle chance.user", 7 | "schema": { 8 | "chance": "user", 9 | "type": "object", 10 | "properties": { 11 | "first": { "type": "string" }, 12 | "last": { "type": "string" }, 13 | "email": { "type": "string" } 14 | }, 15 | "required": ["first", "last", "email"] 16 | }, 17 | "valid": true, 18 | "require": "core/extend/chance-extend" 19 | } 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/schema/core/extend/faker-extend.mjs: -------------------------------------------------------------------------------- 1 | import { faker } from '@faker-js/faker/locale/de'; 2 | 3 | export function extend() { 4 | faker.mixin = (namespace, fnObject) => { 5 | faker[namespace] = fnObject; 6 | }; 7 | 8 | faker.mixin('custom', { 9 | statement(length) { 10 | return `${faker.name.firstName()} has ${faker.finance.amount()} on ${faker.finance.account(length)}.`; 11 | }, 12 | returnThisValue(val) { 13 | return val; 14 | }, 15 | }); 16 | 17 | return faker; 18 | } 19 | 20 | export function register(jsf) { 21 | return jsf.extend('faker', this.extend); 22 | } 23 | -------------------------------------------------------------------------------- /tests/schema/core/extend/faker.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "faker extension", 4 | "tests": [ 5 | { 6 | "description": "should handle faker.custom.statement", 7 | "schema": { 8 | "type": "string", 9 | "faker": { 10 | "custom.statement": [19] 11 | } 12 | }, 13 | "valid": true, 14 | "require": "core/extend/faker-extend" 15 | } 16 | ] 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /tests/schema/core/extend/mockjs-extend.mjs: -------------------------------------------------------------------------------- 1 | import Mock from 'mockjs'; 2 | 3 | export function extend() { 4 | return { 5 | mock(xx) { 6 | return Mock.mock(xx); 7 | }, 8 | }; 9 | } 10 | 11 | export function register(jsf) { 12 | return jsf.extend('mock', this.extend); 13 | } 14 | -------------------------------------------------------------------------------- /tests/schema/core/formats.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "format keywords", 4 | "tests": [ 5 | { 6 | "description": "should handle datetime", 7 | "schema": { 8 | "type": "string", 9 | "format": "datetime" 10 | }, 11 | "type": "string" 12 | }, 13 | { 14 | "description": "should handle date", 15 | "schema": { 16 | "type": "string", 17 | "format": "date" 18 | }, 19 | "type": "string" 20 | }, 21 | { 22 | "description": "should handle time", 23 | "schema": { 24 | "type": "string", 25 | "format": "time" 26 | }, 27 | "type": "string" 28 | } 29 | ] 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /tests/schema/core/formats/semver.mjs: -------------------------------------------------------------------------------- 1 | export function register(jsf) { 2 | return jsf.format({ 3 | semver() { 4 | return jsf.random.randexp('\\d\\.\\d\\.[1-9]\\d?'); 5 | }, 6 | }); 7 | } 8 | -------------------------------------------------------------------------------- /tests/schema/core/issues/all-of-one-of-all-of-nested-overlap-with-additional-props.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "allOf and oneOf nested with overlapping conditions", 4 | "schemas": [{ 5 | "$schema": "http://json-schema.org/draft-04/schema#", 6 | "type": "object", 7 | "properties": { 8 | "date_of_birth": { 9 | "type": "string", 10 | "minimum": 10, 11 | "maximum": 10 12 | }, 13 | "age_group": { 14 | "type": "string", 15 | "minLength": 5, 16 | "maxLength": 5 17 | } 18 | }, 19 | 20 | "allOf": [{ 21 | "anyOf": [{ 22 | "required": [ 23 | "age_group" 24 | ] 25 | }, { 26 | "required": [ 27 | "age_group", 28 | "date_of_birth" 29 | ] 30 | }] 31 | }] 32 | }], 33 | "tests": [ 34 | { 35 | "description": "should combine recursively", 36 | "schema": "schemas.0", 37 | "valid": true 38 | } 39 | ] 40 | } 41 | ] 42 | -------------------------------------------------------------------------------- /tests/schema/core/issues/all-of-one-of-all-of-nested-overlap.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "allOf and oneOf nested with overlapping conditions", 4 | "schemas": [{ 5 | "$schema": "http://json-schema.org/draft-04/schema#", 6 | "type": "object", 7 | "additionalProperties": false, 8 | "properties": { 9 | "date_of_birth": { 10 | "type": "string", 11 | "minimum": 10, 12 | "maximum": 10 13 | }, 14 | "age_group": { 15 | "type": "string", 16 | "minLength": 5, 17 | "maxLength": 5 18 | } 19 | }, 20 | 21 | "allOf": [{ 22 | "anyOf": [{ 23 | "required": [ 24 | "age_group" 25 | ] 26 | }, { 27 | "required": [ 28 | "age_group", 29 | "date_of_birth" 30 | ] 31 | }] 32 | }] 33 | }], 34 | "tests": [ 35 | { 36 | "description": "should combine recursively", 37 | "schema": "schemas.0", 38 | "valid": true 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /tests/schema/core/issues/all-of-one-of-all-of-nested.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "allOf oneOf allOff nested", 4 | "schemas": [{ 5 | "$schema": "http://json-schema.org/draft-04/schema#", 6 | "type": "object", 7 | "additionalProperties": true, 8 | "properties": { 9 | "date_of_birth": { 10 | "type": "string", 11 | "minimum": 10, 12 | "maximum": 10 13 | }, 14 | "age_group": { 15 | "type": "string", 16 | "minLength": 5, 17 | "maxLength": 5 18 | } 19 | }, 20 | 21 | "allOf": [{ 22 | "oneOf": [{ 23 | "allOf": [{ 24 | "type": "object", 25 | "required": ["a"], 26 | "properties": { 27 | "a": { 28 | "type": "string" 29 | } 30 | } 31 | },{ 32 | "type": "object", 33 | "required": ["b"], 34 | "properties": { 35 | "b": { 36 | "type": "string" 37 | } 38 | } 39 | }] 40 | }, { 41 | "allOf": [{ 42 | "type": "object", 43 | "required": ["a"], 44 | "properties": { 45 | "a": { 46 | "type": "string" 47 | } 48 | } 49 | },{ 50 | "type": "object", 51 | "required": ["c"], 52 | "properties": { 53 | "c": { 54 | "type": "string" 55 | } 56 | } 57 | }] 58 | }] 59 | }] 60 | }], 61 | "tests": [ 62 | { 63 | "description": "should combine recursively", 64 | "schema": "schemas.0", 65 | "valid": true, 66 | "hasProps": ["a"] 67 | } 68 | ] 69 | } 70 | ] 71 | -------------------------------------------------------------------------------- /tests/schema/core/issues/all-of-one-of-nested.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "allOf and oneOf nested", 4 | "schemas": [{ 5 | "$schema": "http://json-schema.org/draft-04/schema#", 6 | "type": "object", 7 | "additionalProperties": false, 8 | "properties": { 9 | "date_of_birth": { 10 | "type": "string", 11 | "minimum": 10, 12 | "maximum": 10 13 | }, 14 | "age_group": { 15 | "type": "string", 16 | "minLength": 5, 17 | "maxLength": 5 18 | } 19 | }, 20 | 21 | "allOf": [{ 22 | "oneOf": [{ 23 | "required": [ 24 | "age_group" 25 | ] 26 | }, { 27 | "required": [ 28 | "date_of_birth" 29 | ] 30 | }] 31 | }] 32 | }], 33 | "tests": [ 34 | { 35 | "description": "should combine recursively", 36 | "schema": "schemas.0", 37 | "valid": true 38 | } 39 | ] 40 | } 41 | ] 42 | -------------------------------------------------------------------------------- /tests/schema/core/issues/allOf.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "sub-schema mixins", 4 | "schemas": [ 5 | { 6 | "type": "object", 7 | "definitions": { 8 | "inner": { 9 | "aString": { 10 | "allOf": [ 11 | { "type": "string" }, 12 | { "$ref": "#/definitions/rules" } 13 | ] 14 | } 15 | }, 16 | "rules": { 17 | "allOf": [ 18 | { "$ref": "#/definitions/twoChars" }, 19 | { "$ref": "#/definitions/asEmail" } 20 | ] 21 | }, 22 | "twoChars": { 23 | "minLength": 10 24 | }, 25 | "asEmail": { 26 | "faker": "internet.email" 27 | } 28 | }, 29 | "properties": { 30 | "anArray": { 31 | "type": "array", 32 | "items": { 33 | "type": "object", 34 | "properties": { 35 | "allOf": [ 36 | { "$ref": "#/definitions/inner" } 37 | ] 38 | }, 39 | "required": ["aString"] 40 | } 41 | } 42 | }, 43 | "required": ["anArray"] 44 | } 45 | ], 46 | "tests": [ 47 | { 48 | "description": "should combine recursively", 49 | "schema": "schemas.0", 50 | "valid": true 51 | } 52 | ] 53 | } 54 | ] 55 | -------------------------------------------------------------------------------- /tests/schema/core/issues/anonymous.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "anonymous schemas", 4 | "tests": [ 5 | { 6 | "description": "should not work as expected", 7 | "schema": { 8 | "x": { 9 | "enum": ["y"] 10 | } 11 | }, 12 | "valid": true, 13 | "equal": { 14 | "x": "y" 15 | } 16 | } 17 | ] 18 | } 19 | ] 20 | -------------------------------------------------------------------------------- /tests/schema/core/issues/chance-and-faker.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "chance and faker", 4 | "tests": [ 5 | { 6 | "skip": true, 7 | "description": "should throw error when both defined", 8 | "schema": { 9 | "chance": "url", 10 | "faker": "internet.email" 11 | }, 12 | "throws": "ambiguous generator .+: .+?" 13 | } 14 | ] 15 | } 16 | ] 17 | -------------------------------------------------------------------------------- /tests/schema/core/issues/chance.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "chance issues", 4 | "tests": [ 5 | { 6 | "description": "should allow url-format (0.7.1+)", 7 | "schema": { 8 | "type": "string", 9 | "chance": "url" 10 | }, 11 | "valid": true 12 | }, 13 | { 14 | "description": "should execute chance generator before default boolean type generator", 15 | "schema": { 16 | "type": "boolean", 17 | "chance": { 18 | "bool": { 19 | "likelihood": 100 20 | } 21 | } 22 | }, 23 | "equal": true 24 | } 25 | ] 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /tests/schema/core/issues/cleanup.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "should solve #243", 4 | "schemas": [ 5 | { 6 | "type": "array", 7 | "minItems": 10, 8 | "maxItems": 20, 9 | "items": { 10 | "type": "object", 11 | "properties": { 12 | "salary": { 13 | "type": "object", 14 | "properties": { 15 | "amount": { 16 | "type": "number", 17 | "faker": { 18 | "datatype.number": { 19 | "min": 2000, 20 | "max": 5000, 21 | "precision": 100 22 | } 23 | } 24 | }, 25 | "currency": { 26 | "enum": ["GBP", "USD", "EUR", "PLN"] 27 | } 28 | }, 29 | "required": [ 30 | "amount", 31 | "currency" 32 | ] 33 | }, 34 | "hiredAt": { 35 | "faker": { 36 | "date.between": ["1990-01-01", "2012-12-29"] 37 | } 38 | } 39 | }, 40 | "required": [ 41 | "salary", 42 | "hiredAt" 43 | ] 44 | } 45 | } 46 | ], 47 | "tests": [ 48 | { 49 | "description": "should keep faker props", 50 | "schema": "schemas.0", 51 | "valid": true, 52 | "hasProps": ["salary", "hiredAt"] 53 | } 54 | ] 55 | } 56 | ] 57 | -------------------------------------------------------------------------------- /tests/schema/core/issues/errors.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "error reporting", 4 | "tests": [ 5 | { 6 | "description": "should report paths", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "test": { 11 | "type": "unknown" 12 | } 13 | }, 14 | "required": ["test"] 15 | }, 16 | "throws": "unknown primitive .+? in \\/properties\\/test\\/type" 17 | } 18 | ] 19 | } 20 | ] 21 | -------------------------------------------------------------------------------- /tests/schema/core/issues/format.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "using formats", 4 | "tests": [ 5 | { 6 | "description": "should support core only", 7 | "schema": { 8 | "type": "string", 9 | "format": "not_exists" 10 | }, 11 | "throws": "unknown registry key" 12 | }, 13 | { 14 | "description": "should support custom formats", 15 | "schema": { 16 | "type": "string", 17 | "format": "semver" 18 | }, 19 | "valid": true, 20 | "repeat": 100, 21 | "require": "core/formats/semver" 22 | }, 23 | { 24 | "description": "should support faker/chance on numeric types", 25 | "schema": { 26 | "type": "object", 27 | "properties": { 28 | "chanceNumber": { 29 | "type": "integer", 30 | "chance": "natural" 31 | }, 32 | "fakerNumber": { 33 | "type": "integer", 34 | "faker": "datatype.number" 35 | } 36 | } 37 | }, 38 | "valid": true 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /tests/schema/core/issues/inferred.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "inferred-types keyword issues", 4 | "tests": [ 5 | { 6 | "description": "should work for non-reserved words", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "foo": { 11 | "type": "array", 12 | "items": [ 13 | {"enum":["bar"]} 14 | ], 15 | "minItems": 1, 16 | "maxItems": 1 17 | } 18 | }, 19 | "required": ["foo"] 20 | }, 21 | "equal": { 22 | "foo": ["bar"] 23 | } 24 | }, 25 | { 26 | "description": "should work for reserved words", 27 | "schema": { 28 | "type": "object", 29 | "properties": { 30 | "items": { 31 | "type": "array", 32 | "items": [ 33 | {"enum":["bar"]} 34 | ], 35 | "minItems": 1, 36 | "maxItems": 1 37 | } 38 | }, 39 | "required": ["items"] 40 | }, 41 | "equal": { 42 | "items": ["bar"] 43 | } 44 | } 45 | ] 46 | } 47 | ] 48 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-115.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "support for x-*", 4 | "tests": [ 5 | { 6 | "description": "should handle x-faker", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "name": { 11 | "type": "string", 12 | "x-faker": "name.fullName" 13 | }, 14 | "email": { 15 | "type": "string", 16 | "x-faker": "internet.email" 17 | } 18 | }, 19 | "required": [ 20 | "name", 21 | "email" 22 | ] 23 | }, 24 | "valid": true 25 | }, 26 | { 27 | "description": "should handle x-chance", 28 | "schema": { 29 | "type": "object", 30 | "properties": { 31 | "userId": { 32 | "type": "string", 33 | "x-chance": "guid" 34 | }, 35 | "emailAddr": { 36 | "type": "string", 37 | "x-chance": { 38 | "email": { 39 | "domain": "fake.com" 40 | } 41 | }, 42 | "pattern": ".+@fake.com" 43 | } 44 | }, 45 | "required": [ 46 | "userId", 47 | "emailAddr" 48 | ] 49 | }, 50 | "valid": true 51 | } 52 | ] 53 | } 54 | ] 55 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-158.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "merge and shuffling properties", 4 | "tests": [ 5 | { 6 | "description": "should fake all properties as expected", 7 | "schema": { 8 | "properties": { 9 | "test": { 10 | "type": "string" 11 | }, 12 | "count": { 13 | "type": "integer" 14 | } 15 | }, 16 | "additionalProperties": { 17 | "type": "string", 18 | "faker": "internet.email" 19 | }, 20 | "patternProperties": { 21 | "^ignored": { 22 | "type": "string" 23 | }, 24 | "prop$": { 25 | "faker": "name.fullName" 26 | } 27 | }, 28 | "required": [ 29 | "test", 30 | "count", 31 | "dropped", 32 | "ignored-prop" 33 | ] 34 | }, 35 | "valid": true, 36 | "repeat": 100 37 | } 38 | ] 39 | } 40 | ] 41 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-171.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "support passing array as a single parameter (instead of multiple params)", 4 | "tests": [ 5 | { 6 | "description": "should pass an array, when encountered double square brackets", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "title": { 11 | "type": "string", 12 | "chance": { 13 | "pickone": [ 14 | [ 15 | "one", 16 | "two", 17 | "three" 18 | ] 19 | ] 20 | } 21 | } 22 | }, 23 | "required": [ 24 | "title" 25 | ] 26 | }, 27 | "valid": true 28 | } 29 | ] 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-193.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "pattern and min/max length constraints", 4 | "tests": [ 5 | { 6 | "description": "should support minLength", 7 | "schema": { 8 | "type": "string", 9 | "pattern": ".+", 10 | "minLength": 21 11 | }, 12 | "valid": true 13 | }, 14 | { 15 | "description": "should support maxLength", 16 | "schema": { 17 | "type": "string", 18 | "pattern": ".+", 19 | "maxLength": 2 20 | }, 21 | "valid": true 22 | } 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-224.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "special cases with enums", 4 | "tests": [ 5 | { 6 | "description": "should apply oneOf for minimum/maximum", 7 | "schema": { 8 | "type": "integer", 9 | "enum": [ 10 | 1, 11 | 10, 12 | 100, 13 | 1000, 14 | 10000 15 | ], 16 | "oneOf": [ 17 | { 18 | "maximum": 1000 19 | }, 20 | { 21 | "minimum": 10 22 | } 23 | ] 24 | }, 25 | "repeat": 10, 26 | "valid": true 27 | }, 28 | { 29 | "issue": 580, 30 | "description": "should apply oneOf for overlapping minimum/maximum", 31 | "schema": { 32 | "type": "integer", 33 | "enum": [1, 2, 3, 4, 5, 6, 7, 8, 9], 34 | "oneOf": [ 35 | { 36 | "minimum": 2, 37 | "maximum": 6 38 | }, 39 | { 40 | "minimum": 4, 41 | "maximum": 8 42 | } 43 | ] 44 | }, 45 | "repeat": 10, 46 | "valid": true 47 | }, 48 | { 49 | "description": "should filter out non valid values", 50 | "schema": { 51 | "type": "number", 52 | "enum": [1, 2, 3, 4, 5, 6, 7, 8], 53 | "minimum": 3.5, 54 | "maximum": 6.5 55 | }, 56 | "repeat": 10, 57 | "valid": true 58 | } 59 | ] 60 | } 61 | ] 62 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-238.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "allow empty arrays and null values as result", 4 | "tests": [ 5 | { 6 | "description": "should not filter out null elements from array", 7 | "schema": { 8 | "properties": { 9 | "myArrayWithNullValue": { 10 | "type": [ 11 | "array" 12 | ], 13 | "items": { 14 | "type": [ 15 | "null" 16 | ] 17 | }, 18 | "minimum": 1, 19 | "minItems": 1, 20 | "maxItems": 1 21 | } 22 | }, 23 | "required": [ 24 | "myArrayWithNullValue" 25 | ] 26 | }, 27 | "valid": true 28 | }, 29 | { 30 | "description": "should create array without elements", 31 | "schema": { 32 | "type": "array", 33 | "items": { 34 | "type": [ 35 | "null" 36 | ] 37 | }, 38 | "minimum": 1, 39 | "maximum": 1, 40 | "minItems": 0, 41 | "maxItems": 0 42 | }, 43 | "valid": true 44 | }, 45 | { 46 | "description": "should create null value", 47 | "schema": { 48 | "id": "fooNull", 49 | "properties": { 50 | "fooNull": { 51 | "type": [ 52 | "null" 53 | ] 54 | } 55 | }, 56 | "required": [ 57 | "fooNull" 58 | ] 59 | }, 60 | "valid": true 61 | } 62 | ] 63 | } 64 | ] 65 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-252.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "regression for decimal numbers and multiples", 4 | "tests": [ 5 | { 6 | "description": "should apply multipleOf correctly", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "num": { 11 | "type": "number", 12 | "minimum": 0, 13 | "maximum": 1, 14 | "multipleOf": 0.01 15 | } 16 | }, 17 | "required": [ 18 | "num" 19 | ] 20 | }, 21 | "repeat": 100, 22 | "omit": ["z-schema", "tv4", "ajv"], 23 | "valid": true 24 | } 25 | ] 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-258.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "recursive schemas (self-references)", 3 | "schemas": [ 4 | { 5 | "type": "object", 6 | "properties": { 7 | "user": { 8 | "type": "object", 9 | "properties": { 10 | "id": { 11 | "type": "integer" 12 | }, 13 | "name": { 14 | "type": "string", 15 | "faker": "name.fullName" 16 | }, 17 | "children": { 18 | "$ref": "#/definitions/node" 19 | } 20 | }, 21 | "required": [ 22 | "id", 23 | "name" 24 | ] 25 | } 26 | }, 27 | "required": [ 28 | "user" 29 | ], 30 | "definitions": { 31 | "node": { 32 | "type": "array", 33 | "items": { 34 | "Id": { 35 | "type": "integer" 36 | }, 37 | "Label": { 38 | "type": "string" 39 | }, 40 | "Children": { 41 | "type": "array", 42 | "items": { 43 | "$ref": "#/definitions/node" 44 | }, 45 | "minItems": 5 46 | } 47 | } 48 | } 49 | } 50 | } 51 | ], 52 | "tests": [ 53 | { 54 | "description": "should work as expected", 55 | "schema": "schemas.0", 56 | "valid": true 57 | } 58 | ] 59 | } 60 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-274.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "allOf does not work if array item contains oneOf property", 4 | "tests": [ 5 | { 6 | "description": "should combine sub-schemas on merging allOf", 7 | "schema": { 8 | "$schema": "http://json-schema.org/draft-04/schema#", 9 | "type": "object", 10 | "allOf": [ 11 | { 12 | "oneOf": [ 13 | { 14 | "type": "object", 15 | "properties": { 16 | "b": { 17 | "type": "boolean" 18 | } 19 | }, 20 | "required": [ 21 | "b" 22 | ] 23 | } 24 | ] 25 | }, 26 | { 27 | "type": "object", 28 | "properties": { 29 | "a": { 30 | "type": "string" 31 | } 32 | }, 33 | "required": [ 34 | "a" 35 | ] 36 | } 37 | ] 38 | }, 39 | "valid": true 40 | } 41 | ] 42 | } 43 | ] 44 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-304.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "regression for decimal numbers and multiples", 4 | "tests": [ 5 | { 6 | "description": "should apply multipleOf correctly", 7 | "schema": { 8 | "type": "object", 9 | "allOf": [ 10 | { 11 | "type": "object", 12 | "properties": { 13 | "a": { 14 | "type": "string" 15 | }, 16 | "b": { 17 | "type": "integer" 18 | } 19 | }, 20 | "required": [ 21 | "a", 22 | "b" 23 | ] 24 | }, 25 | { 26 | "type": "object", 27 | "properties": { 28 | "b": { 29 | "type": "integer" 30 | }, 31 | "c": { 32 | "type": "boolean" 33 | } 34 | }, 35 | "required": [ 36 | "b", 37 | "c" 38 | ] 39 | } 40 | ] 41 | }, 42 | "valid": true 43 | } 44 | ] 45 | } 46 | ] 47 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-331.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "regression for non-empty arrays", 4 | "tests": [ 5 | { 6 | "description": "should allow empty arrays if they are required", 7 | "schema": { 8 | "type": "array", 9 | "items": { 10 | "type": "object", 11 | "properties": { 12 | "n": { 13 | "type": "number" 14 | }, 15 | "a": { 16 | "type": "array", 17 | "items": { 18 | "type": "object" 19 | } 20 | } 21 | }, 22 | "required": [ 23 | "n", 24 | "a" 25 | ] 26 | } 27 | }, 28 | "valid": true 29 | } 30 | ] 31 | } 32 | ] 33 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-336.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "regression for oneOf mixins", 4 | "tests": [ 5 | { 6 | "description": "should pick just one property", 7 | "schema": { 8 | "title": "timesync", 9 | "$schema": "http://json-schema.org/draft-04/schema#", 10 | "type": "object", 11 | "properties": { 12 | "sntp": { 13 | "type": "boolean" 14 | }, 15 | "timep": { 16 | "type": "boolean" 17 | }, 18 | "timep-or-sntp": { 19 | "type": "boolean" 20 | }, 21 | "ntp": { 22 | "type": "boolean" 23 | } 24 | }, 25 | "oneOf": [ 26 | { 27 | "required": [ 28 | "sntp" 29 | ] 30 | }, 31 | { 32 | "required": [ 33 | "timep" 34 | ] 35 | }, 36 | { 37 | "required": [ 38 | "timep-or-sntp" 39 | ] 40 | }, 41 | { 42 | "required": [ 43 | "ntp" 44 | ] 45 | } 46 | ], 47 | "additionalProperties": false 48 | }, 49 | "repeat": 100, 50 | "valid": true 51 | } 52 | ] 53 | } 54 | ] 55 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-345.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Invalid JSON generated with cyclic reference", 3 | "tests": [ 4 | { 5 | "description": "it will work as expected", 6 | "schema": { 7 | "type": "object", 8 | "definitions": { 9 | "DefaultCyclic_106": { 10 | "type": "object", 11 | "properties": { 12 | "id": { 13 | "type": "integer" 14 | }, 15 | "me": { 16 | "$ref": "#/definitions/DefaultCyclic_106" 17 | } 18 | }, 19 | "additionalProperties": false, 20 | "required": [ 21 | "id" 22 | ] 23 | } 24 | }, 25 | "properties": { 26 | "id": { 27 | "type": "integer" 28 | }, 29 | "me": { 30 | "$ref": "#/definitions/DefaultCyclic_106" 31 | } 32 | }, 33 | "required": [ 34 | "id" 35 | ], 36 | "additionalProperties": false 37 | }, 38 | "set": { 39 | "optionalsProbability": 0.75 40 | }, 41 | "valid": true 42 | } 43 | ] 44 | } 45 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-369.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Creates unnecessary fields that not described in schema but exists in required section", 3 | "tests": [ 4 | { 5 | "description": "should take missing props from required ones", 6 | "schema": { 7 | "$schema": "http://json-schema.org/draft-04/schema#", 8 | "title": "Customer", 9 | "description": "Customer", 10 | "type": "object", 11 | "properties": { 12 | "emails": { 13 | "type": "array", 14 | "items": { 15 | "type": "object", 16 | "properties": { 17 | "address": { 18 | "type": "string" 19 | }, 20 | "typeCode": { 21 | "type": "string" 22 | }, 23 | "isPrimary": { 24 | "type": "boolean" 25 | } 26 | }, 27 | "required": [ 28 | "address", 29 | "typeCode", 30 | "isPrimary" 31 | ] 32 | }, 33 | "minItems": 1, 34 | "maxItems": 1 35 | } 36 | }, 37 | "required": [ 38 | "name", 39 | "birthDate", 40 | "addresses", 41 | "emails" 42 | ] 43 | }, 44 | "count": 4, 45 | "valid": true 46 | } 47 | ] 48 | } 49 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-379.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Floating point when using multipleOf", 3 | "tests": [ 4 | { 5 | "description": "should truncate up to given decimals", 6 | "schema": { 7 | "type": "number", 8 | "multipleOf": 0.01 9 | }, 10 | "seed": 0.25546874766962246, 11 | "match": "48906250\\.\\d{2}$", 12 | "valid": true 13 | }, 14 | { 15 | "description": "should truncate up to given decimals (large decimals)", 16 | "schema": { 17 | "type": "number", 18 | "multipleOf": 0.01 19 | }, 20 | "seed": 0.06559633646612273, 21 | "equal": -86880732.99, 22 | "valid": true 23 | }, 24 | { 25 | "description": "should also work with minimum (nonzero) and maximum", 26 | "schema": { 27 | "type": "number", 28 | "minimum": 7, 29 | "maximum": 10, 30 | "multipleOf": 0.01 31 | }, 32 | "seed": 0.25546874766962246, 33 | "match": "7\\.\\d{2}$", 34 | "omit": ["tv4", "ajv"], 35 | "valid": true 36 | } 37 | ] 38 | } 39 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-386.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "OneOf/AnyOf Json Schema Validation not working", 4 | "tests": [ 5 | { 6 | "description": "should eventually generate a valid value", 7 | "schema": { 8 | "title": "timesync", 9 | "$schema": "http://json-schema.org/draft-04/schema#", 10 | "type": "object", 11 | "properties": { 12 | "sntp": { 13 | "type": "boolean", 14 | "default": false, 15 | "description": "Update the system clock using SNTP." 16 | }, 17 | "timep": { 18 | "type": "boolean", 19 | "default": false, 20 | "description": "Update the system clock using TIMEP." 21 | }, 22 | "timep-or-sntp": { 23 | "type": "boolean", 24 | "default": true, 25 | "description": "Update the system clock using TIMEP or SNTP." 26 | }, 27 | "ntp": { 28 | "type": "boolean", 29 | "default": false, 30 | "description": "Update the system clock using NTP." 31 | }, 32 | "uri": { 33 | "type": "string", 34 | "description": "The URI of the configuration entity", 35 | "readonly": true 36 | } 37 | }, 38 | "oneOf": [ 39 | { 40 | "required": [ 41 | "sntp" 42 | ] 43 | }, 44 | { 45 | "required": [ 46 | "timep" 47 | ] 48 | }, 49 | { 50 | "required": [ 51 | "timep-or-sntp" 52 | ] 53 | }, 54 | { 55 | "required": [ 56 | "ntp" 57 | ] 58 | } 59 | ], 60 | "additionalProperties": false 61 | }, 62 | "set": { 63 | "alwaysFakeOptionals": true 64 | }, 65 | "valid": true 66 | } 67 | ] 68 | } 69 | ] 70 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-405.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Enum with negative number is not generated", 3 | "tests": [ 4 | { 5 | "description": "should pick anything from enum values", 6 | "schema": { 7 | "type": "integer", 8 | "enum": [ 9 | -4 10 | ] 11 | }, 12 | "equal": -4, 13 | "valid": true 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-416.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Weird output using patternProperties and minProperties", 3 | "tests": [ 4 | { 5 | "description": "it will generate only given props when additionalProperties is false", 6 | "schema": { 7 | "type": "object", 8 | "patternProperties": { 9 | "[a-z0-9]": { 10 | "type": "object", 11 | "properties": { 12 | "example": { 13 | "type": "string" 14 | } 15 | }, 16 | "required": [ 17 | "example" 18 | ] 19 | } 20 | }, 21 | "minProperties": 10, 22 | "maxProperties": 10 23 | }, 24 | "count": 10, 25 | "valid": true 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-419.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Having two properties that have the same value", 3 | "tests": [ 4 | { 5 | "description": "should resolve values from siblings", 6 | "schema": { 7 | "type": "object", 8 | "properties": { 9 | "cards": { 10 | "type": "array", 11 | "items": { 12 | "type": "object", 13 | "properties": { 14 | "id": { 15 | "type": "string", 16 | "default": "osom" 17 | }, 18 | "slug": { 19 | "type": "string", 20 | "template": "#{id}" 21 | } 22 | }, 23 | "required": [ 24 | "id", 25 | "slug" 26 | ] 27 | }, 28 | "minItems": 1, 29 | "maxItems": 1 30 | } 31 | }, 32 | "required": [ 33 | "cards" 34 | ] 35 | }, 36 | "set": { 37 | "useDefaultValue": true 38 | }, 39 | "equal": { 40 | "cards": [ 41 | { 42 | "id": "osom", 43 | "slug": "osom" 44 | } 45 | ] 46 | }, 47 | "valid": true 48 | }, 49 | { 50 | "description": "should access generated values if they're sorted", 51 | "schema": { 52 | "type": "object", 53 | "properties": { 54 | "z": { 55 | "type": "string", 56 | "faker": "name.fullName" 57 | }, 58 | "b": { 59 | "type": "string", 60 | "faker": "name.lastName" 61 | }, 62 | "c": { 63 | "template": "#{b} II" 64 | }, 65 | "y": { 66 | "faker": { 67 | "internet.email": ["#{z}", "#{c}", "#{b}.com"] 68 | } 69 | } 70 | }, 71 | "required": ["z", "b", "c", "y"] 72 | }, 73 | "require": "core/extend/faker-extend", 74 | "valid": true 75 | } 76 | ] 77 | } 78 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-425.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "optionalsProbability not recalculated for each record in an array?", 3 | "tests": [ 4 | { 5 | "description": "it will eventually generate phone property", 6 | "schema": { 7 | "type": "object", 8 | "properties": { 9 | "records": { 10 | "type": "array", 11 | "minItems": 5, 12 | "maxItems": 20, 13 | "items": { 14 | "type": "object", 15 | "properties": { 16 | "name": { 17 | "type": "string", 18 | "faker": "name.fullName" 19 | }, 20 | "phone": { 21 | "type": "string", 22 | "faker": "phone.number" 23 | }, 24 | "email": { 25 | "type": "string", 26 | "faker": "internet.email" 27 | } 28 | }, 29 | "required": [ 30 | "name", 31 | "email" 32 | ] 33 | } 34 | } 35 | }, 36 | "required": [ 37 | "records" 38 | ] 39 | }, 40 | "set": { 41 | "optionalsProbability": 0.6 42 | }, 43 | "valid": true 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-442.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "useDefaultValue should use default, not properties.default", 3 | "tests": [ 4 | { 5 | "description": "Setting useDefaultValue should not pick from properties.default", 6 | "schema": { 7 | "type": "object", 8 | "required": ["default", "other"], 9 | "properties": { 10 | "default": { 11 | "type": "boolean", 12 | "default": false 13 | }, 14 | "other": { 15 | "type": "string", 16 | "enum": ["value"] 17 | } 18 | } 19 | }, 20 | "set": { 21 | "useDefaultValue": true 22 | }, 23 | "equal": { 24 | "default": false, 25 | "other": "value" 26 | }, 27 | "valid": true 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-444.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "properties with not", 3 | "tests": [ 4 | { 5 | "description": "should not be included in with additional properties when not schema matched", 6 | "schema": { 7 | "type": "object", 8 | "properties": { 9 | "allowed": { 10 | "type": "string", 11 | "enum": ["value"] 12 | }, 13 | "notAllowed": { 14 | "not": {} 15 | } 16 | } 17 | }, 18 | "equal": { 19 | "allowed": "value" 20 | }, 21 | "valid": true, 22 | "set": { 23 | "useDefaultValue": true, 24 | "fixedProbabilities": true, 25 | "optionalsProbability": 1.0 26 | } 27 | }, 28 | { 29 | "description": "should not be included in with additional properties when not is true", 30 | "schema": { 31 | "$schema": "http://json-schema.org/draft-06/schema#", 32 | "type": "object", 33 | "properties": { 34 | "allowed": { 35 | "type": "string", 36 | "enum": ["value"] 37 | }, 38 | "notAllowed": { 39 | "not": true 40 | } 41 | } 42 | }, 43 | "equal": { 44 | "allowed": "value" 45 | }, 46 | "valid": false, 47 | "set": { 48 | "useDefaultValue": true, 49 | "fixedProbabilities": true, 50 | "optionalsProbability": 1.0 51 | }, 52 | "comment": "this is fine... but z-schema think is not?" 53 | } 54 | ] 55 | } 56 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-446.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "oneOf/anyOf/allOf is deleted after one item generation", 4 | "schemas": [ 5 | { 6 | "definitions": { 7 | "Element": { 8 | "anyOf": [ 9 | { 10 | "enum": [ 11 | "123" 12 | ] 13 | }, 14 | { 15 | "enum": [ 16 | "456" 17 | ] 18 | } 19 | ] 20 | } 21 | }, 22 | "items": [ 23 | { 24 | "$ref": "#/definitions/Element" 25 | }, 26 | { 27 | "$ref": "#/definitions/Element" 28 | } 29 | ] 30 | } 31 | ], 32 | "tests": [ 33 | { 34 | "description": "it will always generate two items", 35 | "schema": "schemas.0", 36 | "count": 2, 37 | "valid": true 38 | } 39 | ] 40 | } 41 | ] 42 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-453.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Example using $ref not working", 4 | "schemas": [ 5 | { 6 | "id": "otherSchema", 7 | "type": "string" 8 | } 9 | ], 10 | "tests": [ 11 | { 12 | "description": "it will eventually generate a value", 13 | "schema": { 14 | "type": "object", 15 | "properties": { 16 | "someValue": { 17 | "$ref": "otherSchema" 18 | } 19 | } 20 | }, 21 | "refs": ["schemas.0"], 22 | "valid": true 23 | } 24 | ] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-455.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "use faker or chance as object properties", 4 | "tests": [ 5 | { 6 | "description": "should allow both keywords", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "faker": { 11 | "type": "string", 12 | "format": "email" 13 | } 14 | }, 15 | "required": [ 16 | "faker" 17 | ] 18 | }, 19 | "valid": true 20 | } 21 | ] 22 | } 23 | ] 24 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-456.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Optional maxItems, minItems and maxLength doesn't work", 4 | "tests": [ 5 | { 6 | "description": "minItems/maxItems will override schema", 7 | "schema": { 8 | "type": "array", 9 | "minItems": 100, 10 | "maxItems": 200, 11 | "items": { 12 | "type": "integer" 13 | } 14 | }, 15 | "set": { 16 | "minItems": 1, 17 | "maxItems": 1 18 | }, 19 | "count": 1 20 | }, 21 | { 22 | "description": "setting maxLength should truncate schema, not override", 23 | "schema": { 24 | "type": "string", 25 | "minLength": 1, 26 | "maxLength": 1, 27 | "faker": "name.fullName" 28 | }, 29 | "require": "core/extend/faker-extend", 30 | "set": { 31 | "maxLength": 20 32 | }, 33 | "count": 1 34 | } 35 | ] 36 | } 37 | ] 38 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-458.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "when defining object with property called 'pattern'", 4 | "tests": [ 5 | { 6 | "description": "should fake all properties as expected", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "pattern": { 11 | "type": "string" 12 | } 13 | }, 14 | "required": [ 15 | "pattern" 16 | ] 17 | }, 18 | "valid": true 19 | } 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-467.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "String maxLength is ignored after 0.5.0-rc12", 3 | "tests": [ 4 | { 5 | "description": "generated strings must not exceed 10 chars", 6 | "schema": { 7 | "type": "object", 8 | "properties": { 9 | "user": { 10 | "type": "object", 11 | "properties": { 12 | "name": { 13 | "type": [ 14 | "string", 15 | "null" 16 | ], 17 | "maxLength": 10 18 | } 19 | }, 20 | "required": [ 21 | "name" 22 | ] 23 | } 24 | }, 25 | "required": [ 26 | "user" 27 | ] 28 | }, 29 | "valid": true 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-470.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Missing property 'array of object' in object", 3 | "tests": [ 4 | { 5 | "description": "xxx", 6 | "schema": { 7 | "additionalProperties": false, 8 | "properties": { 9 | "offer": { 10 | "type": "object", 11 | "properties": { 12 | "multiplier_for_durations": { 13 | "items": { 14 | "type": "object" 15 | }, 16 | "type": "array" 17 | } 18 | }, 19 | "required": [ 20 | "multiplier_for_durations" 21 | ] 22 | } 23 | }, 24 | "required": [ 25 | "offer" 26 | ], 27 | "type": "object" 28 | }, 29 | "valid": true 30 | } 31 | ] 32 | } 33 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-486.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "pattern constraints", 4 | "tests": [ 5 | { 6 | "description": "should fullfil minLength/maxLength constraints", 7 | "schema": { 8 | "type": "string", 9 | "minLength": 8, 10 | "maxLength": 20, 11 | "pattern": "^[a-zA-Z0-9_]+$" 12 | }, 13 | "valid": true 14 | }, 15 | { 16 | "description": "should sometimes fail on complex patterns", 17 | "schema": { 18 | "type": "string", 19 | "pattern": "^A[CD]{1,6}B$", 20 | "minLength": 6 21 | }, 22 | "repeat": 10, 23 | "valid": "true", 24 | "throwsSometimes": "Given sample does not match schema" 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-489.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "support consider patternProperties", 4 | "tests": [ 5 | { 6 | "description": "ensure first schema passes", 7 | "schema": { 8 | "$schema": "http://json-schema.org/draft-04/schema#", 9 | "patternProperties": { 10 | "test": { 11 | "type": "null" 12 | } 13 | }, 14 | "properties": { 15 | "test": { 16 | "title": "short description" 17 | } 18 | }, 19 | "required": ["test"] 20 | }, 21 | "valid": true 22 | }, 23 | { 24 | "description": "merge both properties definitions", 25 | "schema": { 26 | "$schema": "http://json-schema.org/draft-04/schema#", 27 | "patternProperties": { 28 | ".*_int$": { 29 | "type": "integer" 30 | } 31 | }, 32 | "properties": { 33 | "big_int": { 34 | "title": "short description", 35 | "minimum": 100 36 | }, 37 | "normal_int": { 38 | "title": "short description" 39 | }, 40 | "small_int": { 41 | "title": "short description", 42 | "maximum": 100 43 | } 44 | }, 45 | "required": [ 46 | "big_int", 47 | "normal_int", 48 | "small_int" 49 | ] 50 | }, 51 | "valid": true 52 | } 53 | ] 54 | } 55 | ] 56 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-494.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "will use alwaysFakeOptionals", 4 | "tests": [ 5 | { 6 | "description": "should work if enabled", 7 | "schema": { 8 | "account-response": { 9 | "title": "Account Response", 10 | "type": "object", 11 | "properties": { 12 | "current": { 13 | "type": "array", 14 | "items": { 15 | "$ref": "#/definitions/current-account" 16 | }, 17 | "minItems": 1 18 | }, 19 | "escrow": { 20 | "type": "array", 21 | "items": { 22 | "$ref": "#/definitions/current-account" 23 | }, 24 | "minItems": 1 25 | } 26 | }, 27 | "required": [ 28 | "current" 29 | ] 30 | }, 31 | "definitions": { 32 | "current-account": { 33 | "title": "Current Account", 34 | "type": "object", 35 | "properties": { 36 | "number": { 37 | "type": "string" 38 | }, 39 | "name": { 40 | "type": "string" 41 | }, 42 | "balance": { 43 | "type": "number" 44 | }, 45 | "currency": { 46 | "type": "string" 47 | } 48 | }, 49 | "required": [ 50 | "number", 51 | "name", 52 | "balance", 53 | "currency" 54 | ] 55 | } 56 | } 57 | }, 58 | "set": { 59 | "alwaysFakeOptionals": true 60 | }, 61 | "notEmpty": [ 62 | "account-response.current", 63 | "account-response.escrow" 64 | ], 65 | "valid": true 66 | } 67 | ] 68 | } 69 | ] 70 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-498.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "support consider patternProperties", 4 | "tests": [ 5 | { 6 | "description": "ensure first schema passes", 7 | "schema": { 8 | "required": [ 9 | "longitude" 10 | ], 11 | "type": "object", 12 | "properties": { 13 | "longitude": { 14 | "title": "Longitude", 15 | "type": "string", 16 | "format": "decimal" 17 | } 18 | } 19 | }, 20 | "set": { 21 | "failOnInvalidFormat": false 22 | } 23 | } 24 | ] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-502.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "will use alwaysFakeOptionals (regression)", 4 | "tests": [ 5 | { 6 | "description": "will fix #502", 7 | "schema": { 8 | "title": "Forum", 9 | "type": "object", 10 | "properties": { 11 | "Id": { 12 | "type": "string" 13 | }, 14 | "Topics": { 15 | "type": "array", 16 | "items": { 17 | "$ref": "#/definitions/Topic" 18 | } 19 | } 20 | }, 21 | "definitions": { 22 | "Topic": { 23 | "type": "object", 24 | "properties": { 25 | "Id": { 26 | "type": "string" 27 | }, 28 | "Posts": { 29 | "type": "array", 30 | "items": { 31 | "$ref": "#/definitions/Post" 32 | } 33 | } 34 | } 35 | }, 36 | "Post": { 37 | "type": "object", 38 | "properties": { 39 | "Id": { 40 | "type": "string" 41 | } 42 | } 43 | } 44 | } 45 | }, 46 | "valid": true 47 | } 48 | ] 49 | } 50 | ] 51 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-504.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "pattern and min/max length constraints", 4 | "tests": [ 5 | { 6 | "description": "should support minLength", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "rodo": { 11 | "type": "string" 12 | } 13 | }, 14 | "required": [ 15 | "rodo" 16 | ], 17 | "minProperties": 1, 18 | "maxProperties": 3, 19 | "additionalProperties": { 20 | "type": "boolean" 21 | } 22 | }, 23 | "valid": true 24 | } 25 | ] 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-506.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "about uniqueItems and enum", 4 | "tests": [ 5 | { 6 | "description": "should not take forever", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "test": { 11 | "type": "array", 12 | "items": { 13 | "type": "string", 14 | "enum": [ 15 | "a", 16 | "b", 17 | "c", 18 | "d", 19 | "e" 20 | ] 21 | }, 22 | "maxItems": 10, 23 | "uniqueItems": true 24 | } 25 | } 26 | }, 27 | "valid": true 28 | } 29 | ] 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-508.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "null issues", 4 | "tests": [ 5 | { 6 | "description": "should not iterate nulls", 7 | "schema": { 8 | "anyOf": [ 9 | { 10 | "type": "boolean" 11 | }, 12 | { 13 | "type": "null" 14 | } 15 | ], 16 | "default": null 17 | }, 18 | "valid": true 19 | } 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-510.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "AlwaysFakeOptionals doesn't work anymore", 4 | "schemas": [ 5 | { 6 | "type": "object", 7 | "properties": { 8 | "foo": { 9 | "type": "string" 10 | }, 11 | "bar": { 12 | "type": "string" 13 | } 14 | }, 15 | "additionalProperties": false 16 | } 17 | ], 18 | "tests": [ 19 | { 20 | "description": "make sure foo or bar are generated, optionally", 21 | "schema": "schemas.0", 22 | "valid": true 23 | } 24 | ] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-514.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "requiredOnly option being ignored", 4 | "tests": [ 5 | { 6 | "description": "should omit non-required props if enabled", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "a": { 11 | "type": "string" 12 | }, 13 | "b": { 14 | "type": "number" 15 | } 16 | }, 17 | "required": [ 18 | "a" 19 | ] 20 | }, 21 | "onlyProps": ["a"], 22 | "set": { 23 | "requiredOnly": true 24 | }, 25 | "valid": true 26 | }, 27 | { 28 | "description": "should generate randomly otherwise", 29 | "schema": { 30 | "type": "object", 31 | "additionalProperties": false, 32 | "properties": { 33 | "a": { 34 | "type": "string" 35 | }, 36 | "b": { 37 | "type": "number" 38 | }, 39 | "c": { 40 | "type": "boolean" 41 | } 42 | }, 43 | "required": [ 44 | "a" 45 | ] 46 | }, 47 | "valid": true 48 | } 49 | ] 50 | } 51 | ] 52 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-529.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "repeated properties between oneOf sub schemas", 3 | "tests": [ 4 | { 5 | "description": "should not skip required properties", 6 | "schema": { 7 | "$schema": "http://json-schema.org/draft-06/schema#", 8 | "type": "object", 9 | "required": [ 10 | "filters" 11 | ], 12 | "properties": { 13 | "filters": { 14 | "type": "array", 15 | "items": { 16 | "oneOf": [ 17 | { 18 | "$ref": "#/definitions/FilterAgc" 19 | }, 20 | { 21 | "$ref": "#/definitions/FilterSubspace" 22 | } 23 | ] 24 | } 25 | } 26 | }, 27 | "definitions": { 28 | "FilterAgc": { 29 | "type": "object", 30 | "required": [ 31 | "params" 32 | ], 33 | "properties": { 34 | "params": { 35 | "$ref": "#/definitions/FilterAgcParams" 36 | }, 37 | "enabled": { 38 | "type": "boolean" 39 | } 40 | } 41 | }, 42 | "FilterAgcParams": { 43 | "type": "object", 44 | "required": [ 45 | "window_length_seconds" 46 | ], 47 | "properties": { 48 | "window_length_seconds": { 49 | "type": "number" 50 | } 51 | } 52 | }, 53 | "FilterSubspace": { 54 | "type": "object", 55 | "required": [ 56 | "params" 57 | ], 58 | "properties": { 59 | "params": { 60 | "$ref": "#/definitions/FilterSubspaceParams" 61 | }, 62 | "enabled": { 63 | "type": "boolean" 64 | } 65 | } 66 | }, 67 | "FilterSubspaceParams": { 68 | "type": "object", 69 | "required": [ 70 | "iterations" 71 | ], 72 | "properties": { 73 | "iterations": { 74 | "type": "integer" 75 | } 76 | } 77 | } 78 | } 79 | }, 80 | "flaky": true, 81 | "valid": true 82 | } 83 | ] 84 | } 85 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-530.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "jsf.resolve() hangs with circular reference when alwaysFakeOptionals is true", 4 | "tests": [ 5 | { 6 | "description": "should resolve circular-refs now", 7 | "schema": { 8 | "type": "object", 9 | "definitions": { 10 | "collectionDef": { 11 | "additionalProperties": false, 12 | "properties": { 13 | "a": { 14 | "items": { 15 | "$ref": "#/definitions/aDef" 16 | }, 17 | "type": "array" 18 | }, 19 | "b": { 20 | "type": "string" 21 | } 22 | }, 23 | "type": "object", 24 | "required": [ 25 | "b", 26 | "a" 27 | ] 28 | }, 29 | "aDef": { 30 | "additionalProperties": true, 31 | "properties": { 32 | "subA": { 33 | "items": { 34 | "$ref": "#/definitions/aDef" 35 | }, 36 | "type": "array" 37 | }, 38 | "b": { 39 | "type": "string" 40 | } 41 | }, 42 | "type": "object" 43 | } 44 | }, 45 | "properties": { 46 | "name": { 47 | "type": "string", 48 | "faker": "name.fullName" 49 | }, 50 | "email": { 51 | "type": "string", 52 | "faker": "internet.email" 53 | }, 54 | "collection": { 55 | "$ref": "#/definitions/collectionDef" 56 | } 57 | }, 58 | "required": [ 59 | "name" 60 | ] 61 | }, 62 | "valid": true 63 | } 64 | ] 65 | } 66 | ] 67 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-539.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "out of range dates", 4 | "tests": [ 5 | { 6 | "description": "should format dates properly", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "time": { 11 | "title": "sss", 12 | "description": "zzzzzz", 13 | "type": "string", 14 | "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$", 15 | "format": "full-date" 16 | } 17 | }, 18 | "required": [ 19 | "time" 20 | ] 21 | }, 22 | "valid": true, 23 | "repeat": 100 24 | } 25 | ] 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-540.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Empty strings were causing infinite-loops", 3 | "tests": [ 4 | { 5 | "description": "should generate enough valid strings", 6 | "schema": { 7 | "comment": { 8 | "description": "Comment field", 9 | "maxLength": 254, 10 | "minLength": 1, 11 | "type": "string", 12 | "pattern": "^" 13 | } 14 | }, 15 | "equal": { 16 | "comment": "" 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-558.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "[BUG] `const` as a property", 4 | "tests": [ 5 | { 6 | "description": "should allow use const as valid property", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "const": { 11 | "type": "string", 12 | "pattern": "\\d\\w\\d\\w+" 13 | } 14 | }, 15 | "required": [ 16 | "const" 17 | ] 18 | }, 19 | "valid": true 20 | } 21 | ] 22 | } 23 | ] 24 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-559.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Change Order so that custom generate to be superior than enum", 4 | "tests": [ 5 | { 6 | "description": "make sure generators run before keywords", 7 | "schema": { 8 | "type": "integer", 9 | "enum": [1, 2, 3, 4, 5], 10 | "mock": { 11 | "mock": "@integer(1,3)" 12 | } 13 | }, 14 | "valid": true, 15 | "check": { 16 | "maximum": 3 17 | }, 18 | "require": "core/extend/mockjs-extend" 19 | } 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-565.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "anyOf issue (required props)", 3 | "tests": [ 4 | { 5 | "description": "should properly skip some props", 6 | "schema": { 7 | "type": "object", 8 | "anyOf": [ 9 | { 10 | "properties": { 11 | "a": { 12 | "type": "string" 13 | }, 14 | "b": { 15 | "type": "string" 16 | } 17 | }, 18 | "minProperties": 1, 19 | "additionalProperties": false 20 | }, 21 | { 22 | "properties": { 23 | "c": { 24 | "type": "string" 25 | } 26 | }, 27 | "required": [ 28 | "c" 29 | ], 30 | "additionalProperties": false 31 | } 32 | ] 33 | }, 34 | "valid": true 35 | } 36 | ] 37 | } 38 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-567.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "Unexpected behavior for allOf", 3 | "tests": [ 4 | { 5 | "description": "should combine subschemas from given items", 6 | "schema": { 7 | "allOf": [ 8 | { 9 | "type": "array", 10 | "items": [ 11 | { 12 | "type": "integer", 13 | "minimum": 3 14 | }, 15 | { 16 | "type": "integer", 17 | "minimum": 3 18 | } 19 | ], 20 | "additionalItems": false 21 | }, 22 | { 23 | "type": "array", 24 | "items": [ 25 | { 26 | "type": "integer", 27 | "maximum": 10 28 | }, 29 | { 30 | "type": "integer", 31 | "maximum": 10 32 | } 33 | ], 34 | "additionalItems": false 35 | } 36 | ] 37 | }, 38 | "valid": true, 39 | "set": { 40 | "useDefaultValue": true, 41 | "fixedProbabilities": true, 42 | "optionalsProbability": 1.0 43 | } 44 | } 45 | ] 46 | } 47 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-568.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "ignore nulls if asked", 3 | "tests": [ 4 | { 5 | "description": "should remove null values when omitNulls is enabled", 6 | "schema": { 7 | "type": "object", 8 | "properties": { 9 | "value": { 10 | "type": ["string", "null"] 11 | } 12 | } 13 | }, 14 | "set": { 15 | "omitNulls": true 16 | }, 17 | "hasNot": ":null", 18 | "valid": true 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-569.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Required properties that result in empty objects get removed", 4 | "tests": [ 5 | { 6 | "description": "should eventually generate some props", 7 | "schema": { 8 | "additionalProperties": false, 9 | "type": "object", 10 | "properties": { 11 | "things": { 12 | "type": "object", 13 | "additionalProperties": { 14 | "type": "string" 15 | } 16 | } 17 | }, 18 | "required": [ 19 | "things" 20 | ] 21 | }, 22 | "valid": true 23 | } 24 | ] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-57.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "mixin issues with allOf", 4 | "tests": [ 5 | { 6 | "description": "should get combined as expected", 7 | "schema": { 8 | "definitions": { 9 | "address": { 10 | "type": "object", 11 | "properties": { 12 | "street_address": { "type": "string" }, 13 | "city": { "type": "string" }, 14 | "state": { "type": "string" } 15 | }, 16 | "required": ["street_address", "city", "state"] 17 | } 18 | }, 19 | "type": "object", 20 | "properties": { 21 | "billing_address": { "$ref": "#/definitions/address" }, 22 | "shipping_address": { 23 | "allOf": [ 24 | { "$ref": "#/definitions/address" }, 25 | { "properties": 26 | { "type": { "enum": [ "residential", "business" ] } }, 27 | "required": ["type"] 28 | } 29 | ] 30 | } 31 | } 32 | }, 33 | "valid": true 34 | } 35 | ] 36 | } 37 | ] 38 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-571.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "External file $refs not resolving", 4 | "tests": [ 5 | { 6 | "description": "make sure external file $ref does not cause an error", 7 | "schema": { 8 | "properties": { 9 | "person": { 10 | "$ref": "./tests/external-ref-files/issue-571-external-ref.json#/definitions/externalExample" 11 | } 12 | }, 13 | "type": "object" 14 | }, 15 | "valid": true 16 | } 17 | ] 18 | } 19 | ] 20 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-584.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Maximum call stack size & refDepthMax not work", 4 | "tests": [ 5 | { 6 | "description": "should create items recursively", 7 | "schema": { 8 | "$ref": "#/definitions/A", 9 | "definitions": { 10 | "A": { 11 | "type": "object", 12 | "additionalProperties": false, 13 | "properties": { 14 | "nodeA": { 15 | "type": "array", 16 | "items": { 17 | "$ref": "#/definitions/A" 18 | } 19 | }, 20 | "nodeB": { 21 | "$ref": "#/definitions/B" 22 | } 23 | } 24 | }, 25 | "B": { 26 | "type": "object", 27 | "additionalProperties": false, 28 | "properties": { 29 | "nodeB": { 30 | "type": "array", 31 | "items": { 32 | "$ref": "#/definitions/B" 33 | } 34 | } 35 | } 36 | } 37 | } 38 | }, 39 | "repeat": 50, 40 | "valid": true 41 | } 42 | ] 43 | } 44 | ] 45 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-585.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Support 'content' for arrays", 4 | "tests": [ 5 | { 6 | "description": "should handle content with empty array", 7 | "schema": { 8 | "type": "array", 9 | "minItems": 0, 10 | "maxItems": 0, 11 | "items": { 12 | "type": "integer" 13 | }, 14 | "contains": { 15 | "const": 42 16 | } 17 | }, 18 | "valid": false 19 | }, 20 | { 21 | "description": "should handle content with single item array", 22 | "schema": { 23 | "type": "array", 24 | "items": { 25 | "type": "integer" 26 | }, 27 | "minItems": 1, 28 | "maxItems": 1, 29 | "contains": { 30 | "const": 42 31 | } 32 | }, 33 | "equal": [42] 34 | }, 35 | { 36 | "description": "should handle content with any array length", 37 | "schema": { 38 | "type": "array", 39 | "items": { 40 | "type": "integer" 41 | }, 42 | "minItems": 2, 43 | "maxItems": 10, 44 | "contains": { 45 | "const": 42 46 | } 47 | }, 48 | "repeat": 10, 49 | "valid": true 50 | } 51 | ] 52 | } 53 | ] 54 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-587.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Clean shouldn't remove empty objects that are required to satisfy constraints", 4 | "tests": [ 5 | { 6 | "description": "handle minItems", 7 | "schema": { 8 | "id": "Profile", 9 | "type": "object", 10 | "properties": { 11 | "firstName": { 12 | "type": "array", 13 | "minItems": 1, 14 | "items": { 15 | "type": "object", 16 | "properties": { 17 | "bar": { 18 | "type": "object", 19 | "properties": {} 20 | } 21 | }, 22 | "additionalProperties": false 23 | } 24 | } 25 | }, 26 | "additionalProperties": false, 27 | "required": [ 28 | "firstName" 29 | ] 30 | }, 31 | "hasProps": [ 32 | "firstName.0.bar" 33 | ], 34 | "repeat": 50, 35 | "valid": true 36 | } 37 | ] 38 | } 39 | ] 40 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-601.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Generation of two required properties based on the same enum reference type", 4 | "tests": [ 5 | { 6 | "description": "make sure required properties based on the same enum reference type are always generated", 7 | "schema": { 8 | "type": "object", 9 | "additionalProperties": false, 10 | "properties": { 11 | "property1": { 12 | "$ref": "#/definitions/Enum" 13 | }, 14 | "property2": { 15 | "$ref": "#/definitions/Enum" 16 | } 17 | }, 18 | "definitions": { 19 | "Enum": { 20 | "type": "integer", 21 | "description": "", 22 | "enum": [ 23 | 1 24 | ] 25 | } 26 | } 27 | }, 28 | "repeat": 100, 29 | "valid": true 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-603.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Fields missing when using 'allOf' inside 'definitions'", 4 | "tests": [ 5 | { 6 | "description": "should eventually generate missing props", 7 | "schema": { 8 | "allOf": [ 9 | { 10 | "properties": { 11 | "a": { 12 | "type": "string" 13 | } 14 | }, 15 | "required": [ 16 | "a" 17 | ] 18 | }, 19 | { 20 | "$ref": "#/definitions/foo" 21 | }, 22 | { 23 | "$ref": "#/definitions/bar" 24 | } 25 | ], 26 | "definitions": { 27 | "foo": { 28 | "allOf": [ 29 | { 30 | "properties": { 31 | "b": { 32 | "type": "string" 33 | } 34 | }, 35 | "required": [ 36 | "b" 37 | ] 38 | }, 39 | { 40 | "properties": { 41 | "c": { 42 | "type": "string" 43 | } 44 | }, 45 | "required": [ 46 | "c" 47 | ] 48 | } 49 | ] 50 | }, 51 | "bar": { 52 | "properties": { 53 | "d": { 54 | "type": "string" 55 | } 56 | }, 57 | "required": [ 58 | "d" 59 | ] 60 | } 61 | } 62 | }, 63 | "valid": true 64 | } 65 | ] 66 | } 67 | ] 68 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-620.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Fix again min and maxItem generation", 4 | "tests": [ 5 | { 6 | "description": "minItems is a valid boundary if set to zero", 7 | "schema": { 8 | "type": "array", 9 | "items": { 10 | "type": "integer", 11 | "default": 1 12 | }, 13 | "minItems": 0, 14 | "maxItems": 5 15 | }, 16 | "repeat": 100, 17 | "valid": true, 18 | "set": { 19 | "minItems": 7, 20 | "maxItems": 7, 21 | "useDefaultValue": true 22 | }, 23 | "lessThan": 6 24 | }, 25 | { 26 | "description": "ignore minItems and maxItems if already set", 27 | "schema": { 28 | "type": "array", 29 | "items": { 30 | "type": "integer", 31 | "default": 1 32 | }, 33 | "minItems": 3, 34 | "maxItems": 5 35 | }, 36 | "repeat": 100, 37 | "valid": true, 38 | "set": { 39 | "maxItems": 7, 40 | "useDefaultValue": true 41 | }, 42 | "atLeast": 3 43 | }, 44 | { 45 | "description": "set minItems and/or maxItems if they are not defined", 46 | "schema": { 47 | "type": "array", 48 | "items": { 49 | "type": "integer", 50 | "default": 1 51 | } 52 | }, 53 | "repeat": 100, 54 | "valid": true, 55 | "set": { 56 | "minItems": 7, 57 | "maxItems": 7, 58 | "useDefaultValue": true 59 | }, 60 | "length": 7 61 | } 62 | ] 63 | } 64 | ] 65 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-622.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "mixing minProperties / maxProperties with required", 4 | "tests": [ 5 | { 6 | "description": "should generate no more than all props", 7 | "schema": { 8 | "type": "object", 9 | "required": [ 10 | "val1" 11 | ], 12 | "minProperties": 1, 13 | "maxProperties": 1, 14 | "properties": { 15 | "val1": { 16 | "type": "string" 17 | }, 18 | "val2": { 19 | "type": "string" 20 | } 21 | } 22 | }, 23 | "valid": true, 24 | "repeat": 100 25 | } 26 | ] 27 | } 28 | ] 29 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-624.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "required properties based on the same reference type aren't generated with top ref", 4 | "tests": [ 5 | { 6 | "description": "should generate all values as expected", 7 | "schema": { 8 | "$schema": "http://json-schema.org/draft-07/schema#", 9 | "$ref": "#/definitions/Obj", 10 | "definitions": { 11 | "Obj": { 12 | "type": "object", 13 | "properties": { 14 | "time1": { 15 | "$ref": "#/definitions/DateTimeString" 16 | }, 17 | "time2": { 18 | "$ref": "#/definitions/DateTimeString" 19 | } 20 | }, 21 | "required": [ 22 | "time1", 23 | "time2" 24 | ], 25 | "additionalProperties": false 26 | }, 27 | "DateTimeString": { 28 | "type": "string", 29 | "format": "date" 30 | } 31 | } 32 | }, 33 | "valid": true, 34 | "repeat": 100 35 | } 36 | ] 37 | } 38 | ] 39 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-625.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "unexpected `allOf` behavior with pointer and minProperties", 4 | "schemas": [ 5 | { 6 | "$schema": "http://json-schema.org/draft-07/schema#", 7 | "type": "object", 8 | "properties": { 9 | "countries": { "$ref": "#/definitions/countries" }, 10 | "countries_priority": { 11 | "allOf": [ 12 | { "$ref": "#/definitions/countries" }, 13 | { "maxProperties": 3 } 14 | ] 15 | } 16 | }, 17 | "required": [ 18 | "countries", 19 | "countries_priority" 20 | ], 21 | "additionalProperties": false, 22 | "definitions": { 23 | "countries": { 24 | "type": "object", 25 | "properties": { 26 | "AL": { "enum": ["Albania"] }, 27 | "CA": { "enum": ["Canada"] }, 28 | "KY": { "enum": ["Cayman Islands"] }, 29 | "MR": { "enum": ["Mauritania"] }, 30 | "YT": { "enum": ["Mayotte"] }, 31 | "VI": { "enum": ["U.S. Virgin Islands"] }, 32 | "GB": { "enum": ["United Kingdom"] }, 33 | "US": { "enum": ["United States"] }, 34 | "UY": { "enum": ["Uruguay"] } 35 | }, 36 | "required": ["US", "CA"], 37 | "additionalProperties": false 38 | } 39 | } 40 | } 41 | ], 42 | "tests": [ 43 | { 44 | "description": "should generate an object with either 2 or 3 properties with `alwaysFakeOptionals: false`", 45 | "set": { "alwaysFakeOptionals": false }, 46 | "schema": "schemas.0", 47 | "valid": true, 48 | "repeat": 100 49 | }, 50 | { 51 | "description": "should generate exactly 3 properties with `alwaysFakeOptionals: true`", 52 | "set": { "alwaysFakeOptionals": true }, 53 | "schema": "schemas.0", 54 | "valid": true, 55 | "repeat": 100 56 | } 57 | ] 58 | } 59 | ] 60 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-635.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Include proper type check for values returned from custom functions", 4 | "tests": [ 5 | { 6 | "description": "should handle null", 7 | "schema": { 8 | "type": ["string", "null"], 9 | "faker": { 10 | "custom.returnThisValue": [null] 11 | } 12 | }, 13 | "equal": null, 14 | "require": "core/extend/faker-extend", 15 | "seed": 0.9999999999999999 16 | }, 17 | { 18 | "description": "should handle string", 19 | "schema": { 20 | "type": ["string", "null"], 21 | "faker": { 22 | "custom.returnThisValue": ["something"] 23 | } 24 | }, 25 | "equal": "something", 26 | "require": "core/extend/faker-extend", 27 | "seed": 0.0000000000000001 28 | } 29 | ] 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-642.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "High order formatters, e.g. faker + format", 4 | "tests": [ 5 | { 6 | "description": "format can be applied after any generator", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "aDate": { 11 | "type": "string", 12 | "faker": "date.past", 13 | "format": "date" 14 | } 15 | }, 16 | "required": [ 17 | "aDate" 18 | ] 19 | }, 20 | "valid": true, 21 | "require": "core/extend/faker-extend" 22 | } 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-644.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "using JSON pointers in external $ref", 4 | "tests": [ 5 | { 6 | "description": "should resolve from remote definitions", 7 | "schema": { 8 | "$schema": "http://json-schema.org/draft-04/schema#", 9 | "title": "Static Analysis Results Format (SARIF) Version 2.1.0-rtm.5 address fragment", 10 | "id": "https://sarif/address-fragment.json", 11 | "description": "A dynamic fragment of a SARIF schema.", 12 | "allOf": [ 13 | { 14 | "$ref": "https://raw.githubusercontent.com/schemastore/schemastore/master/src/schemas/json/sarif-2.1.0-rtm.5.json#/definitions/address" 15 | } 16 | ] 17 | }, 18 | "valid": true 19 | } 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-687.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "root-definitions on sync mode", 4 | "tests": [ 5 | { 6 | "description": "should resolve local definitions", 7 | "schema": { 8 | "definitions": { 9 | "foo": { 10 | "type": "object", 11 | "properties": { 12 | "bar": { 13 | "type": "string" 14 | } 15 | } 16 | } 17 | }, 18 | "$ref": "#/definitions/foo" 19 | }, 20 | "sync": true, 21 | "valid": true 22 | } 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-693.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "Generators should respect random type selection", 4 | "tests": [ 5 | { 6 | "description": "always return generator value when same type is randomly selected", 7 | "schema": { 8 | "type": [ 9 | "string", 10 | "null" 11 | ], 12 | "faker": "name.firstName" 13 | }, 14 | "seed": 0.0000000000000001, 15 | "type": "string" 16 | }, 17 | { 18 | "description": "never return generator value when different type is randomly selected", 19 | "schema": { 20 | "type": [ 21 | "string", 22 | "null" 23 | ], 24 | "faker": "name.firstName" 25 | }, 26 | "seed": 0.9999999999999999, 27 | "equal": null 28 | } 29 | ] 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-713.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "enum and oneOf will generate NaN", 4 | "tests": [ 5 | { 6 | "description": "should ignore schema.type if enum is used", 7 | "schema": { 8 | "properties": { 9 | "value": { 10 | "enum": [ 11 | "Int", 12 | 1, 13 | "String", 14 | 2, 15 | "Float", 16 | 3, 17 | "Boolean", 18 | 4 19 | ], 20 | "oneOf": [ 21 | { 22 | "type": "string" 23 | }, 24 | { 25 | "type": "integer" 26 | } 27 | ] 28 | } 29 | }, 30 | "required": [ 31 | "value" 32 | ], 33 | "additionalProperties": false 34 | }, 35 | "valid": true 36 | } 37 | ] 38 | } 39 | ] 40 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-715.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "$defs names with spaces cause 'Prop not found'", 4 | "tests": [ 5 | { 6 | "description": "will fix #710", 7 | "schema": { 8 | "$defs": { 9 | "Def with Spaces": { 10 | "type": "string" 11 | } 12 | }, 13 | "$id": "https://test.json", 14 | "$schema": "http://json-schema.org/draft-07/schema#", 15 | "properties": { 16 | "SomeProp": { 17 | "$ref": "#/$defs/Def with Spaces" 18 | } 19 | }, 20 | "required": [ 21 | "SomeProp" 22 | ], 23 | "type": "object" 24 | }, 25 | "valid": true 26 | } 27 | ] 28 | } 29 | ] 30 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-747.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "empty objects should be preserved if required", 4 | "tests": [ 5 | { 6 | "description": "ensure we have empty objects", 7 | "schema": { 8 | "properties": { 9 | "foo": { 10 | "items": { 11 | "properties": { 12 | "bar": { 13 | "type": "null" 14 | }, 15 | "baz": { 16 | "properties": { 17 | "quux": { 18 | "type": "string" 19 | }, 20 | "corge": { 21 | "type": "number" 22 | } 23 | }, 24 | "required": [], 25 | "type": "object", 26 | "additionalProperties": false 27 | } 28 | }, 29 | "required": [ 30 | "bar", 31 | "baz" 32 | ], 33 | "type": "object" 34 | }, 35 | "minItems": 1, 36 | "type": "array" 37 | } 38 | }, 39 | "required": [ 40 | "foo" 41 | ], 42 | "type": "object" 43 | }, 44 | "equal": { 45 | "foo": [ 46 | { 47 | "bar": null, 48 | "baz": {} 49 | } 50 | ] 51 | }, 52 | "valid": true, 53 | "seed": 0.00123, 54 | "omit": ["z-schema"] 55 | } 56 | ] 57 | } 58 | ] 59 | -------------------------------------------------------------------------------- /tests/schema/core/issues/issue-749.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "generate the current type when use alwaysFakeOptionals true and additionalProperties option", 4 | "tests": [ 5 | { 6 | "description": "should generate current type", 7 | "schema": { 8 | "properties": { 9 | "fields": { 10 | "type": "object", 11 | "additionalProperties": { 12 | "type": "string" 13 | } 14 | } 15 | } 16 | }, 17 | "valid": true, 18 | "random": "some seed", 19 | "set": { 20 | "alwaysFakeOptionals": true 21 | } 22 | } 23 | ] 24 | } 25 | ] 26 | -------------------------------------------------------------------------------- /tests/schema/core/issues/nested-refs.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "nested $refs", 3 | "tests": [ 4 | { 5 | "description": "should follow nested $refs in synchronous mode", 6 | "sync": true, 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "hello": { 11 | "$ref": "#/definitions/middle" 12 | } 13 | }, 14 | "required": ["hello"], 15 | "definitions": { 16 | "middle": { 17 | "$ref": "#/definitions/world" 18 | }, 19 | "world": { 20 | "type": "string", 21 | "const": "world!" 22 | } 23 | } 24 | }, 25 | "equal": { 26 | "hello": "world!" 27 | } 28 | } 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /tests/schema/core/issues/number-min-greater-than-max.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "number from an invalid range (min > max)", 4 | "tests": [ 5 | { 6 | "description": "should return NaN", 7 | "schema": { 8 | "type": "integer", 9 | "minimum": 600, 10 | "maximum": 500 11 | }, 12 | "valid": false 13 | }, 14 | { 15 | "description": "should return NaN", 16 | "schema": { 17 | "type": "integer", 18 | "minimum": 600, 19 | "maximum": 500, 20 | "multipleOf": 7 21 | }, 22 | "valid": false 23 | } 24 | ] 25 | } 26 | ] 27 | -------------------------------------------------------------------------------- /tests/schema/core/issues/number-min-max.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "generated number obeying min/max, 6 times to account for random test pass", 4 | "tests": [ 5 | { 6 | "description": "should handle one possible value min/max number", 7 | "schema": { 8 | "type": "number", 9 | "minimum": 1, 10 | "maximum": 1 11 | }, 12 | "hasNot": ".", 13 | "type": "number", 14 | "valid": true 15 | }, 16 | { 17 | "description": "should handle one possible value min/max number", 18 | "schema": { 19 | "type": "number", 20 | "minimum": 1, 21 | "maximum": 1 22 | }, 23 | "hasNot": ".", 24 | "type": "number", 25 | "valid": true 26 | }, 27 | { 28 | "description": "should handle one possible value min/max number", 29 | "schema": { 30 | "type": "number", 31 | "minimum": 1, 32 | "maximum": 1 33 | }, 34 | "hasNot": ".", 35 | "type": "number", 36 | "valid": true 37 | }, 38 | { 39 | "description": "should handle one possible value min/max number", 40 | "schema": { 41 | "type": "number", 42 | "minimum": 1, 43 | "maximum": 1 44 | }, 45 | "hasNot": ".", 46 | "type": "number", 47 | "valid": true 48 | }, 49 | { 50 | "description": "should handle one possible value min/max number", 51 | "schema": { 52 | "type": "number", 53 | "minimum": 1, 54 | "maximum": 1 55 | }, 56 | "hasNot": ".", 57 | "type": "number", 58 | "valid": true 59 | }, 60 | { 61 | "description": "should handle one possible value min/max number", 62 | "schema": { 63 | "type": "number", 64 | "minimum": 1, 65 | "maximum": 1 66 | }, 67 | "hasNot": ".", 68 | "type": "number", 69 | "valid": true 70 | } 71 | ] 72 | } 73 | ] 74 | -------------------------------------------------------------------------------- /tests/schema/core/issues/reserved.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "reserved words", 4 | "tests": [ 5 | { 6 | "description": "should allow type-keyword", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "type": { 11 | "type": "string" 12 | } 13 | }, 14 | "required": ["type"] 15 | }, 16 | "valid": true 17 | }, 18 | { 19 | "description": "should allow enum-keyword", 20 | "schema": { 21 | "type": "object", 22 | "properties": { 23 | "enum": { 24 | "type": "boolean" 25 | } 26 | }, 27 | "required": ["enum"] 28 | }, 29 | "valid": true 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /tests/schema/core/jsonpath.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "jsonpath support", 4 | "tests": [ 5 | { 6 | "description": "should enable jsonPath queries", 7 | "schema": { 8 | "test": { 9 | "type": "object", 10 | "properties": { 11 | "value": { 12 | "jsonPath": "$.foo.bar.baz" 13 | } 14 | }, 15 | "required": ["value"] 16 | }, 17 | "foo": { 18 | "bar": { 19 | "baz": "buzz" 20 | } 21 | } 22 | }, 23 | "equal": { 24 | "test": { 25 | "value": "buzz" 26 | }, 27 | "foo": { 28 | "bar": { 29 | "baz": "buzz" 30 | } 31 | } 32 | }, 33 | "set": { 34 | "resolveJsonPath": true 35 | } 36 | } 37 | ] 38 | } 39 | ] 40 | -------------------------------------------------------------------------------- /tests/schema/core/keywords.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "instance keywords", 4 | "tests": [ 5 | { 6 | "description": "should handle array of types", 7 | "schema": { 8 | "type": ["string", "integer"] 9 | }, 10 | "valid": true 11 | }, 12 | { 13 | "description": "should handle enum values", 14 | "schema": { 15 | "enum": ["", [], {}, false, null, -1] 16 | }, 17 | "valid": true 18 | }, 19 | { 20 | "description": "should handle allOf values", 21 | "schema": { 22 | "allOf": [ 23 | { 24 | "type": "string" 25 | }, 26 | { 27 | "enum": ["a", "value"] 28 | } 29 | ] 30 | }, 31 | "valid": true 32 | }, 33 | { 34 | "description": "should handle anyof values", 35 | "schema": { 36 | "anyOf": [ 37 | { 38 | "type": "integer" 39 | }, 40 | { 41 | "type": "array" 42 | } 43 | ] 44 | }, 45 | "valid": true 46 | }, 47 | { 48 | "description": "should handle oneOf values", 49 | "schema": { 50 | "oneOf": [ 51 | { 52 | "type": "boolean" 53 | }, 54 | { 55 | "type": "null" 56 | } 57 | ] 58 | }, 59 | "valid": true 60 | } 61 | ] 62 | } 63 | ] 64 | -------------------------------------------------------------------------------- /tests/schema/core/option/alwaysFakeOptionals.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "alwaysFakeOptionals option", 4 | "tests": [ 5 | { 6 | "description": "should handle alwaysFakeOptionals option (= true) for objects", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "optionalProperty1": { "type": "number", "default": 1 }, 11 | "optionalProperty2": { "type": "number", "default": 1 }, 12 | "optionalProperty3": { "type": "number", "default": 1 }, 13 | "optionalProperty4": { "type": "number", "default": 1 }, 14 | "optionalProperty5": { "type": "number", "default": 1 } 15 | } 16 | }, 17 | "valid": true, 18 | "equal": { 19 | "optionalProperty1": 1, 20 | "optionalProperty2": 1, 21 | "optionalProperty3": 1, 22 | "optionalProperty4": 1, 23 | "optionalProperty5": 1 24 | }, 25 | "set": { 26 | "useDefaultValue": true, 27 | "fixedProbabilities": true, 28 | "alwaysFakeOptionals": true 29 | } 30 | }, 31 | { 32 | "description": "should handle alwaysFakeOptionals option (= true) for arrays", 33 | "schema": { 34 | "type": "array", 35 | "items": { 36 | "type": "string", 37 | "enum": ["a"] 38 | }, 39 | "maxItems": 5, 40 | "minItems": 0 41 | }, 42 | "valid": true, 43 | "equal": ["a", "a", "a", "a", "a"], 44 | "set": { 45 | "useDefaultValue": true, 46 | "fixedProbabilities": true, 47 | "alwaysFakeOptionals": true 48 | } 49 | } 50 | ] 51 | } 52 | ] 53 | -------------------------------------------------------------------------------- /tests/schema/core/option/alwaysFakeOptionalsNoAdditional.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "alwaysFakeOptionals option with additionalProperties: false", 4 | "tests": [ 5 | { 6 | "description": "should handle alwaysFakeOptionals option (= true) for objects", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "optionalProperty1": { "type": "number", "default": 1 }, 11 | "optionalProperty2": { "type": "number", "default": 1 }, 12 | "optionalProperty3": { "type": "number", "default": 1 }, 13 | "optionalProperty4": { "type": "number", "default": 1 }, 14 | "optionalProperty5": { "type": "number", "default": 1 } 15 | }, 16 | "additionalProperties": false 17 | }, 18 | "valid": true, 19 | "equal": { 20 | "optionalProperty1": 1, 21 | "optionalProperty2": 1, 22 | "optionalProperty3": 1, 23 | "optionalProperty4": 1, 24 | "optionalProperty5": 1 25 | }, 26 | "set": { 27 | "alwaysFakeOptionals": true, 28 | "useDefaultValue": true 29 | } 30 | } 31 | ] 32 | } 33 | ] 34 | -------------------------------------------------------------------------------- /tests/schema/core/option/defaultInvalidTypeProduct.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "defaultInvalidTypeProduct option (requires failOnInvalidTypes=false)", 4 | "tests": [ 5 | { 6 | "description": "should return static values if they are not well-known strings", 7 | "schema": { 8 | "type": "undef" 9 | }, 10 | "equal": -1, 11 | "set": { 12 | "failOnInvalidTypes": false, 13 | "defaultInvalidTypeProduct": -1 14 | } 15 | }, 16 | { 17 | "description": "should generate values if they are well-known strings", 18 | "schema": { 19 | "type": "undef" 20 | }, 21 | "equal": false, 22 | "seed": 0.01, 23 | "set": { 24 | "failOnInvalidTypes": false, 25 | "defaultInvalidTypeProduct": "boolean" 26 | } 27 | } 28 | ] 29 | } 30 | ] 31 | -------------------------------------------------------------------------------- /tests/schema/core/option/failOnInvalidType.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "failOnInvalidType option", 4 | "tests": [ 5 | { 6 | "description": "should handle failOnInvalidType option", 7 | "schema": { 8 | "type": "nonExistentType" 9 | }, 10 | "valid": false, 11 | "set": { 12 | "failOnInvalidTypes": false 13 | } 14 | } 15 | ] 16 | } 17 | ] 18 | -------------------------------------------------------------------------------- /tests/schema/core/option/falsy-defaults.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "falsy defaults", 4 | "tests": [ 5 | { 6 | "description": "boolean can be false", 7 | "schema": { 8 | "type": "boolean", 9 | "default": false 10 | }, 11 | "equal": false, 12 | "set": { 13 | "useDefaultValue": true 14 | } 15 | }, 16 | { 17 | "description": "number can be 0", 18 | "schema": { 19 | "type": "number", 20 | "default": 0 21 | }, 22 | "equal": 0, 23 | "set": { 24 | "useDefaultValue": true 25 | } 26 | }, 27 | { 28 | "description": "integer can be 0", 29 | "schema": { 30 | "type": "integer", 31 | "default": 0 32 | }, 33 | "equal": 0, 34 | "set": { 35 | "useDefaultValue": true 36 | } 37 | }, 38 | { 39 | "description": "string can be empty", 40 | "schema": { 41 | "type": "string", 42 | "default": "" 43 | }, 44 | "equal": "", 45 | "set": { 46 | "useDefaultValue": true 47 | } 48 | }, 49 | { 50 | "description": "objects can be null", 51 | "schema": { 52 | "type": "object", 53 | "default": null 54 | }, 55 | "equal": null, 56 | "set": { 57 | "useDefaultValue": true 58 | } 59 | }, 60 | { 61 | "description": "array of booleans all being false", 62 | "schema": { 63 | "type": "array", 64 | "minItems": 5, 65 | "maxItems": 5, 66 | "items": { 67 | "type": "boolean", 68 | "default": false 69 | } 70 | }, 71 | "equal": [ false, false, false, false, false ], 72 | "set": { 73 | "useDefaultValue": true 74 | } 75 | } 76 | ] 77 | } 78 | ] 79 | -------------------------------------------------------------------------------- /tests/schema/core/option/ignoreProperties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "ignoreProperties option", 4 | "tests": [ 5 | { 6 | "description": "should skip generating from ignoreProperties", 7 | "schema": { 8 | "properties": { 9 | "id": { 10 | "type": "integer" 11 | }, 12 | "key": { 13 | "type": "string" 14 | }, 15 | "foo": { 16 | "enum": ["bar", "baz"] 17 | }, 18 | "bar": { 19 | "type": "boolean" 20 | }, 21 | "buzz": { 22 | "type": "array" 23 | }, 24 | "truth": { 25 | "default": 42 26 | } 27 | }, 28 | "required": [ 29 | "id", 30 | "key", 31 | "foo", 32 | "bar", 33 | "buzz", 34 | "truth" 35 | ] 36 | }, 37 | "onlyProps": ["id", "key"], 38 | "require": "core/option/ignoreProperties" 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /tests/schema/core/option/ignoreProperties.mjs: -------------------------------------------------------------------------------- 1 | export function register(jsf) { 2 | return jsf.option({ 3 | fillProperties: false, 4 | ignoreProperties: ['foo', /^b/, x => x.default === 42], 5 | }); 6 | } 7 | -------------------------------------------------------------------------------- /tests/schema/core/option/minMaxDateTime.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "random option", 4 | "tests": [ 5 | { 6 | "description": "should allow to set min and max values for date-time", 7 | "schema": { 8 | "type": "string", 9 | "format": "date-time" 10 | }, 11 | "valid": true, 12 | "equal": "2017-04-19T01:01:01.0Z", 13 | "set": { 14 | "minDateTime": "1977-11-22", 15 | "maxDateTime": "2017-04-19" 16 | }, 17 | "repeat": 1, 18 | "seed": 1 19 | } 20 | ] 21 | }, 22 | { 23 | "description": "random option", 24 | "tests": [ 25 | { 26 | "description": "should allow to set min and max values for date-time", 27 | "schema": { 28 | "type": "string", 29 | "format": "date-time" 30 | }, 31 | "valid": true, 32 | "equal": "2000-02-04T01:01:01.0Z", 33 | "set": { 34 | "minDateTime": "2000-02-03", 35 | "maxDateTime": "2000-02-05" 36 | }, 37 | "repeat": 1, 38 | "seed": 0.5 39 | } 40 | ] 41 | } 42 | ] 43 | -------------------------------------------------------------------------------- /tests/schema/core/option/pruneProperties.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "pruneProperties option", 4 | "tests": [ 5 | { 6 | "description": "should remove nested keys from pruneProperties", 7 | "schema": { 8 | "properties": { 9 | "test": { 10 | "nestedProp": { 11 | "foo": "bar" 12 | }, 13 | "otherProp": true 14 | } 15 | }, 16 | "required": [ 17 | "test" 18 | ] 19 | }, 20 | "equal": { "test": {} }, 21 | "set": { 22 | "pruneProperties": ["nestedProp", "otherProp"] 23 | } 24 | } 25 | ] 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /tests/schema/core/option/random.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "random option", 4 | "tests": [ 5 | { 6 | "description": "should allow pseudorandom value generation", 7 | "schema": { 8 | "type": "object", 9 | "properties": { 10 | "a": { 11 | "type": "integer", 12 | "minimum": 0, 13 | "maximum": 100 14 | }, 15 | "b": { 16 | "type": "string" 17 | }, 18 | "c": { 19 | "pattern": "^[a-z]{2}[0-9]{3}$" 20 | } 21 | }, 22 | "required": ["a", "b", "c"] 23 | }, 24 | "valid": true, 25 | "equal": { 26 | "a": 44, 27 | "b": "in culpa proident amet", 28 | "c": "fe228" 29 | }, 30 | "repeat": 1, 31 | "random": "some seed" 32 | } 33 | ] 34 | } 35 | ] 36 | -------------------------------------------------------------------------------- /tests/schema/core/option/useDefaultValue.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "useDefaultValue option", 4 | "tests": [ 5 | { 6 | "description": "should handle useDefaultValue option", 7 | "schema": { 8 | "type": "string", 9 | "default": "Hello" 10 | }, 11 | "equal": "Hello", 12 | "set": { 13 | "useDefaultValue": true 14 | } 15 | }, 16 | { 17 | "description": "should handle useDefaultValue option with an empty default value", 18 | "schema": { 19 | "type": "string", 20 | "default": "" 21 | }, 22 | "equal": "", 23 | "set": { 24 | "useDefaultValue": true 25 | } 26 | }, 27 | { 28 | "description": "should handle useDefaultValue & replaceEmptyByRandomValue option", 29 | "schema": { 30 | "test-response": { 31 | "type": "string", 32 | "default": "" 33 | } 34 | }, 35 | "valid": true, 36 | "notEmpty": ["test-response"], 37 | "set": { 38 | "useDefaultValue": true, 39 | "replaceEmptyByRandomValue": true 40 | } 41 | } 42 | ] 43 | } 44 | ] 45 | -------------------------------------------------------------------------------- /tests/schema/core/option/useExamplesValue.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "useExamplesValue option", 4 | "tests": [ 5 | { 6 | "description": "should handle useExamplesValue option with 'examples' array", 7 | "schema": { 8 | "type": "string", 9 | "examples": [ 10 | "World" 11 | ] 12 | }, 13 | "equal": "World", 14 | "set": { 15 | "useExamplesValue": true 16 | } 17 | }, 18 | { 19 | "description": "should handle useExamplesValue option with 'example' property", 20 | "schema": { 21 | "type": "string", 22 | "example": "World" 23 | }, 24 | "equal": "World", 25 | "set": { 26 | "useExamplesValue": true 27 | } 28 | } 29 | ] 30 | } 31 | ] 32 | -------------------------------------------------------------------------------- /tests/schema/core/primitives.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "primitive values", 4 | "tests": [ 5 | { 6 | "description": "should generate arrays", 7 | "schema": { 8 | "type": "array" 9 | }, 10 | "type": "array", 11 | "valid": true 12 | }, 13 | { 14 | "description": "should generate booleans", 15 | "schema": { 16 | "type": "boolean" 17 | }, 18 | "type": "boolean", 19 | "valid": true 20 | }, 21 | { 22 | "description": "should generate integers", 23 | "schema": { 24 | "type": "integer" 25 | }, 26 | "type": "number", 27 | "valid": true 28 | }, 29 | { 30 | "description": "should generate numbers", 31 | "schema": { 32 | "type": "number" 33 | }, 34 | "type": "number", 35 | "valid": true 36 | }, 37 | { 38 | "description": "should generate nulls", 39 | "schema": { 40 | "type": "null" 41 | }, 42 | "type": "null", 43 | "valid": true 44 | }, 45 | { 46 | "description": "should generate objects", 47 | "schema": { 48 | "type": "object" 49 | }, 50 | "type": "object", 51 | "valid": true 52 | }, 53 | { 54 | "description": "should generate strings", 55 | "schema": { 56 | "type": "string" 57 | }, 58 | "type": "string", 59 | "valid": true 60 | } 61 | ] 62 | } 63 | ] 64 | -------------------------------------------------------------------------------- /tests/schema/core/refs/allOf.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "arbitrary local-references", 4 | "tests": [ 5 | { 6 | "description": "should resolve any local-reference", 7 | "schema": { 8 | "components": { 9 | "schemas": { 10 | "A": { 11 | "allOf": [ 12 | { 13 | "$ref": "#/components/schemas/B" 14 | }, 15 | { 16 | "$ref": "#/components/schemas/C" 17 | } 18 | ] 19 | }, 20 | "B": { 21 | "type": "object", 22 | "properties": { 23 | "bProp": { 24 | "type": "string", 25 | "format": "date-time" 26 | } 27 | }, 28 | "required": [ 29 | "bProp" 30 | ] 31 | }, 32 | "C": { 33 | "type": "object", 34 | "properties": { 35 | "cProp": { 36 | "type": "number", 37 | "required": true 38 | } 39 | } 40 | } 41 | } 42 | } 43 | }, 44 | "sync": true, 45 | "valid": true, 46 | "set": { 47 | "alwaysFakeOptionals": true 48 | }, 49 | "hasProps": [ 50 | "components.schemas.A", 51 | "components.schemas.B", 52 | "components.schemas.C" 53 | ] 54 | } 55 | ] 56 | } 57 | ] 58 | -------------------------------------------------------------------------------- /tests/schema/core/refs/sync.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "should work on async mode (by default)", 4 | "timeout": 30000, 5 | "online": true, 6 | "tests": [ 7 | { 8 | "description": "should resolve all references", 9 | "schema": { 10 | "type": "object", 11 | "required": ["value", "other"], 12 | "properties": { 13 | "value": { 14 | "$ref": "#/definitions/test" 15 | }, 16 | "other": { 17 | "$ref": "#/definitions/other" 18 | } 19 | }, 20 | "definitions": { 21 | "test": { 22 | "type": "string" 23 | }, 24 | "other": { 25 | "$ref": "https://gist.githubusercontent.com/anonymous/eb11f16c9edccf040c028dc8bd2b1756/raw/cbac21f18550ff559b5bec4187aa813e59a8d825/User" 26 | } 27 | } 28 | }, 29 | "FIXME": "this eventually fails, but because other is resolved to undefined; it just happen when repeating too much (too many requests?)", 30 | "_repeat": 100, 31 | "skip": true, 32 | "valid": true 33 | }, 34 | { 35 | "description": "should resolve only local references", 36 | "schema": { 37 | "type": "object", 38 | "properties": { 39 | "value": { 40 | "$ref": "#/definitions/test" 41 | } 42 | }, 43 | "definitions": { 44 | "test": { 45 | "type": "string" 46 | } 47 | } 48 | }, 49 | "valid": true 50 | }, 51 | { 52 | "description": "should fail on undefined/unreachable references", 53 | "schema": { 54 | "type": "object", 55 | "properties": { 56 | "value": { 57 | "$ref": "LocalIfOrRemoteURL" 58 | } 59 | } 60 | }, 61 | "throws": "ENOENT: no such file or directory" 62 | } 63 | ] 64 | } 65 | ] 66 | -------------------------------------------------------------------------------- /tests/schema/core/typecast/chance/bool.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "should typecast chance.bool when generated value type is different than defined", 4 | "tests": [ 5 | { 6 | "description": "should generate the value with default type provided by chance.js (no explicit typedef)", 7 | "schema": { 8 | "chance": "bool" 9 | }, 10 | "valid": true 11 | }, 12 | { 13 | "description": "should cast to string", 14 | "schema": { 15 | "type": "string", 16 | "chance": "bool" 17 | }, 18 | "valid": true 19 | } 20 | ] 21 | } 22 | ] 23 | -------------------------------------------------------------------------------- /tests/schema/core/typecast/chance/year.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "should typecast chance.year when generated value type is different than defined", 4 | "tests": [ 5 | { 6 | "description": "should generate the value with default type provided by chance.js (no explicit typedef)", 7 | "schema": { 8 | "chance": "year" 9 | }, 10 | "valid": true 11 | }, 12 | { 13 | "description": "should cast to string", 14 | "schema": { 15 | "type": "string", 16 | "chance": "year" 17 | }, 18 | "valid": true 19 | }, 20 | { 21 | "description": "should cast parametrized generator to string", 22 | "schema": { 23 | "type": "string", 24 | "chance": { 25 | "year": { 26 | "min": 1939, 27 | "max": 1945 28 | } 29 | } 30 | }, 31 | "valid": true 32 | } 33 | ] 34 | } 35 | ] 36 | -------------------------------------------------------------------------------- /tests/schema/core/typecast/faker/address-latitude-longitude.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "should typecast faker.address.latitude and faker.address.longitude when generated value type is different than defined", 4 | "tests": [ 5 | { 6 | "description": "should generate the value with default type provided by faker.js (no explicit typedef)", 7 | "schema": { 8 | "faker": "address.longitude" 9 | }, 10 | "valid": true 11 | }, 12 | { 13 | "description": "should cast to number", 14 | "schema": { 15 | "type": "number", 16 | "faker": "address.longitude" 17 | }, 18 | "valid": true 19 | }, 20 | { 21 | "description": "should cast to integer", 22 | "schema": { 23 | "type": "integer", 24 | "faker": "address.longitude" 25 | }, 26 | "valid": true 27 | }, 28 | { 29 | "description": "should cast array elements to number", 30 | "schema": { 31 | "type": "array", 32 | "items": [ 33 | { 34 | "type": "number", 35 | "faker": "address.latitude" 36 | }, 37 | { 38 | "type": "number", 39 | "faker": "address.longitude" 40 | } 41 | ] 42 | }, 43 | "valid": true 44 | }, 45 | { 46 | "description": "should cast object properties values to number", 47 | "schema": { 48 | "$schema": "http://json-schema.org/draft-04/schema#", 49 | "description": "A geographical coordinate", 50 | "type": "object", 51 | "properties": { 52 | "latitude": { 53 | "type": "number", 54 | "faker": "address.latitude" 55 | }, 56 | "longitude": { 57 | "type": "number", 58 | "faker": "address.longitude" 59 | } 60 | }, 61 | "required": [ 62 | "latitude", 63 | "longitude" 64 | ] 65 | }, 66 | "valid": true 67 | } 68 | ] 69 | } 70 | ] 71 | -------------------------------------------------------------------------------- /tests/schema/core/typecast/faker/finance-amount.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "description": "should typecast faker.finance.amount when generated value type is different than defined", 4 | "tests": [ 5 | { 6 | "description": "should generate the value with default type provided by faker.js (no explicit typedef)", 7 | "schema": { 8 | "faker": "finance.amount" 9 | }, 10 | "valid": true 11 | }, 12 | { 13 | "description": "should cast to string", 14 | "schema": { 15 | "type": "string", 16 | "faker": "finance.amount" 17 | }, 18 | "valid": true 19 | }, 20 | { 21 | "description": "should cast faker.finance.amount to number", 22 | "schema": { 23 | "type": "number", 24 | "faker": "finance.amount" 25 | }, 26 | "valid": true 27 | }, 28 | { 29 | "description": "should cast faker.finance.amount to integer", 30 | "schema": { 31 | "type": "integer", 32 | "faker": "finance.amount" 33 | }, 34 | "valid": true 35 | } 36 | ] 37 | } 38 | ] 39 | -------------------------------------------------------------------------------- /tests/unit/core/infer.spec.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import infer from '../../../src/lib/core/infer.mjs'; 3 | 4 | describe('Infer', () => { 5 | it('should infer `array` type when `additionalItems` property exists on top-level schema', () => { 6 | const schema = { 7 | additionalItems: true, 8 | }; 9 | 10 | expect(infer(schema, '')).to.eql('array'); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /tests/unit/core/randomGeneration.spec.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import jsf from '../../../src/lib/main.mjs'; 3 | 4 | describe('Random Generation', () => { 5 | it('should generate all the fields with alwaysFakeOptionals option and additionalProperties: true', () => { 6 | jsf.option({ 7 | alwaysFakeOptionals: true, 8 | }); 9 | 10 | const schema = { 11 | type: 'object', 12 | properties: { 13 | foo: { type: 'string' }, 14 | bar: { type: 'string' }, 15 | }, 16 | required: [], 17 | additionalProperties: true, 18 | }; 19 | 20 | return jsf.resolve(schema).then(resolved => { 21 | expect(Object.keys(resolved).length).to.be.at.least(2); 22 | }); 23 | }); 24 | it('should generate all the fields with alwaysFakeOptionals option and additionalProperties: false', () => { 25 | jsf.option({ 26 | alwaysFakeOptionals: true, 27 | }); 28 | 29 | const schema = { 30 | type: 'object', 31 | properties: { 32 | foo: { type: 'string' }, 33 | bar: { type: 'string' }, 34 | }, 35 | required: [], 36 | additionalProperties: false, 37 | }; 38 | 39 | return jsf.resolve(schema).then(resolved => { 40 | expect(Object.keys(resolved).length).is.eql(2); 41 | }); 42 | }); 43 | }); 44 | -------------------------------------------------------------------------------- /tests/unit/generators/boolean.spec.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import booleanGenerator from '../../../src/lib/generators/boolean.mjs'; 3 | 4 | describe('Boolean Generator', () => { 5 | it('should always return a boolean type', () => { 6 | expect(typeof booleanGenerator()).to.eql('boolean'); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /tests/unit/generators/ipv4.spec.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import ipv4Generator from '../../../src/lib/generators/ipv4.mjs'; 3 | 4 | describe('IPv4 Generator', () => { 5 | it('should always match the IPv4 regex', () => { 6 | expect(ipv4Generator()).to.match(/^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$/); 7 | }); 8 | }); 9 | -------------------------------------------------------------------------------- /tests/unit/generators/null.spec.mjs: -------------------------------------------------------------------------------- 1 | import { expect } from 'chai'; 2 | import nullGenerator from '../../../src/lib/generators/null.mjs'; 3 | 4 | describe('Null Generator', () => { 5 | it('should always return `null` value', () => { 6 | expect(nullGenerator()).to.eql(null); 7 | }); 8 | }); 9 | --------------------------------------------------------------------------------