Connexion: Question: How should I deal with operationId when the same function handles both PUT and POST calls?

Created on 30 May 2019  路  2Comments  路  Source: zalando/connexion

Description

I've recently been acquainted with Connexion when I started working on Swagger. As mentioned in the title, I have an api (called "post_users()" for example) that handles both PUT and POST calls, which I think is commonly done. Since the operationId in the swagger.yaml is supposed to be unique, I was wondering how I can tell connexion to use the same function for both the calls. Sorry, if this was previously asked or if this is a noob question (I am), but I could not find any way to get around this. Thanks, in advance.

Most helpful comment

one workaround would be to write a function which only calls the other function.

def post_function(data):
    do_stuff_here_with(data)

def put_function(data):
    return post_function(data)

and specify those two respectively in the swagger file.

All 2 comments

one workaround would be to write a function which only calls the other function.

def post_function(data):
    do_stuff_here_with(data)

def put_function(data):
    return post_function(data)

and specify those two respectively in the swagger file.

Even simpler, you can also just create a variable pointing to the same function:

```python
def post_function(data)
# my code here
....

put_function = post_function

Was this page helpful?
0 / 5 - 0 ratings