OpenAPITools / OpenAPITools/openapi-generator
[PYTHON-FLASK] Problem posting with x-www-form-urlencoded
Open
Nobody has claimed this yet.
Server: Python
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
My python flask server is crashing when posting url encoded post parameter.
openapi-generator version
5.0.0
OpenAPI declaration file content or url
---
openapi: 3.0.3
servers:
- url: 'https://my.api.com'
info:
version: 1.0
title: A test API
paths:
/login:
post:
operationId: login
requestBody:
required: true
content:
application/x-www-form-urlencoded:
schema:
$ref: '#/components/schemas/LogInInfo'
responses:
'200':
description: Login successfull
components:
schemas:
LogInInfo:
type: object
required:
- email
- password
properties:
email:
type: string
password:
type: string
Command line used for generation
openapi-generator generate -g python-flask -i api.yaml
Steps to reproduce
- Generate the flask server
- Run it with
python -m openapi_server - Make a post request on the path
/login - See the crash log:
$ python -m openapi_server
* Serving Flask app "__main__" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:8080/ (Press CTRL+C to quit)
[2021-01-28 20:05:12,933] ERROR in app: Exception on /login [POST]
Traceback (most recent call last):
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.9/site-packages/connexion/decorators/decorator.py", line 48, in wrapper
response = function(request)
File "/usr/local/lib/python3.9/site-packages/connexion/decorators/uri_parsing.py", line 144, in wrapper
response = function(request)
File "/usr/local/lib/python3.9/site-packages/connexion/decorators/validation.py", line 184, in wrapper
response = function(request)
File "/usr/local/lib/python3.9/site-packages/connexion/decorators/parameter.py", line 121, in wrapper
return function(**kwargs)
TypeError: login() missing 2 required positional arguments: 'email' and 'password'
127.0.0.1 - - [28/Jan/2021 20:05:12] "POST /login HTTP/1.1" 500 -
Related issues/PRs
Not that I know.
Suggest a fix/enhancement
I manage to fix it by replacing the openapi_server/controllers/default_controller.py code:
import connexion
import six
from openapi_server import util
def login(email, password): # noqa: E501
"""login
# noqa: E501
:param email:
:type email: str
:param password:
:type password: str
:rtype: None
"""
return
With:
import connexion
import six
from openapi_server import util
def login(**kwargs): # noqa: E501
email = kwargs["body"]["email"]
password = kwargs["body"]["password"]
"""login
# noqa: E501
:param email:
:type email: str
:param password:
:type password: str
:rtype: None
"""
return
Any idea what is going wrong ?
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 with the generated openapi_server/controllers/default_controller.py and the provided OpenAPI declaration, then reproduce the issue using the documented openapi-generator command and POST to /login. Done means the generated Flask server accepts application/x-www-form-urlencoded email and password parameters without crashing.
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