Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] missing 1 required positional argument #3345

Open
5 of 6 tasks
FFY00 opened this issue Jul 12, 2019 · 5 comments
Open
5 of 6 tasks

[BUG] missing 1 required positional argument #3345

FFY00 opened this issue Jul 12, 2019 · 5 comments

Comments

@FFY00
Copy link

FFY00 commented Jul 12, 2019

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

openapi-generator is generating invalid python-flask code.

openapi-generator version
4.0.3
OpenAPI declaration file content or url
openapi: 3.0.0
servers:
  - url: 'http://localhost:8080'

info:
  version: 0.0.1
  title: ratbag-emu
  license:
    name: MIT
    url: 'https://raw.githubusercontent.com/libratbag/ratbag-emu/master/LICENSE'

tags:
  - name: device
    description: Control interface for the simulated device

paths:
  /devices:
    get:
      tags:
        - device
      summary: List of simulated devices
      description: 'Provides the list of devices that are being currently simulated by ratbag-emu'
      operationId: list_devices
      parameters: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Device'
  '/devices/add/{shortname}':
    get:
      tags:
        - device
      summary: Creates a simulated device
      description: 'Tells ratbag-emu to create a new simulated device'
      operationId: add_device
      parameters:
        - name: shortname
          in: path
          description: Short name name of the device to add
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
        '400':
          description: Can't add device
  '/devices/{device_id}':
    get:
      tags:
        - device
      summary: Returns a simulated device
      description: 'Returns one the of devices currently simulated by ratbag-emu'
      operationId: get_device
      parameters:
        - name: device_id
          in: path
          description: ID of the device to return
          required: true
          schema:
            type: integer
            format: int32
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Device'
        '404':
          description: Device not found
  '/devices/{device_id}/event':
    post:
      tags:
        - device
      summary: Send an event to a simulated device
      operationId: device_event
      description: 'Send HID event data to the target device'
      parameters:
        - name: device_id
          in: path
          description: ID of the device to use as the event source
          required: true
          schema:
            type: integer
            format: int32
      requestBody:
        description: Event data
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventData'
      responses:
        '200':
          description: OK
        '400':
          description: Error sending data to the device
        '404':
          description: Device not found

components:
  requestBodies:
    Device:
      description: Simulated device
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Device'
  schemas:
    Device:
      title: Device
      description: Simulated device
      type: object
      required:
        - id
      properties:
        id:
          type: integer
          format: int32
        name:
          type: string
    EventData:
      title: Event data
      description: Raw HID event data
      type: object
      properties:
        x:
          type: integer
          format: int32
        y:
          type: integer
          format: int32
Command line used for generation
openapi-generator generate \
    -i src/ratbag_emu/openapi/ratbag-emu.yaml \
    --package-name ratbag_emu_server \
    -g python-flask \
    -o src/server_gen/
Steps to reproduce
  • Run the command above
  • Run the server
$ curl -X POST "http://localhost:8080/devices/0/event" -H  "accept: */*" -H  "Content-Type: application/json" -d "{\"x\":0,\"y\":6}"
{
  "detail": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.",
  "status": 500,
  "title": "Internal Server Error",
  "type": "about:blank"
}

And in the server log

[2019-07-12 10:45:14,479] ERROR in app: Exception on /devices/0/event [POST]
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 2311, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1834, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1737, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python3.7/site-packages/flask/_compat.py", line 36, in reraise
    raise value
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/root/.local/lib/python3.7/site-packages/connexion/decorators/decorator.py", line 73, in wrapper
    response = function(request)
  File "/root/.local/lib/python3.7/site-packages/connexion/decorators/uri_parsing.py", line 132, in wrapper
    response = function(request)
  File "/root/.local/lib/python3.7/site-packages/connexion/decorators/validation.py", line 165, in wrapper
    response = function(request)
  File "/root/.local/lib/python3.7/site-packages/connexion/decorators/validation.py", line 339, in wrapper
    return function(request)
  File "/root/.local/lib/python3.7/site-packages/connexion/decorators/decorator.py", line 44, in wrapper
    response = function(request)
  File "/root/.local/lib/python3.7/site-packages/connexion/decorators/parameter.py", line 126, in wrapper
    return function(**kwargs)
TypeError: device_event() missing 1 required positional argument: 'event_data'
@auto-labeler
Copy link

auto-labeler bot commented Jul 12, 2019

👍 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.

@juviwhale
Copy link

I am having this issue as well, does anyone know a quick patch to the generated code? @FFY00

@juviwhale
Copy link

Oh I see, it is adding arguments for the request body with the param arguments. So I can just delete those.

@jdeyton
Copy link

jdeyton commented Oct 24, 2019

Looks to me to be the same as #1666

There are some workarounds mentioned in that older issue.

@H21lab
Copy link

H21lab commented May 29, 2020

The same happens when generating https://github.com/jdegre/5GC_APIs/blob/master/TS29573_N32_Handshake.yaml

It generates:

./openapi_server/controllers/security_capability_negotiation_controller.py:10
def post_exchange_capability(sec_negotiate_req_data)

As a workaround, the generated code can be manually changed to:

./openapi_server/controllers/security_capability_negotiation_controller.py:10
def post_exchange_capability(body)

In #1666 are mentioned also workarounds like editing yaml file or applying template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants