From: Adam A.G. Shamblin Date: Thu, 13 Jun 2019 20:25:10 +0000 (-0600) Subject: Parameters and start to responses. X-Git-Url: https://git.vexinglabs.com/?a=commitdiff_plain;h=076197f0e4287a4171241ab96cce464b095a4c27;p=hector.git Parameters and start to responses. --- diff --git a/README.md b/README.md index ef17349..c206e2c 100644 --- a/README.md +++ b/README.md @@ -53,3 +53,4 @@ previous session. Default: `None` * Add option to filter by host or regex * Optionally write to multiple files instead of just one * Post-process swagger to collapse on base-path +* Add a command to trigger a write to file diff --git a/hector.py b/hector.py index e18ed78..8902c4c 100644 --- a/hector.py +++ b/hector.py @@ -34,7 +34,6 @@ class Hector: if ctx.options.hector_input != '': with open(ctx.options.hector_input, 'r') as swagger: for doc in yaml.load_all(swagger, Loader=yaml.Loader): - print(doc) self._output[doc['host']] = doc def done(self): @@ -51,11 +50,65 @@ class Hector: target = self._output[request.host] target['host'] = request.host + path = '/'.join(request.path_components) + if path == '': + path = '/' + method = request.method.lower() + if request.scheme not in target['schemes']: target['schemes'].append(request.scheme) if request.path not in target: - target['paths'][request.path] = {} + target['paths'][path] = {} + + if request.method not in target['paths'][path]: + target['paths'][path][method] = { + 'summary': request.path + } + + query = request.query.items() + if len(query) != 0: + target['paths'][path][method]['parameters'] = [] + for key, val in query: + target['paths'][path][method]['parameters'].append({ + 'name': key, + 'in': 'query', + 'type': typePy2OAPI(val), + 'example': val + }) + + def response(self, flow): + request = flow.request + response = flow.response + + target = self._output[request.host] + + path = '/'.join(request.path_components) + if path == '': + path = '/' + method = request.method.lower() + content_type = response.headers.get('Content-Type') + + print(method) + + if 'responses' not in target['paths'][path][method]: + target['paths'][path][method]['responses'] = {} + + target['paths'][path][method]['responses'][response.status_code] = { + 'content': { + content_type: { + 'schema': {} + } + } + } + + +def typePy2OAPI(val): + types = { + 'str': 'string', + 'int': 'integer' + } + return types[type(val).__name__] addons = [