How to refer to enclosing type definition recursively in OpenAPI / Swagger?

六眼飞鱼酱① 提交于 2019-11-29 09:35:32

Your definition is perfectly fine. It's a known issue issue with rendering recursive schemas in Swagger Editor and Swagger UI:

https://github.com/swagger-api/swagger-ui/issues/3325

To work around the null/undefined values in the "Example Value", you can add a custom example to your schema:

definitions:
  TreeNode:
    type: object
    properties:
      name:
        type: string
        description: The name of the tree node.
      children:
        type: array
        items:
          $ref: '#/definitions/TreeNode'
    example:
      name: foo
      children:
        - name: bar
        - name: baz
          children:
            - name: qux
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!