Skip to content
mock-from-json-schema
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts
src
test
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
LICENSE
README.md
jest.config.js
jsdoc.json
package.json
rollup.config.production.js
tsconfig.json

README.md

mock-from-json-schema

Build Status Coverage Status MIT Licence npm version

Simple utility to mock example objects based on JSON schema definitions. Copy from mock-json-schema, but not use lodash (less bundle size)

Installation

Node.js / Browserify

npm install mock-from-json-schema --save
import mock from "mock-from-json-schema";

var schema = {
    "title": "配置",
    "description": "",
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "商品名称",
            "title": "name"
        },
        "list": {
            "type": "array",
            "title": "list",
            "description": "列表",
            "items": {
                "title": "",
                "description": "",
                "type": "object",
                "properties": {
                    "itemName": {
                        "type": "string",
                        "description": "子项名称",
                        "title": "itemName"
                    }
                },
                "required": [
                    "itemName"
                ]
            }
        }
    },
    "required": [
        "name"
    ]
};

console.log(555, mock(schema));

// 输出:
// {
//     "name": "string",
//     "list": [
//         {
//             "itemName": "string"
//         }
//     ]
// }

Build & test

npm run build
npm test
npm run doc

then open the generated out/index.html file in your browser.

License

MIT.

You can’t perform that action at this time.