Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anttiviljami/mock-json-schema
Simple utility to mock example objects based on JSON schema definitions
https://github.com/anttiviljami/mock-json-schema
hacktoberfest json-schema mock openapi
Last synced: 4 days ago
JSON representation
Simple utility to mock example objects based on JSON schema definitions
- Host: GitHub
- URL: https://github.com/anttiviljami/mock-json-schema
- Owner: anttiviljami
- License: mit
- Created: 2018-11-17T22:34:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-17T03:41:25.000Z (about 1 year ago)
- Last Synced: 2024-10-04T12:53:37.990Z (about 1 month ago)
- Topics: hacktoberfest, json-schema, mock, openapi
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/mock-json-schema
- Size: 264 KB
- Stars: 26
- Watchers: 3
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# mock-json-schema
[![CI](https://github.com/anttiviljami/mock-json-schema/workflows/CI/badge.svg)](https://github.com/anttiviljami/mock-json-schema/actions?query=workflow%3ACI)
[![npm version](https://img.shields.io/npm/v/mock-json-schema.svg)](https://www.npmjs.com/package/mock-json-schema)
[![npm downloads](https://img.shields.io/npm/dw/mock-json-schema)](https://www.npmjs.com/package/mock-json-schema)
[![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/anttiviljami/mock-json-schema/blob/master/LICENSE)
[![Buy me a coffee](https://img.shields.io/badge/donate-buy%20me%20a%20coffee-orange)](https://buymeacoff.ee/anttiviljami)Simple utility to mock example objects based on JSON schema definitions
## Features
- [x] Minimal & deterministic. Predictable single example with no randomisation involved
- [x] Thoroughly [tested](https://github.com/anttiviljami/mock-json-schema/blob/master/src/mock.test.ts) feature set
- [x] Supports `example`, `default`
- [x] Supports `anyOf`, `allOf`, `oneOf`
- [x] Built-in examples for following string formats:
- `email`
- `hostname`
- `ipv4`
- `ipv6`
- `uri`
- `uri-reference`
- `uri-template`
- `json-pointer`
- `date-time`
- `uuid`
- [x] TypeScript types included
- [ ] Supports $ref pointers## Usage
```javascript
const { mock } = require('mock-json-schema');
const assert = require('assert');const schema = {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'integer',
minimum: 1,
},
name: {
type: 'string',
example: 'John Doe',
},
email: {
type: 'string',
format: 'email',
},
},
},
};assert.deepEqual(mock(schema), [{ id: 1, name: 'John Doe', email: '[email protected]' }]);
```View more [examples](https://github.com/anttiviljami/mock-json-schema/blob/master/src/mock.test.ts)
## Contributing
mock-json-schema is Free and Open Source Software. Issues and pull requests are more than welcome!