diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000000000000000000000000000000000..2965e19a9a98dacfcc2c44194ae199710f732bcd --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,4 @@ +custom: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8MXLRJ7QQXGYY&source=url +open_collective: json-schema-faker +github: pateketrueke +ko-fi: pateketrueke diff --git a/dist/bundle.umd.min.js b/dist/bundle.umd.min.js index fbab44069c94b58c7f5d1b98f9d7734020a397a5..60ce23ccbc162bfe25b0dc5544cc245063ab8d06 100644 Binary files a/dist/bundle.umd.min.js and b/dist/bundle.umd.min.js differ diff --git a/dist/index.esm.js b/dist/index.esm.js new file mode 100644 index 0000000000000000000000000000000000000000..19acac0529e583ef00ebf59b9afe7e0d684af72f Binary files /dev/null and b/dist/index.esm.js differ diff --git a/dist/index.umd.js b/dist/index.umd.js index 8558ecb5ef0a1f530eddb7e0d238cdf25e870779..8c8957a6c0ad2520437e2f96cda99f86ea4f0ece 100644 Binary files a/dist/index.umd.js and b/dist/index.umd.js differ diff --git a/dist/index.umd.min.js b/dist/index.umd.min.js index 7f1b59690f06132ac8857b111df565d69674c04c..3e875ae5afb441fb75708c09f7ac30dffdd05fac 100644 Binary files a/dist/index.umd.min.js and b/dist/index.umd.min.js differ diff --git a/dist/index.umd.min.js.map b/dist/index.umd.min.js.map index 1dd191996f83a5659e6c86c2fb6fe67e9b628927..e5a265e941855c7e316e43094f06268a8f3d9d1f 100644 Binary files a/dist/index.umd.min.js.map and b/dist/index.umd.min.js.map differ diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index f0d4af6010d4dc2347efee3bf476dfd06c7126f8..0000000000000000000000000000000000000000 Binary files a/package-lock.json and /dev/null differ diff --git a/package.json b/package.json index 7a710180b6a072e252894cf7b1035320d78f8cee..02b559a33bb7a366d45879b962dce0ecfa2ee721 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "unpkg": "dist/bundle.umd.min.js", "browser": "dist/index.umd.min.js", "scripts": { - "build:concat:dist": "concat -o dist/bundle.umd.min.js node_modules/json-schema-ref-parser/dist/ref-parser.min.js node_modules/jsonpath/jsonpath.min.js dist/index.umd.min.js", + "build:concat:dist": "concat -o dist/bundle.umd.min.js node_modules/json-schema-ref-parser/dist/ref-parser.min.js node_modules/jsonpath-plus/dist/index-umd.min.js dist/index.umd.min.js", "build:browser": "bili --banner --format umd --format umd-min --module-name JSONSchemaFaker --minimal && npm run build:concat:dist", "build:node": "bili src/index.js --minimal --format es --format cjs", "build": "npm run build:browser && npm run build:node", diff --git a/src/types/object.js b/src/types/object.js index c50d98a6f5b17648b232ff991c0e6efbc47ff972..7d6a72036ca60e78b309f5099b6e74e584a6460a 100644 --- a/src/types/object.js +++ b/src/types/object.js @@ -117,6 +117,12 @@ function objectType(value, path, resolve, traverseCallback) { } } + if (additionalProperties === false) { + if (requiredProperties.indexOf(key) !== -1) { + props[key] = properties[key]; + } + } + if (properties[key]) { props[key] = properties[key]; } diff --git a/tests/unit/core/randomGeneration.spec.js b/tests/unit/core/randomGeneration.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..59c4280c89bcd1ace1989e9fa8d258e719a53425 --- /dev/null +++ b/tests/unit/core/randomGeneration.spec.js @@ -0,0 +1,45 @@ +import { expect } from 'chai'; +import jsf from '../../../src'; + +/* global describe, it */ + +describe('Random Generation', () => { + it('should generate all the fields with alwaysFakeOptionals option and additionalProperties: true', async () => { + jsf.option({ + alwaysFakeOptionals: true, + }); + + const schema = { + type: 'object', + properties: { + foo: { type: 'string' }, + bar: { type: 'string' }, + }, + required: [], + additionalProperties: true, + }; + + const resolved = await jsf.resolve(schema); + + expect(Object.keys(resolved).length).to.be.at.least(2); + }); + it('should generate all the fields with alwaysFakeOptionals option and additionalProperties: false', async () => { + jsf.option({ + alwaysFakeOptionals: true, + }); + + const schema = { + type: 'object', + properties: { + foo: { type: 'string' }, + bar: { type: 'string' }, + }, + required: [], + additionalProperties: false, + }; + + const resolved = await jsf.resolve(schema); + + expect(Object.keys(resolved).length).is.eql(2); + }); +});