Array of string parameter not passed correctly to server
Description
Using connexion 2.0.2 and openapi 3.0 YAML file, array of string parameters not passed correctly.
Expected behaviour
When running auto-generated browser UI, the browser shows type 'array[string] (query)' and prompts user to add array items one by one. If user does that, it is expected a list of str would be passed to the server processing method (defined by operationId in the YAML file).
Actual behaviour
Server processing method gets a list with only one element, regardless of length of array entered by user into browser UI. A work around exists: if array is entered into the first item, with elements separated by commas, then server processing method gets list of str as expected.
Steps to reproduce
- YAML file contains:
` openapi: 3.0.0
....
paths:
/end_point:
post:
operationId: server_processing_method
tags:
- Tag
summary: Do something
parameters:
- name: inParam
in: query
description: "list of str"
schema:
type: array
items:
type: string
required: true
`
-
Run server on localhost. Point browser to UI: 127.0.0.1:5000/ui/#
-
Enter parameter for
POST end_point: use 'add item' to specify an array with >1 elements, say "first","second","third" (each string as a separate item) -
server_processing_method(inParam) will get inParam==["first"]. The rest of the elements are missing.
-
back to step 3, enter "first","second","third" into first item. This time server_processing_method(inParam) will get inParam==["first","second","third"]
Additional info:
Output of the commands:
python --versionPython 3.6.5 :: Anaconda, Inc.pip show connexion | grep "^Version\:"Version: 2.0.2
Hey @RonKalian for next time It's really helpful if you can post a fully working yaml spec.
Can you post the curl command that swagger-ui is outputting?
Hi @dtkav, thank you for your response. The curl when swagger-ui is used to enter 3 separate array elements is:
curl -X POST "http://127.0.0.1:5000/end_point?inParam=first&inParam=second&inParam=third" -H "accept: application/json"
I think that's possibly the root of the problem. If it is:
curl -X POST "http://127.0.0.1:5000/end_point?inParam=first%2Csecond%2Cthird" -H "accept: application/json"
It works OK.
Fully working YAML spec (you only need to change operationId value to use it)
openapi: 3.0.0
info:
title: Sample API
description: API description in Markdown.
version: 1.0.0
paths:
/end_point:
post:
operationId: path.to.my.python.file.server_processing_method
tags:
- Tag
summary: Do something
parameters:
- name: inParam
in: query
description: "list of str"
schema:
type: array
items:
type: string
required: true
responses:
'200':
description: Success
content:
application/json:
schema:
type: string
The operationId server function I use is:
def server_processing_method(inParam):
print("{}".format(inParam))
Hey @RonKalian - This is indeed a bug. Thanks for the detailed ticket.
You can fix it in the near term by setting style: form for your parameter.
parameters:
- name: inParam
in: query
description: "list of str"
style: form
schema:
type: array
items:
type: string
required: true
According to the spec the default for query parameters is intended to be form.
IIRC connexion currently defaults to simple (aka csv).
Hi @dtkav , thank you for your help. I can confirm
setting
style: form
fixes the issue.