Swagger 请求正文一次显示单个对象,即使它接受对象列表,我怀疑我们是否可以默认在 put API swagger 文档中显示对象列表
简短回答:
是的,根据文档,您可以添加数组示例。 (https://swagger.io/docs/specification/adding-examples/)
少简短回答:
这完全取决于 swagger 定义中的 schema 和 definitions 部分。有一个用于 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