I'm trying to make REST API with connexion but can't figure out how to set up get operation that consumes an array of objects. In the end, I need to get information about several items at once.
Using Python 3.7, connexion-2.3.0 and Swagger with OpenAPI Specification ver. 2.
My swagger file:
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"
My Python file with test function:
def test(query):
for item in query:
print(item)
return {'result': 'it is fine'}
Trying to pass JSON through Swagger UI:
[
{
"a": 42,
"b": "hi",
"c": "abc"
}
]
Expected response from my test function:
{
"result": "it is fine"
}
Actual response:
{
"detail": "None is not of type 'array'",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}
The problem is the GET verb, you can not use body. You should use something like that :
parameters:
- name: objects
in: query
required: true
type: array
items:
type: string
The array itens must be of types : string , number, integer, boolean or array