Fixes Issue 20189: REST connector checks updated (#20736)

This commit is contained in:
chrisrayrayne 2025-04-15 06:54:57 +02:00 committed by GitHub
parent b59a37d244
commit b14f83940a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 17 deletions

View File

@ -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,18 +66,22 @@ 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:
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"
)

View File

@ -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