I have a Flask backend which uses Connexion 2.7.0 with OpenAPI 3.0.0.
My swagger.yaml file is defined like this:
openapi: 3.0.0
info:
title: MyApp
version: "1.0"
paths:
/run_recon:
post:
summary: run_recon
operationId: services.model.run_recon
requestBody:
content:
application/json:
schema:
type: object
x-name: payload
x-body-name: payload
responses:
"200":
description: response
content:
"application/json":
schema:
type: object
security:
- jwt-user: ["secret"]
swagger.yaml is loaded into connexion app like this:
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
load_dotenv()
options = {"swagger_ui": True,
"debug": True}
app = connexion.App(__name__, server='gevent')
app.add_api('swagger.yaml', options=options)
app.app.config["JSON_SORT_KEYS"] = False
app.app.wsgi_app = CorsHeaderMiddleware(app.app.wsgi_app)
if __name__ == "__main__":
print("DB_NAME:",os.getenv("DB_NAME"))
app.run(port=5002, host='0.0.0.0')
And the Python function in Flask app is defined like this:
def run_recon(payload):
print("[run_recon]")
When the frontend sends request to /run_recon
, the request does not even reach the Python function.
But if I simply change the function signature to: def run_recon(body)
, then the rqeeust reaches and the function works.
Why is the custom name for the request body breaking the automatic parameter injection of Connexion?
I have tried individually x-body
and x-body-name
, as well as using both together. Nothing seems to work.