OpenAPI - 如何在架构中仅引用另一个架构的一个属性?

问题描述 投票:0回答:1

我在组件 --> 架构中有以下 OpenAPI。在 CreateBookDto 中,我只想引用我的 Person 架构的

id
属性。这可以通过 OpenAPI 实现吗?如果是,怎么办?如果没有,这个功能有什么原因不存在吗?

Person:
      type: object
      properties:
        id:
          type: number
          description: ID of the person
        username:
          type: string
          description: Username of the person
        books:
          description: All books of one person
          type: array
          items:
            $ref: '#/components/schemas/Book'
CreateBookDto:
      type: object
      properties:
        title:
          type: string
          description: The title of the book
        person_id: <-- Here I want to reference to the id property of Person
          type: number
          description: The ID of the person
yaml swagger openapi
1个回答
0
投票

您可以使用 JSON 指针

...

person_id:
  $ref: '#/components/schemas/Person/properties/id'

...
© www.soinside.com 2019 - 2024. All rights reserved.