OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.9k stars 6.59k forks source link

[BUG] [python-flask] deepObjects in query causes exception with duplicates #7837

Open colford opened 4 years ago

colford commented 4 years ago

Bug Report Checklist

Description

When a query has deepObjects either a BAD REQUEST with "missing parameter" is observed with python3.5 or an exception is raised with python3.6 in _resolve_param_duplicates.

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url
openapi: 3.0.0

info:
    title: Foo API
    description:
        Test out deepObjects with query
    version: 0.1.0

servers:
  - url: 'http://localhost:8080/v1'

components:
  schemas:
    fakeObj:
      type: object
      required:
        - part1
        - part2
      properties:
        part1:
          type: number
          format: double
        part2:
          type: number
          format: double
      description: 
        Fake object that takes doubles
      example:
        part1: 50.4351
        part2: -3.5642
  parameters:
    fakeObj-arrayparam:
      in: query
      name: fakeit
      required: true
      style: deepObject
      explode: true
      schema:
        type: array
        items:
          $ref: '#/components/schemas/fakeObj'
      description:
        Array of fake objects
      example:
        - part1: 37.222864
          part2: -80.420806
        - part1: 37.223637
          part2: -80.420153
        - part1: 37.224372
          part2: -80.419886

paths:
  /obs/fake:
    get:
      operationId: FakeOp
      parameters:
        - $ref: '#/components/parameters/fakeObj-arrayparam'
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
Generation Details

./run-in-docker.sh generate -i PNT-A/Fake.yaml -g python-flask -o PNT-A/CDN/Fake --package-name=FaakeINF

Steps to reproduce

Created using docker tools in Ubuntu and then ran. Connected to http://localhost:8080/v1/ui and used the "Try it Out" on the /obs/fake path, accepted all the defaults and pressed execute. Expected it to come back with 'do some magic!'

Related issues/PRs

Only some for typescript but not for python-flask.

Suggest a fix

Looks like it is not handling the duplicates in the URL with the deepObject:

http://localhost:8080/v1/obs/fake?fakeit[part1]=37.222864&fakeit[part2]=-80.420806&fakeit[part1]=37.223637&fakeit[part2]=-80.420153&fakeit[part1]=37.224372&fakeit[part2]=-80.419886

python3.6 stack dump is:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2447, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1952, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.6/dist-packages/flask/_compat.py", line 39, in reraise
    raise value
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/local/lib/python3.6/dist-packages/connexion/decorators/decorator.py", line 48, in wrapper
    response = function(request)
  File "/usr/local/lib/python3.6/dist-packages/connexion/decorators/uri_parsing.py", line 141, in wrapper
    request.query = self.resolve_query(query)
  File "/usr/local/lib/python3.6/dist-packages/connexion/decorators/uri_parsing.py", line 215, in resolve_query
    return self.resolve_params(query_data, 'query')
  File "/usr/local/lib/python3.6/dist-packages/connexion/decorators/uri_parsing.py", line 113, in resolve_params
    values = self._resolve_param_duplicates(values, param_defn, _in)
  File "/usr/local/lib/python3.6/dist-packages/connexion/decorators/uri_parsing.py", line 235, in _resolve_param_duplicates
    return delimiter.join(values)
TypeError: sequence item 0: expected str instance, dict found
auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

mcejp commented 3 years ago

Apologies for hijacking the issue, but have you tried to generate a Python client for this spec? It seems to me that style: deepObject is completely ignored there, but I could not find a relevant issue already open.

colford commented 3 years ago

Apologies for hijacking the issue, but have you tried to generate a Python client for this spec? It seems to me that style: deepObject is completely ignored there, but I could not find a relevant issue already open.

No, I didn't since I couldn't get the server side to work with python and deepObjects.