Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/apipost-team/apipost-mock-schema
Simple utility to mock example objects based on JSON schema definitions
https://github.com/apipost-team/apipost-mock-schema
json-schema jsonschema mock-data mock-json-schema mockjs
Last synced: 3 months ago
JSON representation
Simple utility to mock example objects based on JSON schema definitions
- Host: GitHub
- URL: https://github.com/apipost-team/apipost-mock-schema
- Owner: Apipost-Team
- License: mit
- Created: 2022-07-11T03:28:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-04-24T06:09:36.000Z (9 months ago)
- Last Synced: 2024-04-25T04:51:07.620Z (9 months ago)
- Topics: json-schema, jsonschema, mock-data, mock-json-schema, mockjs
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/apipost-mock-schema
- Size: 78.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 🚀 apipost-mock-schema
[![Package Quality](https://packagequality.com/shield/apipost-mock-schema.svg)](https://packagequality.com/#?package=apipost-mock-schema)
Simple utility to mock example objects based on JSON schema definitions
## Features
Minimal & deterministic. Predictable single example with no randomisation involved
TypeScript types included
Supports $ref pointers
Thoroughly tested feature set
Supports example, default
Supports anyOf, allOf, oneOf
Built-in examples for following string formats:
- hostname
- ipv4
- ipv6
- uri
- uri-reference
- uri-template
- json-pointer
- date-time
- uuid## Install
```
$ npm install apipost-mock-schema
```## Usage
```javascript
const schema = {
type: 'array',
items: {
type: 'object',
properties: {
id: {
type: 'integer',
minimum: 1,
},
name: {
type: 'string',
example: 'John Doe',
},
email: {
type: 'string',
format: 'email',
},
},
},
};
const MockSchema = require('apipost-mock-schema');
const myMockSchema = new MockSchema();myMockSchema.mock(schema).then(res => {
console.log(res)
// will return
/*
[
{
"id": 7156472017141059,
"name": "John Doe",
"email": "[email protected]"
}
]
*/
}).catch(err => {
console.log(err)
})
```