@@ -28,13 +28,30 @@ def __init__(self, args: TestArgs, test_manifest: TestManifest) -> None:
28
28
super ().__init__ (args , test_manifest )
29
29
logging .info ("Entering Smoke test for OpenSearch Bundle." )
30
30
31
- # TODO: Download the spec from https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml
32
- spec_file = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "smoke_tests_spec" , "opensearch-openapi.yaml" )
33
- self .spec_ = Spec .from_file_path (spec_file )
31
+ # Below URL is for the pre-release latest. In the future may consider use formal released spec when available.
32
+ self .spec_url = "https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml"
33
+ self .spec_local_path = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "smoke_tests_spec" , "opensearch-openapi-local.yaml" )
34
+ self .spec_download_path = os .path .join (os .path .dirname (os .path .abspath (__file__ )), "smoke_tests_spec" , "opensearch-openapi.yaml" )
35
+ self .spec_path = self .download_spec (self .spec_url , self .spec_local_path , self .spec_download_path )
36
+ self .spec_ = Spec .from_file_path (self .spec_path )
34
37
self .mimetype = {
35
38
"Content-Type" : "application/json"
36
39
}
37
- # self.openapi = openapi_core.OpenAPI.from_file_path(spec_file)
40
+
41
+ def download_spec (self , url : str , local_path : str , download_path : str ) -> str :
42
+ try :
43
+ response = requests .get (url , timeout = 10 )
44
+ if response .status_code == 200 :
45
+ with open (download_path , "wb" ) as file :
46
+ file .write (response .content )
47
+ logging .info (f"Downloaded latest spec from { url } " )
48
+ return download_path
49
+ else :
50
+ logging .info (f"Failed to fetch remote API spec, using local file: { local_path } " )
51
+ return local_path
52
+ except requests .RequestException :
53
+ logging .info (f"Could not reach { url } , using local file: { local_path } " )
54
+ return local_path
38
55
39
56
def validate_request_swagger (self , request : Any ) -> None :
40
57
request = RequestsOpenAPIRequest (request )
0 commit comments