Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support Object Pattern Properties #63

Closed
Prodesire opened this issue Feb 20, 2020 · 3 comments
Closed

[Feature] Support Object Pattern Properties #63

Prodesire opened this issue Feb 20, 2020 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@Prodesire
Copy link

Is your feature request related to a problem? Please describe.
form-render seems not support object pattern properties currently. This feature is pretty useful, hope it will be supportted.

Describe the solution you'd like
Object pattern propperties is like this:

{
  "type": "object",
  "patternProperties": {
    "^S_": { "type": "string" },
    "^I_": { "type": "integer" }
  },
  "additionalProperties": false
}

Sometimes you may want to restrict the names of the extra properties, or you may want to say that, given a particular kind of name, the value should match a particular schema. That’s where patternProperties comes in: it is a new keyword that maps from regular expressions to schemas. If an additional property matches a given regular expression, it must also validate against the corresponding schema.

Hope form-render can support this standard json schema grammer.

@Prodesire Prodesire added the enhancement New feature or request label Feb 20, 2020
@FateRiddle
Copy link
Contributor

感觉上, object pattern properties在校验JSON数据上很有用,写一个pattern就能校验一大批字段。但是在表单场景,每个表单元素的schema都应该是明确的schema。因为schema不仅描述了数据校验,也同时描述了表单的UI,感觉非常难以想象一个确实必须使用pattern的表单渲染场景,能否给个现实场景? @Prodesire

@Prodesire
Copy link
Author

Prodesire commented Mar 11, 2020

感觉上, object pattern properties在校验JSON数据上很有用,写一个pattern就能校验一大批字段。但是在表单场景,每个表单元素的schema都应该是明确的schema。因为schema不仅描述了数据校验,也同时描述了表单的UI,感觉非常难以想象一个确实必须使用pattern的表单渲染场景,能否给个现实场景? @Prodesire

其实 patternProperties 非常常见。在我们内部使用场景中,用户要新建一个资源,他告诉服务端必要的信息(比如产品、类型),然后点一个按钮来动态生成资源。服务端会返回根据给定的信息找到相关的数据,动态生成出表示这个资源的数据结构(比如说这个资源有哪些属性,每个属性是什么类型,涉及到哪些增删改查API)。这份元数据就是要填写到表单中,由于元数据是动态生成的,深层次的数据结构中并不知道一个字典它有哪些key(就比如说我并不能事先知道资源的属性名称是什么,这些都是动态生成的,所以表单的校验规则中需要有 patternProperties进行正则匹配)。
@FateRiddle

@FateRiddle
Copy link
Contributor

schema本身也可以动态生成吧?Object Pattern Properties 太贴数据校验规范,而且写起来对于不熟悉JSON schema的用户来说也不友好。至于批量校验,会用别的方式来做。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants