我想发布一个字符串数组,如
[
"id1",
"id2"
]
到基于 Swagger 的 API。在我的 swagger 文件中,我有以下几行:
paths:
/some_url:
post:
parameters:
- name: ids
in: body
required: true
指定
ids
类型的正确方法是什么?作为字符串数组?更新:
根据规范,以下应该在我的选择中起作用:
parameters:
- in: body
description: xxx
required: true
schema:
type: array
items:
type: string
https://github.com/Yelp/swagger_spec_validator不接受它并返回一长串令人费解的错误,看起来代码需要一些
$ref
.
最佳答案
你对字符串数组的描述是正确的,但参数定义漏掉了name
属性有效。
这是一个完整的工作示例:
swagger: "2.0"
info:
title: A dummy title
version: 1.0.0
paths:
/path:
post:
parameters:
- in: body
description: xxx
required: true
name: a name
schema:
type: array
items:
type: string
responses:
default:
description: OK
尝试使用在线编辑器检查您的 OpenAPI (fka. Swagger) 规范:http://editor.swagger.io/
关于rest - 在 swagger API 中指定一个字符串数组作为 body 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39281532/