From 164754ef6d2cfd583e8a82a422c2ddbaab5dd0b6 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 1 Dec 2020 20:55:30 +0100 Subject: [PATCH 1/5] Fix dependency on auth_provider --- app.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 3515974..2510298 100644 --- a/app.py +++ b/app.py @@ -68,7 +68,7 @@ class Oas3Handler(tornado.web.RequestHandler, metaclass=ABCMeta): self.finish() -def make_app(_auth_provider=None): +def make_app(): version_path = r"/v[0-9]" return tornado.web.Application([ (version_path + r"/health", HealthHandler), @@ -81,7 +81,7 @@ def main(): # Setup - util.run_tornado_server(make_app(auth_provider), + util.run_tornado_server(make_app(), server_port=port) # Teardown -- 2.45.2 From 114c6327976c9e93e5a22097c3284febb875ae2b Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 1 Dec 2020 20:55:49 +0100 Subject: [PATCH 2/5] Add validate handler --- app.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app.py b/app.py index 2510298..f9300df 100644 --- a/app.py +++ b/app.py @@ -68,6 +68,21 @@ class Oas3Handler(tornado.web.RequestHandler, metaclass=ABCMeta): self.finish() +class ValidateHandler(tornado.web.RequestHandler, metaclass=ABCMeta): + def post(self): + self.set_header("Content-Type", "application/json") + + entity = self.request.body.decode() + + # TODO call validator + validation_result = { + "valid": "true" + } + + self.write(validation_result) + self.finish() + + def make_app(): version_path = r"/v[0-9]" return tornado.web.Application([ -- 2.45.2 From 74d6e2ea5cd92d88b249e4fe998d2ab69cb9304b Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 1 Dec 2020 20:56:21 +0100 Subject: [PATCH 3/5] Integrate Validate Handler with make_app --- app.py | 1 + 1 file changed, 1 insertion(+) diff --git a/app.py b/app.py index f9300df..96a27ef 100644 --- a/app.py +++ b/app.py @@ -88,6 +88,7 @@ def make_app(): return tornado.web.Application([ (version_path + r"/health", HealthHandler), (version_path + r"/oas3", Oas3Handler), + (version_path + r"/validate", ValidateHandler), ]) -- 2.45.2 From 9dc82b769bbf3bd6e43fc88a5cee4e85b86a1e22 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 1 Dec 2020 21:03:11 +0100 Subject: [PATCH 4/5] Add simple validation test case --- test.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test.py b/test.py index 84a6315..ee268d3 100644 --- a/test.py +++ b/test.py @@ -38,5 +38,25 @@ class TestBaseAPI(tornado.testing.AsyncHTTPTestCase): self.assertEqual(response.body.decode(), oas3f.read(), "OAS3 content differs from spec file!") +class TestValidation(tornado.testing.AsyncHTTPTestCase): + """Validation test cases""" + def get_app(self): + return make_app() + + def test_null_validation(self): + entity = {} + + response = self.fetch('/v0/validate', + method='POST', + body=json.dumps(entity)) + + self.assertEqual(200, response.code, "Validation must always return 200") + + validation_result = json.loads(response.body.decode()) + + self.assertIn('valid', validation_result, "Key 'valid' expected in validation result") + self.assertTrue(validation_result['valid'], "Validation result is expected to be valid==true") + + if __name__ == "__main__": unittest.main() -- 2.45.2 From b8f8a91e4a1240bf7db0f34b9493d354b8e788f3 Mon Sep 17 00:00:00 2001 From: Stefan Haun Date: Tue, 1 Dec 2020 21:08:01 +0100 Subject: [PATCH 5/5] Add type to validation findings --- OAS3.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OAS3.yml b/OAS3.yml index 47710e3..6db74eb 100644 --- a/OAS3.yml +++ b/OAS3.yml @@ -93,6 +93,9 @@ components: type: string message: type: string + "type": + type: string + enum: ["ERR", "WARN"] responses: AuthenticationRequired: description: Authentication is required (401) -- 2.45.2