小编csk*_*k87的帖子

如何使用 $ref 文件中的附加属性?

我将我的 JSON 模式分成两个文件。

person-input.json (将由输入设置的所有属性。)

person.json (持有对 person-input.json 的引用,但也有 dateUpdate、dateCreated 和 DateDeleted)。

这将输入与自动生成的日期属性分开。

我不希望任何帖子能够向我的数据添加不需要的属性,所以我想我会使用"additionalProperties": false的问题是,如果我在person-input.json文件中使用它,它将不接受文件中的“日期”属性person.json。如果我把它放在 person.json 文件中,它不会阻止添加随机属性。这个问题有方法解决吗?

所以下面这个不起作用,我放错地方了"additionalProperties": false吗?

person.json

{
  "allOf": [
    {
      "$ref": "./person-input.json"
    },
    {
      "type": "object",
      "properties": {
        "dateCreated": {
        "name": "dateCreated",
        "type": "string",
        "description": "date created",
        "example": "2019-09-02T11:17:41.783Z"
        },
        "dateUpdated": {
          "type": "string",
          "nullable": true,
          "description": "date updated",
          "example": "2019-09-02T11:17:41.783Z"
        },
        "dateDeleted": {
          "type": "string",
          "nullable": true,
          "description": "date deleted",
          "example": "2019-09-02T11:17:41.783Z"
        }
      },
      "additionalProperties": false
    } …
Run Code Online (Sandbox Code Playgroud)

json jsonschema openapi

4
推荐指数
1
解决办法
609
查看次数

如何将 getFieldDecorator 与 React (function) hooks 一起使用

我正在尝试创建一个简单的 antd 表单,但不知道如何使 getFieldDecorator 与我的 React 函数一起使用。我如何转化this.props.form为反应钩子方法?这是 antd 文档中的类语法。

  function FormDrawerButton () {

  // ToggleDrawer
  const [visible, setVisible] = useState(false);

  const toggleDrawer = () => {
    setVisible(!visible)
  }

const { getFieldDecorator } = this.props.form; // how to use this?

  return (
    <>
    <Button
      type="primary"
      icon="edit"
      size="large"
      style={{ float: 'right' }}
      onClick={ toggleDrawer }
    >
      Add user
    </Button>
  <div>
    <Drawer
      title="Create a new user"
      width={720}
      onClose={ toggleDrawer }
      visible={ visible }
    >
    <p>Form</p>
    <Form className="login-form">
        <Form.Item>
          {getFieldDecorator('username', {
            rules: …
Run Code Online (Sandbox Code Playgroud)

forms reactjs antd react-hooks

2
推荐指数
1
解决办法
7389
查看次数

标签 统计

antd ×1

forms ×1

json ×1

jsonschema ×1

openapi ×1

react-hooks ×1

reactjs ×1