我们可以在swagger put API请求体中显示多个对象吗

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

Swagger 请求正文一次显示单个对象,即使它接受对象列表,我怀疑我们是否可以默认在 put API swagger 文档中显示对象列表

java rest swagger
1个回答
0
投票

简短回答:

是的,根据文档,您可以添加数组示例。 (https://swagger.io/docs/specification/adding-examples/

少简短回答:

这完全取决于 swagger 定义中的 schemadefinitions 部分。有一个用于 swagger 编辑器的示例 yaml 文件 (https://editor.swagger.io/),其中包含带有简单值、对象和示例的数组定义。

swagger: '2.0'
info:a
  version: 1.0.0
  title: Privacy-Service API
paths:
  /allNames:
    post:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - name: request
          in: body
          schema:
            $ref: '#/definitions/ArrayOfNames'
      responses:
        '200':
          description: List of names
          schema:
            type: array
            items:
              type: string
              
  /allAddresses:
    post:
      consumes:
        - application/json
      produces:
        - application/json
      parameters:
        - name: request
          in: body
          schema:
            $ref: '#/definitions/ArrayOfAddresses'
      responses:
        '200':
          description: List of addresses
          schema:
            type: array
            items:
              type: object  
              
definitions:
  ArrayOfNames:
    type: array
    items:
      minItems: 1
      type: object
      required:
        - name
      properties:
        name:
          type: string
    example: ["name":"John", "name" : "Arthur", "name": "Thomas"]
  
    
  ArrayOfAddresses:
    type: array
    items:
      minItems: 1
      type: object
      required:
        - city
        - street
        - houseNumber
      properties:
        city:
          type: string
        street:
          type: string
        houseNumber:
          type: number
    example:
      - city: Knoxville
        street: Raver Croft Drive
        houseNumber: 225
      - city: Gates Mills
        street: Simpson Avenue
        houseNumber: 4636
© www.soinside.com 2019 - 2024. All rights reserved.