Skip to content

Commit

Permalink
Addressed all comments
Browse files Browse the repository at this point in the history
Signed-off-by: Junwei Dai <[email protected]>
  • Loading branch information
Junwei Dai committed Oct 8, 2024
1 parent f021ef8 commit af15a00
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
*/
public class ApiSpecFetcher {

Check warning on line 34 in src/main/java/org/opensearch/flowframework/util/ApiSpecFetcher.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/org/opensearch/flowframework/util/ApiSpecFetcher.java#L34

Added line #L34 was not covered by tests
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);
}

/**
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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<String> expectedRequiredParams = Arrays.asList("name", "type");
Expand All @@ -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<String> wrongRequiredParams = Arrays.asList("nonexistent_param");

Expand All @@ -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,
Expand All @@ -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
);
});

Expand All @@ -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
);
});

Expand Down

0 comments on commit af15a00

Please sign in to comment.