在属性中限制 openapi 类型的正确方法是什么?

Which is the correct way to restrict openapi type in properties?

到目前为止我有以下内容:

Links:
  description: Must contain links objects
  type: object
  properties:
    $ref: "#/components/schemas/Link"
ErrorLinks:
  allOf:
    - $ref: "#/components/schemas/Links"
    - properties:
        about:
          $ref: "#/components/schemas/Link"

Links中,我不关心任何properties的名称是什么,只关心它们都是Link对象。在 ErrorLinks 中,我希望有一个 about 属性,它也是一个 Link 对象。

这是定义它的正确方法吗,或者我是说(在 Links 中)我希望 properties 节点本身是一个 Link 对象?

我发现 openapi 文档在有用的示例中有点缺乏,并且上面的验证有效,所以我不完全确定。

In Links, I don't care what the names of any properties are, just that they are all Link objects.

Links 是一个字典(hashmap)。字典使用 additionalProperties 定义,如 this answer:

中所述
Links:
  description: Must contain links objects
  type: object
  additionalProperties:
    $ref: "#/components/schemas/Link"

In ErrorLinks, I expect there to be an about property, which is also an Link object.

你快到了。不需要allOf,你只需要一个简单的对象模式:

ErrorLinks:
  type: object
  properties:
    about:
      $ref: "#/components/schemas/Link"
  required:
    - about