Extend pyswagger

This section describes things about extending pyswagger.

A new client implementation

To implement a customized client, you need to aware BaseClient

class pyswagger.core.BaseClient(security=None)[source]

base implementation of SwaggerClient, below is an minimum example to extend this class

class MyClient(BaseClient):

    # declare supported schemes here
    __schemes__ = ['http', 'https']

    def request(self, req_and_resp, opt):
        # passing to parent for default patching behavior,
        # applying authorizations, ...etc.
        req, resp = super(MyClient, self).request(req_and_resp, opt)

        # perform request by req
        ...
        # apply result to resp
        resp.apply(header=header, raw=data_received, status=code)
        return resp
__init__(security=None)[source]

constructor

Parameters:security (Security) – the security holder
__weakref__

list of weak references to the object (if defined)

prepare_schemes(req)[source]

make sure this client support schemes required by current request

Parameters:req (pyswagger.io.Request) – current request object
request(req_and_resp, opt)[source]

preprocess before performing a request, usually some patching. authorization also applied here.

Parameters:req_and_resp ((Request, Response)) – tuple of Request and Response
Returns:patched request and response
Return type:Request, Response