Open microrache opened 5 months ago
Meanwhile I did a little debugging which brought me to an experiment: I changed the value for QUERY_STRING_DELIMITERS['form']
in the file uri_parsing.py from ","
(comma) to a less common/likely string like "|||"
(three pipes) and could observe that the erroneously split disappeared. But to be honest, I am not very experienced with elaborate testing nor with all the multiple possible query-formats, so I cannot overlook the consequences of such a modification.
But digging through the code raised a question for me: I don't really understand, why at all - speaking for the form-request-style - in the process of URI-parsing the parameters-array is joined to a string first, just to be exploded back into an array a little later. Could anyone explain to me what's the reason behind this?
For anyone running into this issue, here is a workaround by defining a custom URI-parser-class within our app. We abstract the OpenAPIURIParser
and re-define the delimiter by re-assigning a value to the delimiter-dictionary (which is very bad practice as this is supposed to be a constant):
from connexion.uri_parsing import OpenAPIURIParser, QUERY_STRING_DELIMITERS
class OpenAPIURIParserMod(OpenAPIURIParser):
def __init__(self, param_defns, body_defn):
super().__init__(param_defns, body_defn)
QUERY_STRING_DELIMITERS['form'] = '|||'
and in app.py
:
from .parsers.OpenAPIURIParserMod import OpenAPIURIParserMod
app = AsyncApp(
__name__,
# any other options
uri_parser_class=OpenAPIURIParserMod,
)
We also have this problem
Description
When I specify an array-parameter with string-items by using the default serialization-options (style=form, explode=true), the submitted strings are split on every occurence of comma before passed into my operation.
Actual behaviour
A submitted array
["a, b", "c"]
is passed as["a", "b", "c"]
into the handler-method.Expected behaviour
The strings remain untouched and the array is passed as list-object with length = 2 and the values
"a, b"
and"c"
.Steps to reproduce
Create a Connexion-app with v3.0.6 and load the following spec:
Create a method which simply returns the submitted list![image](https://github.com/spec-first/connexion/assets/23389242/3223cf65-37d3-4213-816f-bdcb2828fb5f)
mylist
. Start Swagger UI and submit the 3 provided example-values. The response will be an array consisting of 8 entries instead of the submitted 3 values:Additional info: