diff --git a/src/main/java/org/opensearch/flowframework/util/ApiSpecFetcher.java b/src/main/java/org/opensearch/flowframework/util/ApiSpecFetcher.java index e393587b..80be71b6 100644 --- a/src/main/java/org/opensearch/flowframework/util/ApiSpecFetcher.java +++ b/src/main/java/org/opensearch/flowframework/util/ApiSpecFetcher.java @@ -33,12 +33,12 @@ */ public class ApiSpecFetcher { private static final Logger logger = LogManager.getLogger(ApiSpecFetcher.class); - private static final ParseOptions OPENAPI_PARSER = new ParseOptions(); - private static final OpenAPIV3Parser PARSER = new OpenAPIV3Parser(); + private static final ParseOptions PARSE_OPTIONS = new ParseOptions(); + private static final OpenAPIV3Parser OPENAPI_PARSER = new OpenAPIV3Parser(); static { - OPENAPI_PARSER.setResolve(true); - OPENAPI_PARSER.setResolveFully(true); + PARSE_OPTIONS.setResolve(true); + PARSE_OPTIONS.setResolveFully(true); } /** @@ -50,7 +50,7 @@ public class ApiSpecFetcher { */ public static OpenAPI fetchApiSpec(String apiSpecUri) { logger.info("Parsing API spec from URI: {}", apiSpecUri); - SwaggerParseResult result = PARSER.readLocation(apiSpecUri, null, OPENAPI_PARSER); + SwaggerParseResult result = OPENAPI_PARSER.readLocation(apiSpecUri, null, PARSE_OPTIONS); OpenAPI openApi = result.getOpenAPI(); if (openApi == null) { diff --git a/src/test/java/org/opensearch/flowframework/util/ApiSpecFetcherTests.java b/src/test/java/org/opensearch/flowframework/util/ApiSpecFetcherTests.java index b7d70b58..fb60ae08 100644 --- a/src/test/java/org/opensearch/flowframework/util/ApiSpecFetcherTests.java +++ b/src/test/java/org/opensearch/flowframework/util/ApiSpecFetcherTests.java @@ -19,6 +19,10 @@ import io.swagger.v3.oas.models.OpenAPI; import static org.opensearch.flowframework.common.CommonValue.ML_COMMONS_API_SPEC_YAML_URI; +import static org.opensearch.rest.RestRequest.Method.DELETE; +import static org.opensearch.rest.RestRequest.Method.PATCH; +import static org.opensearch.rest.RestRequest.Method.POST; +import static org.opensearch.rest.RestRequest.Method.PUT; public class ApiSpecFetcherTests extends OpenSearchTestCase { @@ -48,7 +52,7 @@ public void testFetchApiSpecThrowsException() throws Exception { public void testCompareRequiredFieldsSuccess() throws Exception { String path = "/_plugins/_ml/agents/_register"; - RestRequest.Method method = RestRequest.Method.POST; + RestRequest.Method method = POST; // Assuming REGISTER_AGENT step in the enum has these required fields List expectedRequiredParams = Arrays.asList("name", "type"); @@ -61,7 +65,7 @@ public void testCompareRequiredFieldsSuccess() throws Exception { public void testCompareRequiredFieldsFailure() throws Exception { String path = "/_plugins/_ml/agents/_register"; - RestRequest.Method method = RestRequest.Method.POST; + RestRequest.Method method = POST; List wrongRequiredParams = Arrays.asList("nonexistent_param"); @@ -73,7 +77,7 @@ public void testCompareRequiredFieldsFailure() throws Exception { public void testCompareRequiredFieldsThrowsException() throws Exception { String invalidUri = "http://invalid-url.com/fail.yaml"; String path = "/_plugins/_ml/agents/_register"; - RestRequest.Method method = RestRequest.Method.POST; + RestRequest.Method method = PUT; Exception exception = expectThrows( Exception.class, @@ -90,7 +94,7 @@ public void testUnsupportedMethodException() throws IllegalArgumentException { List.of("name", "type"), ML_COMMONS_API_SPEC_YAML_URI, "/_plugins/_ml/agents/_register", - RestRequest.Method.PATCH + PATCH ); }); @@ -103,7 +107,7 @@ public void testNoOperationFoundException() throws Exception { List.of("name", "type"), ML_COMMONS_API_SPEC_YAML_URI, "/_plugins/_ml/agents/_register", - RestRequest.Method.DELETE // PATCH should be unsupported + DELETE ); });