#111 Create API documentation
Opened 5 years ago by naiieandrade. Modified 5 years ago
naiieandrade/kiskadee master  into  master

empty or binary file added
file added
+210
@@ -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)

file modified
+3 -1
@@ -1,5 +1,5 @@ 

  psutil

- psycopg2

+ psycopg2-binary

  firehose>=0.5

  sqlalchemy

  chardet
@@ -13,3 +13,5 @@ 

  marshmallow

  alembic

  python-debian

+ flasgger

+ flask_restful