Search code examples
pythonflaskconnexion

Connexion class based handling


I'm using the connexion framework for flask. I'd like to group several related functions into a class and I'm wondering whether methods of a class can be used for operationId instead of functions.

Something like

class Job:

    def get():
        "something"

    def post():
        "something"

in the describing yaml file:

 paths:
    /hello:
        post:
            operationId: myapp.api.Job.post

Solution

  • You can use the methods if they are available as staticmethods on the class:

    class Job:
    
        @staticmethod
        def get():
            "something"
    
        @staticmethod
        def post():
            "something"