mock-from-json-schema
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i mock-from-json-schema

Weekly Downloads

10

Version

0.1.4

License

none

Unpacked Size

58.3 kB

Total Files

14

Last publish

Collaborators

  • jscon