Reputation: 21
I'm trying to document an already existing python API with Swagger. I wrote the swagger.yaml with every route documented with the help of their editor. Now i would like to deploy the documentation using connexion.
(brief example of the swagger.yaml file)
swagger: "2.0"
info:
description: "This is a description of the routes of the API"
version: "1.0.0"
title: "API"
basePath: "/api"
paths:
/home:
get:
tags:
- "API"
summary: "Home of the application"
operationId: home
responses:
200:
description: "Success"
schema:
type: object
properties:
user_id:
type: string
username:
type: string
403:
description: "Limit of api connections overrun"
I changed the Flask app by a connexion.app during the launch of the server, and was able to specify the .yaml file. But when i'm trying to launch it, it crashes instantly:
File "/usr/local/lib/python2.7/dist-packages/connexion/utils.py", line 74, in get_function_from_name
raise ValueError("Empty function name")
exceptions.ValueError: Empty function name
From my understanding connexion will base it's manual testing feature from the object operationId in every route that needs to point on the function handling the request. Problem: every route of the API are defined as nested function.
def add_routes(app, oauth):
@app.route('/api/home', methods=['GET'])
@oauth.require_oauth()
def home():
user = request.oauth.user
return jsonify(
user_id=user.user_id,
username=user.username
)
I know nested functions in python are not actually functions at all: not callable, just present in the language in order for us programmers to organize our code.
I think that would be the issue with connexion, it is just not capable of finding these functions and map them for the manual testing feature, but i'm not sure how to fix this. Do you see something that would allow connexion to map the function without having to refactor the entire API in order not to have nested functions ?
Thanks a lot for any help.
Upvotes: 2
Views: 1850
Reputation: 309
My guess is that you haven't defined your handler function. You need to provide a module+function that matches the operationId in the spec.
For example: I have a function called get_user() in a file app.py , I need to set the operationId to app.get_user.
operationId: app.get_user
Hope that helps!
Upvotes: 4