OpenAPITools / OpenAPITools/openapi-generator
[BUG] missing 1 required positional argument
Open
Nobody has claimed this yet.
Issue: Bug
Server: Python
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided openapi-generator command with the YAML declaration and inspect the generated handler for device_event and its request-body parameter handling. Reproduce the POST request and trace why event_data is not passed; done means the generated python-flask server accepts the payload without the missing-argument TypeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- flask, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100