feat(json-schema-2020-12-samples): support randomness option
Refs #9739
Description
Add support for randomness, enabled via optionAPI and implemented in core/random.js. Default is no randomness so everything is backward compatible. For now only used in the minimal number of generates to enable full unit test code coverage of the changes in core/random.js. Other generators can follow in next PRs.
Open question: do we need changes to the documentation? It could make sense but I was expecting a place to already find documentation about APIs like formatAPI where we can add description for optionAPI. We can also do this later when it's actually working with all types/formats and/or exposed to users.
Motivation and Context
This is one step in #9739 to eventually support propertyNames, while also having other uses like configuration option to use randomness across the board.
How Has This Been Tested?
Unit tests have been added to cover the changes, and existing tests still pass.
Checklist
My PR contains...
- [ ] No code changes (
src/is unmodified: changes to documentation, CI, metadata, etc.) - [ ] Dependency changes (any modification to dependencies in
package.json) - [ ] Bug fixes (non-breaking change which fixes an issue)
- [ ] Improvements (misc. changes to existing features)
- [x] Features (non-breaking change which adds functionality)
My changes...
- [ ] are breaking changes to a public API (config options, System API, major UI change, etc).
- [ ] are breaking changes to a private API (Redux, component props, utility functions, etc.).
- [ ] are breaking changes to a developer API (npm script behavior changes, new dev system dependencies, etc).
- [x] are not breaking changes.
Documentation
- [ ] My changes do not require a change to the project documentation.
- [ ] My changes require a change to the project documentation.
- [ ] If yes to above: I have updated the documentation accordingly.
Automated tests
- [ ] My changes can not or do not need to be tested.
- [x] My changes can and should be tested by unit and/or integration tests.
- [x] If yes to above: I have added tests to cover my changes.
- [x] If yes to above: I have taken care to cover edge cases in my tests.
- [x] All new and existing tests passed.
@char0n let me know if this one is ok before I move to next, I think it should be good to go. Btw I changed the account where I host the fork but shouldn't affect the PR.
@char0n would you or another maintainer be able to look into merging this? I hope to implement the support for propertyNames but there are quite a few more PRs to go, so would like to get started on the next after finished this one.
@char0n @glowcloud could this one be merged? My goal as in #9739 is to add support for randomness in generators (though by default still return constants) and then use that to eventually support propertyNames which is key to full JSON Schema 2020-12 support for samples and significantly improves things like #5713. It would help if this one is merged so the next step can be built on top.