From 1ab8c20d92b4690fb25433fec356c829ec35c6a5 Mon Sep 17 00:00:00 2001 From: Jorgen Evens Date: Tue, 15 Mar 2022 01:52:08 +0100 Subject: [PATCH] fix(ingest): handle endpoints without 200 response in openapi (#4332) --- .../src/datahub/ingestion/source/openapi_parser.py | 8 ++++++-- metadata-ingestion/tests/unit/test_openapi.py | 7 +++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/metadata-ingestion/src/datahub/ingestion/source/openapi_parser.py b/metadata-ingestion/src/datahub/ingestion/source/openapi_parser.py index c2f87b55d88717..830b6562755eb7 100755 --- a/metadata-ingestion/src/datahub/ingestion/source/openapi_parser.py +++ b/metadata-ingestion/src/datahub/ingestion/source/openapi_parser.py @@ -120,10 +120,14 @@ def get_endpoints(sw_dict: dict) -> dict: # noqa: C901 # will track only the "get" methods, which are the ones that give us data if "get" in p_o.keys(): - try: + if "200" in p_o["get"]["responses"].keys(): base_res = p_o["get"]["responses"]["200"] - except KeyError: # if you read a plain yml file the 200 will be an integer + elif 200 in p_o["get"]["responses"].keys(): + # if you read a plain yml file the 200 will be an integer base_res = p_o["get"]["responses"][200] + else: + # the endpoint does not have a 200 response + continue if "description" in p_o["get"].keys(): desc = p_o["get"]["description"] diff --git a/metadata-ingestion/tests/unit/test_openapi.py b/metadata-ingestion/tests/unit/test_openapi.py index b4b61e685718be..b6c14426dbb38f 100644 --- a/metadata-ingestion/tests/unit/test_openapi.py +++ b/metadata-ingestion/tests/unit/test_openapi.py @@ -261,6 +261,13 @@ class TestGetEndpoints(unittest.TestCase): } ] } + /redirect: + get: + operationId: redirectSomewhere + summary: Redirect to a different endpoint + responses: + '302': + description: 302 response /v2: get: operationId: getVersionDetailsv2