我正在尝试使REST API具有连接功能,但无法弄清楚如何设置使用一系列对象的get操作。 最后,我需要一次获取有关多个项目的信息。
使用Python 3.7,connexion-2.3.0和Swagger与OpenAPI Specification版本。 2。
我的摇摇欲坠文件:
swagger: "2.0"
info:
description: "This is documentation for REST api test."
version: "1.0.0"
title: test
consumes:
- application/json
produces:
- application/json
basePath: /api
paths:
/test:
get:
operationId: test.test
summary: "Just testing array."
parameters:
- name: query
in: body
schema:
type: array
items:
$ref: '#/definitions/query'
responses:
200:
description: All ok!
definitions:
query:
type: object
required:
- a
- b
properties:
a:
type: integer
description: "Test propertie 1."
example: 42
b:
type: string
description: "Test propertie 2."
example: "hi"
c:
type: string
description: "Test propertie 3."
example: "abc"
我的带有测试功能的Python文件:
def test(query):
for item in query:
print(item)
return {'result': 'it is fine'}
尝试通过Swagger UI传递JSON:
[
{
"a": 42,
"b": "hi",
"c": "abc"
}
]
我的测试功能的预期响应:
{
"result": "it is fine"
}
实际回应:
{
"detail": "None is not of type 'array'",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}