nuysoft / Mock

A simulation data generator
http://mockjs.com
Other
19.53k stars 2.66k forks source link

Mock.toJSONSchema( template ) #31

Closed nuysoft closed 9 years ago

nuysoft commented 10 years ago

规则映射

rule String Number Boolean Object Array Function RegExp
min
max
dmin
dmax
step
Bosn commented 10 years ago

应该是toJSONSchema吧

nuysoft commented 10 years ago

@Bosn 嗯

nuysoft commented 9 years ago

2014.12.24 纪要

@nuysoft @Bosn @蒋壮

  1. RAP 输出的 JSON Schema 需要把数据的规则结构化

    完善输出的 JSON Schema,对应的 Java 代码在 这里

    常用类型:Number,String

  2. 占位符(标签)

    1. RAP 原封不动的输出
    2. IF-Test 和 Mock 共建占位符(标签)基础库
    3. IF-Test 扩展的占位符(标签)可以共用在 RAP 和 IF-Test(包括验证)
    4. IF-Test 建立占位符(标签)的验证规则

      Mock.js 也会扩展和建立占位符(标签)的验证规则,但是不用在 Mock-RAP-IFTest 的生态里。参考 river/mock/blob/master/lib/river-mock.js

      优先保证占位符(标签)基础库的一致。

  3. Mock Service 验证

占位符(标签)基础库

2014.12.24

Type Method
Basics boolean, natural, integer, float, character, string
Date date, time, datetime
Image image
Web url, domain, email, ip

DDDeadLine

2014.12.26

  1. 确定占位符(标签)基础库的方法签名和行为
  2. 前面的第 1 条
paolier commented 9 years ago

占位符标签的基础库,已经开发完成尽办。简单举个例子: 如下是是个jsonchema:

{
    "title": "custom format attribute demonstration",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "naturalNum": {
                "type": "number",
                "iftest": "@natural(5,10)"
            },
            "isSuccess": {
                "type": "boolean",
                "iftest": "@boolean(5,10)"
            },
            "userMock": {
                "type": "string",
                "iftest": "@mock=sdff"
            }
        }
    }
}

下面是data:

[
    {
        "naturalNum":456
    },
    {
        "isSuccess":false
    },
    {
        "userMock":"sdff"
    }
]

结果是:

--- BEGIN MESSAGES ---
error: 超出范围
    level: "error"
    schema: {"loadingURI":"#","pointer":"/items/properties/naturalNum"}
    instance: {"pointer":"/0/naturalNum"}
    domain: "validation"
    keyword: "iftest"
    argumentList: ["5","10"]
    failed: ["456"]
---  END MESSAGES  ---

rap这边需要调整的是querySchema接口,对于原本

"format":"MOCKJS|A-PART|B-PART"

的输出要更改为:

"iftest":"A-PART|B-PART"

@Bosn @nuysoft 明天找个15分钟我们电话会议下

paolier commented 9 years ago

会议纪要: 1、@Bosn 按照如上修改querySchema接口 2、DEADLINE为:1月23日(周五)完成,包括开发机部署

感谢!么么哒!

paolier commented 9 years ago

type:web的情况要扩种一种方法 @url(host,path,query) 例如:要mock 天猫宝贝详情的detail: http://detail.tmall.com/item.htm?id=41156775172&spm=a1z09.5.0.0.otr1cg 则为:@url('detail.tmall.com','item.htm','id') 大概是这个意思,不是很严禁,里面的参数可以再细化

@nuysoft 你看呢?

paolier commented 9 years ago

我想了下改成这样易用性会更好 @url() @url(example) @url(example,type) type=protocal/host/path/query/all,缺省是all 例如:@url('http://detail.tmall.com/item.htm?id=41156775172&spm=a1z09.5.0.0.otr1cg', 'query') 那么仅仅会验证data是url,同时,有两个参数,且为id和spm

paolier commented 9 years ago

目前if-validator已经支持了mockjs方法如下:

Type Method
Basics boolean, natural, integer, float, character, string
Date date, time, datetime
Image image
Web url
Other (data)

Other 的example:

{
   "type":"string",
   "iftest:"data"
}

yes:

   "data"

no:

   "sdf"