You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been trying out Connexion recently. I have an API spec that is like a 3GPP API spec in yaml format. I noticed that all the given examples follow the "PythonAppName.runThisFunction" operationId format. Also found examples where only the name of the function is defined.
I would like to now, if it is mandatory to follow the mentioned format or the function name is enough?
I wrote a simple code where it should give back a fix answer.
Expected behaviour
According to the swagger OpenAPI guide (https://swagger.io/docs/specification/paths-and-operations/#operations), it should be enough to specify the function name only. The middleware should recognise that operationId function is defined in my python code. In it I start the AsyncApp with the run() function.
Actual behaviour
With: "operationId: Login"
Failed to add operation for POST /ss-nra/v1/login
and if I try to reach it regardless: Internal server error 500, empty module name
With: "operationId: app.Login"
No error, but a securitySchemes warning of a missing x-term (x-tokenInfoFunc missing), but the server is reachable and there is no empty module name.
Also recieves the expected response.
Steps to reproduce
Create "mockupserver.py", code:
import socket
import os
from connexion import AsyncApp, ConnexionMiddleware, request, App
from pathlib import Path
import connexion
from threading import Timer
import json
TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImZvbyIsInBhc3N3b3JkIjoiYmFyIiwiaWF0IjoxNjY4MDg0NDI1fQ.lT4ABOQSHyJdIiF9rso06qcwrBkIxRFyolIgdBAI4l0"
PASSWD = {"admin": "secret", "foo": "bar"}
#Simulating an authentication process
#Should more secure than this
#@app.route("/login")
def Login(body):
# data = {
# 'username': str,
# 'password': str,
# 'accessToken': str
# }
if body is not json:
body = json.loads(body)
data = {
'username': body['username'],
'password': body['password'],
'accessToken': ""
}
if PASSWD.get(body.username) == body.password:
print("Right password and username")
headers = {"Content-Type": "application/json"}
data['accessToken'] = TOKEN
return data, 200, headers
else:
print("Wrong username ('foo') or password ('bar')")
print(": "+body['username']+" "+body['password'])
headers = {"Content-Type": "application/json"}
data['accessToken'] = TOKEN
return data, 200, headers
def Login_Get(body):
data = {
'username': 'foo',
'password': 'bar',
'accessToken': ""
}
print("Right password and username")
data['accessToken'] = TOKEN
headers = {"Content-Type": "application/json"}
return data, 200, headers
##Create the server
app = AsyncApp(__name__, specification_dir="./")
##Add the required APIs
app.add_api("login.yaml")
try:
if __name__ == '__main__':
#Start server
app.run(f"{Path(__file__).stem}:app", port=7777)
except KeyboardInterrupt:
#Ater KeyboardInterrupt
print("CTRL-C: Exiting")
print("CTRL-C: Exiting")
Description
I have been trying out Connexion recently. I have an API spec that is like a 3GPP API spec in yaml format. I noticed that all the given examples follow the "PythonAppName.runThisFunction" operationId format. Also found examples where only the name of the function is defined.
I would like to now, if it is mandatory to follow the mentioned format or the function name is enough?
I wrote a simple code where it should give back a fix answer.
Expected behaviour
According to the swagger OpenAPI guide (https://swagger.io/docs/specification/paths-and-operations/#operations), it should be enough to specify the function name only. The middleware should recognise that operationId function is defined in my python code. In it I start the AsyncApp with the run() function.
Actual behaviour
With: "operationId: Login"
Failed to add operation for POST /ss-nra/v1/login
and if I try to reach it regardless: Internal server error 500, empty module name
With: "operationId: app.Login"
No error, but a securitySchemes warning of a missing x-term (
x-tokenInfoFunc missing
), but the server is reachable and there is no empty module name.Also recieves the expected response.
Steps to reproduce
Create "mockupserver.py", code:
Create "login.yaml" API spec:
Tester code "loginer.py":
Run:
python3 mockupserver.py
Run:
python3 loginer.py
Then repeat with the login.yaml modified to this:
Additional info:
Output of the commands:
python3 --version
Python 3.10.12pip show connexion | grep "^Version\:"
Version: 3.1.0The text was updated successfully, but these errors were encountered: