diff --git a/ingestion/src/metadata/ingestion/source/api/rest/connection.py b/ingestion/src/metadata/ingestion/source/api/rest/connection.py index 8b534fc24f8..d8d3bed10ed 100644 --- a/ingestion/src/metadata/ingestion/source/api/rest/connection.py +++ b/ingestion/src/metadata/ingestion/source/api/rest/connection.py @@ -30,8 +30,6 @@ from metadata.ingestion.connections.test_connections import test_connection_step from metadata.ingestion.ometa.ometa_api import OpenMetadata from metadata.utils.constants import THREE_MIN -ACCEPTED_CONTENT_TYPES = ["application/json", "application/vnd.oai.openapi+json"] - class SchemaURLError(Exception): """ @@ -68,21 +66,25 @@ def test_connection( """ def custom_url_exec(): - if client.status_code == 200 and any( - content_type in client.headers.get("content-type") - for content_type in ACCEPTED_CONTENT_TYPES - ): + if client.status_code == 200: return [] raise SchemaURLError( - "Failed to parse JSON schema url. Please check if provided url is valid JSON schema." + "Failed to connect to the JSON schema url. Please check the url and credentials. Status Code was: " + + str(client.status_code) ) def custom_schema_exec(): - if client.json().get("openapi") is not None: - return [] - raise InvalidOpenAPISchemaError( - "Provided schema is not valid OpenAPI JSON schema" - ) + try: + if client.json() is not None and client.json().get("openapi") is not None: + return [] + + raise InvalidOpenAPISchemaError( + "Provided schema is not valid OpenAPI JSON schema" + ) + except: + raise InvalidOpenAPISchemaError( + "Provided schema is not valid OpenAPI JSON schema" + ) test_fn = {"CheckURL": custom_url_exec, "CheckSchema": custom_schema_exec} diff --git a/ingestion/tests/unit/topology/api/test_rest.py b/ingestion/tests/unit/topology/api/test_rest.py index e519fcb0cf3..8540df3ee87 100644 --- a/ingestion/tests/unit/topology/api/test_rest.py +++ b/ingestion/tests/unit/topology/api/test_rest.py @@ -169,11 +169,6 @@ class RESTTest(TestCase): ) assert collection_request == EXPECTED_COLLECTION_REQUEST - def test_json_schema(self): - """test json schema""" - schema_content_type = self.rest_source.connection.headers.get("content-type") - assert "application/json" in schema_content_type - def test_all_collections(self): with patch.object( self.rest_source.connection, "json", return_value=MOCK_JSON_RESPONSE