From a3f16e3f2ee65cfb07c84dae8fe8444028ce87cb Mon Sep 17 00:00:00 2001
From: naiieandrade <andradenaiara@hotmail.com>
Date: Jun 08 2018 01:39:15 +0000
Subject: Create API documentantion


---

diff --git a/flasgger/__init__.py b/flasgger/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/flasgger/__init__.py
diff --git a/flasgger/api.py b/flasgger/api.py
new file mode 100644
index 0000000..f2edcd9
--- /dev/null
+++ b/flasgger/api.py
@@ -0,0 +1,210 @@
+from flask import Flask, jsonify
+from flask_restful import Api, Resource
+
+from flasgger import Swagger
+
+
+app = Flask(__name__)
+api = Api(app)
+app.config['SWAGGER'] = {
+    'title': 'Kiskadee Api',
+    'uiversion': 2
+}
+swag = Swagger(app)
+
+
+class GetFetchersView(Resource):
+
+    def get(self):
+        """
+        Example endpoint returning a list of fetchers
+        List fetchers
+        ---
+        tags:
+          - fetchers
+        responses:
+          200:
+            description: Returns a list of fetchers
+            schema:
+              id: Fetchers
+              properties:
+                fetchers:
+                  type: array
+                  items:
+                    $ref: '#/definitions/Fetcher'
+            examples:
+              fetchers: [{'description': 'A fetcher to monitor Anitya packages', 'id': 1, 'name': 'anitya', 'target': 'release-monitoring.org'}]
+        """
+        data = {
+            "fetchers": [
+                {'description': 'A fetcher to monitor Anitya packages',
+                 'id': 1,
+                 'name': 'anitya',
+                 'target': 'release-monitoring.org'},
+                {"description": "SAMATE Juliet test suite",
+                 "id": 2,
+                 'name': 'example',
+                 'target': 'example'},
+            ]
+        }
+        return jsonify(data)
+
+
+class GetAnalysisProjectView(Resource):
+
+    def get(self, project, version):
+        """
+        Example endpoint returning a analyze from a project
+        Analizes the project version
+        ---
+        tags:
+          - analysis
+        parameters:
+          - name: project
+            in: path
+            description: Name of project
+            required: true
+            type: string
+            default: bodhi
+          - name: version
+            in: path
+            description: Version of project
+            required: true
+            type: string
+            default: 3.5.0
+        responses:
+          200:
+            description: Returns a analyze from a project
+        """
+        data = {
+            '': [
+                {'analyzer_id': 2,
+                 'analyzers': {'name': "flawfinder",
+                               'version': "1.0.0"},
+                 'id': 4,
+                 'version_id': 3},
+            ]
+        }
+        return jsonify(data)
+
+
+class GetResultsProjectView(Resource):
+
+    def get(self, project, version, analysis_id):
+        """
+        Example endpoint returning a results from a project version
+        Shows the results of the project version
+        ---
+        tags:
+          - analysis
+        parameters:
+          - name: project
+            in: path
+            description: Name of project
+            required: true
+            type: string
+            default: bodhi
+          - name: version
+            in: path
+            description: Version of project
+            required: true
+            type: string
+            default: 3.5.0
+          - name: analysis_id
+            in: path
+            description: Analysis ID
+            required: true
+            type: integer
+            default: 2
+
+        responses:
+          200:
+            description: Returns a results from a project analyze
+        """
+        data = {
+            'analysis_results': [
+                {'custmofields': 'null',
+                    'cwe': 'null',
+                    'location': {'file': {'abspath': 'null',
+                                          'givenpath': "deepin-menu-2014.2.3/dbus.h",
+                                          'hash_': 'null'},
+                                 'function': 'null',
+                                 'point': {'column': 0,
+                                           'line': 44},
+                                 'range': 'null'},
+                    'message': {'text': 'Class \'ManagerAdaptor\' has a constructor with 1 argument that is not explicit.'},
+                    'notes': {'text': 'Class \'ManagerAdaptor\' has a constructor with 1 argument that is not explicit. Such constructors should in general be explicit for type safety reasons. Using the explicit keyword in the constructor means some mistakes when using the class can be avoided.'},
+                    'severity': 'style',
+                    'testeid': 'noExplicitConstructor',
+                    'trace': 'null',
+                    'type': 'Issue'},
+            ]
+        }
+        return jsonify(data)
+
+
+class GetReportsProjectView(Resource):
+
+    def get(self, project, version, analysis_id):
+        """
+        Example endpoint returning a reports from a project version
+        Shows the results of the project version
+        ---
+        tags:
+          - analysis
+        parameters:
+          - name: project
+            in: path
+            description: Name of project
+            required: true
+            type: string
+            default: bodhi
+          - name: version
+            in: path
+            description: Version of project
+            required: true
+            type: string
+            default: 3.5.0
+          - name: analysis_id
+            in: path
+            description: Analysis ID
+            required: true
+            type: integer
+            default: 2
+
+        responses:
+          200:
+            description: Returns a reports from a project analyze
+        """
+        data = {
+            'analysis_reports': [
+                {'analysis_id': 4,
+                    'id': 3,
+                    'results': {'severity_1': 0,
+                                'severity_2': 0,
+                                'severity_3': 0,
+                                'severity_4': 0,
+                                'severity_5': 0},
+                 },
+            ]
+        }
+        return jsonify(data)
+
+
+api.add_resource(GetFetchersView, '/fetchers')
+api.add_resource(GetAnalysisProjectView, '/analysis/<string:project>/<string:version>')
+api.add_resource(GetResultsProjectView, '/analysis/<string:project>/<string:version>/<int:analysis_id>/results')
+api.add_resource(GetReportsProjectView, '/analysis/<string:project>/<string:version>/<int:analysis_id>/reports')
+
+
+@app.route("/")
+def hello():
+    return """
+    <h1>Welcome Kiskadee API</h1>
+    The API documentation you can see on
+    <a href="/apidocs">Api docs</a>
+    """
+
+
+if __name__ == "__main__":
+    app.run(debug=True)
diff --git a/requirements.txt b/requirements.txt
index f1039cf..af0b039 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,5 +1,5 @@
 psutil
-psycopg2
+psycopg2-binary
 firehose>=0.5
 sqlalchemy
 chardet
@@ -13,3 +13,5 @@ Flask-Restless
 marshmallow
 alembic
 python-debian
+flasgger
+flask_restful

