json模式:使键值取决于先前的值

时间:2020-04-13 17:58:16

标签: json validation schema

我将通过一个过于简化的示例来提问。鉴于此yaml模式:

type: object
properties:
  relations:
    type: array
    items:
      type: object
      required: [name, nickname, friends]
      properties:
        name:
          type: string
        nickname:
          type: string
        friends:           # This must reference a name value already defined:
          type: array
          items:
            type: string
            $ref: #name

当然,“ $ ref:#name”部分是SWAG作为占位符,在这里我需要一些聪明的东西。我想要的是“朋友”字段,以引用以前定义的名称。例如,这是有效的: 关系:

- name: James Smith
  nickname: Jimmy S
- name: Stan Smith
  nickname: SS
  friends: [James Smith]        # <-- references a previously defined name

但不是这样:

- name: James Smith
  nickname: Jimmy S
- name: Stan Smith
  nickname: SS
  friends: [Dave Jones]         # <-- invalid as it does NOT reference a previously defined name

尽管有很多关于$ ref,定义,anyOf,oneOf等的出色文档和示例;我没有为这种用途量身定制它们。

任何信息都将不胜感激!

0 个答案:

没有答案