Swagger发送和接收数组


openapi: "3.0.0" 
info:   
title: project 
servers:
- url: http://example1.net/v3
- url: http://example/v3
paths:
/Pn/{PnId}/service1:
post:
summary: Pn data
description: |
can Pn the data
requestBody:
required: true
content:
application/json:
schema:
$ref: "#/components/schemas/dataInfo"
application/x-www-form-urlencoded:
schema:
$ref: "#/components/schemas/dataInfo"
parameters:
- name: PnId
in: path
description: PnId
required: true
schema:
$ref: "#/components/schemas/Pn"
responses:
'200':
description: status
content:
application/json:
schema:
$ref: "#/components/schemas/dataInfoStatus"
example: infoable
default:
description: error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
components:   
schemas:
Error:
type: object
properties:
code:
type: integer
message:
type: string
required:
- message
Pn:
type: integer
format: int64
dataInfo:
type: string
dataInfoStatus:
type: string
enum: [infoable, non_infoable,ignorable]

我在请求中发送单个dataInfo,在响应中获得单个dataInfoStatus,但我希望发送一个dataInfo数组,并获得一个dataInfoStatus数组。

我尝试了以下内容:

schema:
type:array
items:
$ref: "#/components/schemas/dataInfo"

但我有

解析程序错误映射条目的错误缩进

项。我正在关注这一点。

如何在请求中将dataInfo作为dataInfo数组发送,并在响应中获得dataInfoStatus数组?

您必须在type:array之间再添加一个空格,然后错误消息消失:

schema:
type: array
items:
$ref: "#/components/schemas/dataInfo"

您可以为openapi文件的版本添加info.version

最新更新