From 5adec708b524618dfdde0700aee87cf756fa88c9 Mon Sep 17 00:00:00 2001 From: dblock Date: Fri, 19 Jan 2024 14:24:31 -0500 Subject: [PATCH] Rebased to use public interfaces added in https://github.com/opensearch-project/OpenSearch/pull/11876. Signed-off-by: dblock --- .github/workflows/CI.yml | 7 - build.gradle | 2 +- .../api/action/api/APIResponse.java | 133 ------------------ .../{ => plugin}/api/APIPlugin.java | 33 +++-- .../{ => plugin}/api/RestAPIAction.java | 45 ++++-- .../api/action/api/APIAction.java | 2 +- .../api/action/api/APIRequest.java | 10 +- .../api/action/api/APIRequestBuilder.java | 2 +- .../plugin/api/action/api/APIResponse.java | 105 ++++++++++++++ .../api/action/api/TransportAPIAction.java | 12 +- .../api/action/api/package-info.java | 2 +- .../plugin/api/action/api/package.json | 6 + .../plugin-metadata/plugin-security.policy | 11 ++ .../to/plugin => plugin/api}/APIPluginIT.java | 28 +--- .../plugin => plugin/api}/APIPluginTests.java | 9 +- .../api/APIClientYamlTestSuiteIT.java | 6 +- .../resources/rest-api-spec/api/api.json | 38 ++--- .../resources/rest-api-spec/test/20_api.yml | 10 +- 18 files changed, 236 insertions(+), 225 deletions(-) delete mode 100644 src/main/java/org/opensearch/api/action/api/APIResponse.java rename src/main/java/org/opensearch/{ => plugin}/api/APIPlugin.java (73%) rename src/main/java/org/opensearch/{ => plugin}/api/RestAPIAction.java (64%) rename src/main/java/org/opensearch/{ => plugin}/api/action/api/APIAction.java (91%) rename src/main/java/org/opensearch/{ => plugin}/api/action/api/APIRequest.java (82%) rename src/main/java/org/opensearch/{ => plugin}/api/action/api/APIRequestBuilder.java (91%) create mode 100644 src/main/java/org/opensearch/plugin/api/action/api/APIResponse.java rename src/main/java/org/opensearch/{ => plugin}/api/action/api/TransportAPIAction.java (76%) rename src/main/java/org/opensearch/{ => plugin}/api/action/api/package-info.java (82%) create mode 100644 src/main/java/org/opensearch/plugin/api/action/api/package.json create mode 100644 src/main/plugin-metadata/plugin-security.policy rename src/test/java/org/opensearch/{path/to/plugin => plugin/api}/APIPluginIT.java (61%) rename src/test/java/org/opensearch/{path/to/plugin => plugin/api}/APIPluginTests.java (66%) rename src/yamlRestTest/java/org/opensearch/{ => plugin}/api/APIClientYamlTestSuiteIT.java (95%) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 7ed1fcc..cb8569b 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -32,10 +32,3 @@ jobs: - name: Build and Run Tests run: | ./gradlew build - # Generated by 'opensearch.pluginzip' custom gradle plugin - ./gradlew publishPluginZipPublicationToZipStagingRepository - - name: Update version to the next development iteration - if: matrix.os != 'windows-latest' - run: | - # Task to auto update version to the next development iteration - ./gradlew updateVersion -DnewVersion=3.1.0-SNAPSHOT diff --git a/build.gradle b/build.gradle index ff679ae..f9a82df 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ apply plugin: 'opensearch.pluginzip' def pluginName = 'opensearch-api' def pluginDescription = 'OpenSearch API plugin.' def projectPath = 'org.opensearch' -def pathToPlugin = 'api' +def pathToPlugin = 'plugin.api' def pluginClassName = 'APIPlugin' group = "APIPluginGroup" diff --git a/src/main/java/org/opensearch/api/action/api/APIResponse.java b/src/main/java/org/opensearch/api/action/api/APIResponse.java deleted file mode 100644 index 0744d9c..0000000 --- a/src/main/java/org/opensearch/api/action/api/APIResponse.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * SPDX-License-Identifier: Apache-2.0 - * - * The OpenSearch Contributors require contributions made to - * this file be licensed under the Apache-2.0 license or a - * compatible open source license. - */ - -package org.opensearch.api.action.api; - -import org.opensearch.Build; -import org.opensearch.Version; -import org.opensearch.core.ParseField; -import org.opensearch.core.action.ActionResponse; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.common.io.stream.StreamOutput; -import org.opensearch.core.xcontent.ObjectParser; -import org.opensearch.core.xcontent.ToXContentObject; -import org.opensearch.core.xcontent.XContentBuilder; -import org.opensearch.core.xcontent.XContentParser; - -import java.io.IOException; -import java.util.Objects; - -public class APIResponse extends ActionResponse implements ToXContentObject { - - private Version version; - private Build build; - - APIResponse() { - - } - - APIResponse(StreamInput in) throws IOException { - super(in); - version = in.readVersion(); - build = in.readBuild(); - } - - APIResponse(Version version, Build build) { - this.version = version; - this.build = build; - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeVersion(version); - out.writeBuild(build); - } - - public Version getVersion() { - return version; - } - - public Build getBuild() { - return build; - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - builder.startObject("version") - .field("distribution", build.getDistribution()) - .field("number", build.getQualifiedVersion()) - .field("build_type", build.type().displayName()) - .field("build_hash", build.hash()) - .field("build_date", build.date()) - .field("build_snapshot", build.isSnapshot()) - .field("lucene_version", version.luceneVersion.toString()) - .field("minimum_wire_compatibility_version", version.minimumCompatibilityVersion().toString()) - .field("minimum_index_compatibility_version", version.minimumIndexCompatibilityVersion().toString()) - .endObject(); - builder.endObject(); - return builder; - } - - private static final ObjectParser PARSER = new ObjectParser<>( - APIResponse.class.getName(), - true, - APIResponse::new - ); - - static { - PARSER.declareObject((response, value) -> { - final String buildType = (String) value.get("build_type"); - response.build = new Build( - buildType == null ? Build.Type.UNKNOWN : Build.Type.fromDisplayName(buildType, false), - (String) value.get("build_hash"), - (String) value.get("build_date"), - (boolean) value.get("build_snapshot"), - (String) value.get("number"), - (String) value.get("distribution") - ); - response.version = Version.fromString( - ((String) value.get("number")).replace("-SNAPSHOT", "").replaceFirst("-(alpha\\d+|beta\\d+|rc\\d+)", "") - ); - }, (parser, context) -> parser.map(), new ParseField("version")); - } - - public static APIResponse fromXContent(XContentParser parser) { - return PARSER.apply(parser, null); - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - APIResponse other = (APIResponse) o; - return Objects.equals(version, other.version) - && Objects.equals(build, other.build); - } - - @Override - public int hashCode() { - return Objects.hash(version, build); - } - - @Override - public String toString() { - return "APIResponse{" - + '\'' - + ", version=" - + version - + '\'' - + ", build=" - + build - + '}'; - } -} \ No newline at end of file diff --git a/src/main/java/org/opensearch/api/APIPlugin.java b/src/main/java/org/opensearch/plugin/api/APIPlugin.java similarity index 73% rename from src/main/java/org/opensearch/api/APIPlugin.java rename to src/main/java/org/opensearch/plugin/api/APIPlugin.java index a8682cf..019d4ff 100644 --- a/src/main/java/org/opensearch/api/APIPlugin.java +++ b/src/main/java/org/opensearch/plugin/api/APIPlugin.java @@ -6,44 +6,55 @@ * compatible open source license. */ -package org.opensearch.api; - -import static java.util.Collections.singletonList; - -import java.util.List; -import java.util.function.Supplier; +package org.opensearch.plugin.api; import org.opensearch.action.ActionRequest; -import org.opensearch.api.action.api.APIAction; -import org.opensearch.api.action.api.TransportAPIAction; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; +import org.opensearch.cluster.node.DiscoveryNodes; import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.IndexScopedSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.settings.SettingsFilter; import org.opensearch.core.action.ActionResponse; +import org.opensearch.plugin.api.action.api.APIAction; +import org.opensearch.plugin.api.action.api.TransportAPIAction; import org.opensearch.plugins.ActionPlugin; import org.opensearch.plugins.Plugin; import org.opensearch.rest.RestController; +import org.opensearch.rest.RestHandler; + +import java.util.List; +import java.util.function.Supplier; + +import static java.util.Collections.singletonList; /** * A plugin that returns the OpenAPI spec for the current OpenSearch instance. */ public class APIPlugin extends Plugin implements ActionPlugin { + /** + * Instantiate this plugin. + */ + public APIPlugin() { + + } + @Override public List> getActions() { return singletonList(new ActionHandler<>(APIAction.INSTANCE, TransportAPIAction.class)); } @Override - public List getRestHandlers(final Settings settings, + public List getRestHandlers( + final Settings settings, final RestController restController, final ClusterSettings clusterSettings, final IndexScopedSettings indexScopedSettings, final SettingsFilter settingsFilter, final IndexNameExpressionResolver indexNameExpressionResolver, - final Supplier nodesInCluster) { + final Supplier nodesInCluster + ) { - return singletonList(new RestAPIAction()); + return singletonList(new RestAPIAction(restController)); } } \ No newline at end of file diff --git a/src/main/java/org/opensearch/api/RestAPIAction.java b/src/main/java/org/opensearch/plugin/api/RestAPIAction.java similarity index 64% rename from src/main/java/org/opensearch/api/RestAPIAction.java rename to src/main/java/org/opensearch/plugin/api/RestAPIAction.java index 19dd459..f8162f7 100644 --- a/src/main/java/org/opensearch/api/RestAPIAction.java +++ b/src/main/java/org/opensearch/plugin/api/RestAPIAction.java @@ -6,48 +6,69 @@ * compatible open source license. */ -package org.opensearch.api; +package org.opensearch.plugin.api; -import java.io.IOException; -import java.util.List; - -import org.opensearch.api.action.api.APIAction; -import org.opensearch.api.action.api.APIRequest; -import org.opensearch.api.action.api.APIResponse; import org.opensearch.client.node.NodeClient; import org.opensearch.core.rest.RestStatus; import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.plugin.api.action.api.APIAction; +import org.opensearch.plugin.api.action.api.APIRequest; +import org.opensearch.plugin.api.action.api.APIResponse; import org.opensearch.rest.BaseRestHandler; import org.opensearch.rest.BytesRestResponse; +import org.opensearch.rest.RestController; import org.opensearch.rest.RestRequest; import org.opensearch.rest.RestResponse; import org.opensearch.rest.action.RestBuilderListener; -import static org.opensearch.rest.RestRequest.Method.GET; +import java.io.IOException; +import java.util.List; + import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableList; +import static org.opensearch.rest.RestRequest.Method.GET; /** * A REST handler. */ public class RestAPIAction extends BaseRestHandler { + RestController restController; + + RestAPIAction(RestController restController) { + this.restController = restController; + } + + /** + * + * @return + */ @Override public String getName() { return "api"; } + /** + * + * @return + */ @Override - public List routes() { - return unmodifiableList(asList( - new Route(GET, "/_plugins/api") - )); + public List routes() { + return unmodifiableList(asList(new Route(GET, "/_plugins/api"))); } + /** + * + * @param request the request to execute + * @param client client for executing actions on the local node + * @return + * @throws IOException + */ @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { return channel -> client.execute(APIAction.INSTANCE, new APIRequest(), new RestBuilderListener(channel) { @Override public RestResponse buildResponse(APIResponse response, XContentBuilder builder) throws Exception { + response.setRestController(restController); response.toXContent(builder, request); return new BytesRestResponse(RestStatus.OK, builder); } diff --git a/src/main/java/org/opensearch/api/action/api/APIAction.java b/src/main/java/org/opensearch/plugin/api/action/api/APIAction.java similarity index 91% rename from src/main/java/org/opensearch/api/action/api/APIAction.java rename to src/main/java/org/opensearch/plugin/api/action/api/APIAction.java index 668f4da..2315891 100644 --- a/src/main/java/org/opensearch/api/action/api/APIAction.java +++ b/src/main/java/org/opensearch/plugin/api/action/api/APIAction.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.api.action.api; +package org.opensearch.plugin.api.action.api; import org.opensearch.action.ActionType; diff --git a/src/main/java/org/opensearch/api/action/api/APIRequest.java b/src/main/java/org/opensearch/plugin/api/action/api/APIRequest.java similarity index 82% rename from src/main/java/org/opensearch/api/action/api/APIRequest.java rename to src/main/java/org/opensearch/plugin/api/action/api/APIRequest.java index c38c607..5970627 100644 --- a/src/main/java/org/opensearch/api/action/api/APIRequest.java +++ b/src/main/java/org/opensearch/plugin/api/action/api/APIRequest.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.api.action.api; +package org.opensearch.plugin.api.action.api; import org.opensearch.action.ActionRequest; import org.opensearch.action.ActionRequestValidationException; @@ -16,8 +16,16 @@ public class APIRequest extends ActionRequest { + /** + * + */ public APIRequest() {} + /** + * + * @param in + * @throws IOException + */ APIRequest(StreamInput in) throws IOException { super(in); } diff --git a/src/main/java/org/opensearch/api/action/api/APIRequestBuilder.java b/src/main/java/org/opensearch/plugin/api/action/api/APIRequestBuilder.java similarity index 91% rename from src/main/java/org/opensearch/api/action/api/APIRequestBuilder.java rename to src/main/java/org/opensearch/plugin/api/action/api/APIRequestBuilder.java index 272accf..65018ea 100644 --- a/src/main/java/org/opensearch/api/action/api/APIRequestBuilder.java +++ b/src/main/java/org/opensearch/plugin/api/action/api/APIRequestBuilder.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.api.action.api; +package org.opensearch.plugin.api.action.api; import org.opensearch.action.ActionRequestBuilder; import org.opensearch.client.OpenSearchClient; diff --git a/src/main/java/org/opensearch/plugin/api/action/api/APIResponse.java b/src/main/java/org/opensearch/plugin/api/action/api/APIResponse.java new file mode 100644 index 0000000..56d1a08 --- /dev/null +++ b/src/main/java/org/opensearch/plugin/api/action/api/APIResponse.java @@ -0,0 +1,105 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.plugin.api.action.api; + +import org.opensearch.Build; +import org.opensearch.Version; +import org.opensearch.action.main.MainResponse; +import org.opensearch.core.action.ActionResponse; +import org.opensearch.core.common.io.stream.StreamInput; +import org.opensearch.core.common.io.stream.StreamOutput; +import org.opensearch.core.xcontent.ToXContentObject; +import org.opensearch.core.xcontent.XContentBuilder; +import org.opensearch.rest.MethodHandlers; +import org.opensearch.rest.RestController; +import org.opensearch.rest.RestRequest; + +import java.io.IOException; +import java.util.Iterator; +import java.util.Locale; + +public class APIResponse extends ActionResponse implements ToXContentObject { + + private Version version; + private Build build; + private RestController restController; + + APIResponse() { + + } + + APIResponse(StreamInput in) throws IOException { + super(in); + version = in.readVersion(); + build = in.readBuild(); + } + + APIResponse(Version version, Build build) { + this.version = version; + this.build = build; + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeVersion(version); + out.writeBuild(build); + } + + public Version getVersion() { + return version; + } + + public Build getBuild() { + return build; + } + + public void setRestController(RestController restController) { + this.restController = restController; + } + + @Override + public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { + builder.startObject(); + + builder.field("openapi", "3.0.1"); + + builder.startObject("info") + .field("title", build.getDistribution()) + .field("description", MainResponse.TAGLINE) + .field("version", build.getQualifiedVersion()) + .endObject(); + + builder.startObject("paths"); + + Iterator methodHandlers = restController.getAllHandlers(); + while (methodHandlers.hasNext()) { + MethodHandlers handlers = methodHandlers.next(); + builder.startObject(handlers.getPath()); + for (RestRequest.Method method : handlers.getValidMethods()) { + builder.startObject(method.name().toLowerCase(Locale.ROOT)) + // .field("summary", "") + // .field("description", "") + // .startObject("responses", "") + // .endObject()) + .endObject(); + } + builder.endObject(); + } + + builder.endObject(); + + builder.endObject(); + return builder; + } + + @Override + public String toString() { + return "APIResponse{" + '\'' + ", version=" + version + '\'' + ", build=" + build + '}'; + } +} \ No newline at end of file diff --git a/src/main/java/org/opensearch/api/action/api/TransportAPIAction.java b/src/main/java/org/opensearch/plugin/api/action/api/TransportAPIAction.java similarity index 76% rename from src/main/java/org/opensearch/api/action/api/TransportAPIAction.java rename to src/main/java/org/opensearch/plugin/api/action/api/TransportAPIAction.java index aa80a56..aca5eeb 100644 --- a/src/main/java/org/opensearch/api/action/api/TransportAPIAction.java +++ b/src/main/java/org/opensearch/plugin/api/action/api/TransportAPIAction.java @@ -6,7 +6,7 @@ * compatible open source license. */ -package org.opensearch.api.action.api; +package org.opensearch.plugin.api.action.api; import org.opensearch.Build; import org.opensearch.Version; @@ -21,18 +21,12 @@ public class TransportAPIAction extends HandledTransportAction { @Inject - public TransportAPIAction( - Settings settings, - TransportService transportService, - ActionFilters actionFilters - ) { + public TransportAPIAction(Settings settings, TransportService transportService, ActionFilters actionFilters) { super(APIAction.NAME, transportService, actionFilters, APIRequest::new); } @Override protected void doExecute(Task task, APIRequest request, ActionListener listener) { - listener.onResponse( - new APIResponse(Version.CURRENT, Build.CURRENT) - ); + listener.onResponse(new APIResponse(Version.CURRENT, Build.CURRENT)); } } \ No newline at end of file diff --git a/src/main/java/org/opensearch/api/action/api/package-info.java b/src/main/java/org/opensearch/plugin/api/action/api/package-info.java similarity index 82% rename from src/main/java/org/opensearch/api/action/api/package-info.java rename to src/main/java/org/opensearch/plugin/api/action/api/package-info.java index 99a5916..32560ad 100644 --- a/src/main/java/org/opensearch/api/action/api/package-info.java +++ b/src/main/java/org/opensearch/plugin/api/action/api/package-info.java @@ -6,4 +6,4 @@ * compatible open source license. */ -package org.opensearch.api.action.api; \ No newline at end of file +package org.opensearch.plugin.api.action.api; \ No newline at end of file diff --git a/src/main/java/org/opensearch/plugin/api/action/api/package.json b/src/main/java/org/opensearch/plugin/api/action/api/package.json new file mode 100644 index 0000000..6a9b706 --- /dev/null +++ b/src/main/java/org/opensearch/plugin/api/action/api/package.json @@ -0,0 +1,6 @@ +{ + "name": "api", + "version": "1.0.0", + "dependencies": { + } +} diff --git a/src/main/plugin-metadata/plugin-security.policy b/src/main/plugin-metadata/plugin-security.policy new file mode 100644 index 0000000..ff07a71 --- /dev/null +++ b/src/main/plugin-metadata/plugin-security.policy @@ -0,0 +1,11 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +grant { + +}; \ No newline at end of file diff --git a/src/test/java/org/opensearch/path/to/plugin/APIPluginIT.java b/src/test/java/org/opensearch/plugin/api/APIPluginIT.java similarity index 61% rename from src/test/java/org/opensearch/path/to/plugin/APIPluginIT.java rename to src/test/java/org/opensearch/plugin/api/APIPluginIT.java index 15a74a6..ae836c9 100644 --- a/src/test/java/org/opensearch/path/to/plugin/APIPluginIT.java +++ b/src/test/java/org/opensearch/plugin/api/APIPluginIT.java @@ -5,20 +5,14 @@ * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ -package org.opensearch.api; +package org.opensearch.plugin.api; import com.carrotsearch.randomizedtesting.annotations.ThreadLeakScope; + import org.apache.hc.core5.http.ParseException; import org.apache.hc.core5.http.io.entity.EntityUtils; -import org.opensearch.Version; -import org.opensearch.action.search.SearchResponse; -import org.opensearch.api.APIPlugin; -import org.opensearch.api.action.api.APIResponse; import org.opensearch.client.Request; import org.opensearch.client.Response; -import org.opensearch.common.xcontent.json.JsonXContent; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.xcontent.MediaTypeRegistry; import org.opensearch.plugins.Plugin; import org.opensearch.test.OpenSearchIntegTestCase; @@ -27,9 +21,6 @@ import java.util.Collection; import java.util.Collections; - -import static org.hamcrest.Matchers.containsString; - @ThreadLeakScope(ThreadLeakScope.Scope.NONE) @OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.SUITE) public class APIPluginIT extends OpenSearchIntegTestCase { @@ -40,22 +31,17 @@ protected Collection> nodePlugins() { } public void testPluginInstalled() throws IOException, ParseException { - Response response = createRestClient().performRequest(new Request("GET", "/_cat/plugins")); + Response response = getRestClient().performRequest(new Request("GET", "/_cat/plugins")); String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); - logger.info("response body: {}", body); + logger.info("response body: {}", body.toString()); assertTrue(body.contains("api")); } public void testPluginGetAPI() throws IOException, ParseException { - Response response = createRestClient().performRequest(new Request("GET", "/_plugins/api")); + Response response = getRestClient().performRequest(new Request("GET", "/_plugins/api")); String body = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); logger.info("response body: {}", body); - - APIResponse apiResponse = APIResponse.fromXContent( - createParser(JsonXContent.jsonXContent, response.getEntity().getContent()) - ); - - assertEquals(apiResponse.getVersion(), Version.CURRENT); + assertTrue(body.startsWith("{\"openapi\":\"3.0.1\"")); } -} +} \ No newline at end of file diff --git a/src/test/java/org/opensearch/path/to/plugin/APIPluginTests.java b/src/test/java/org/opensearch/plugin/api/APIPluginTests.java similarity index 66% rename from src/test/java/org/opensearch/path/to/plugin/APIPluginTests.java rename to src/test/java/org/opensearch/plugin/api/APIPluginTests.java index e16c3a3..c7cd20b 100644 --- a/src/test/java/org/opensearch/path/to/plugin/APIPluginTests.java +++ b/src/test/java/org/opensearch/plugin/api/APIPluginTests.java @@ -5,10 +5,13 @@ * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ -package org.opensearch.api; +package org.opensearch.plugin.api; import org.opensearch.test.OpenSearchTestCase; public class APIPluginTests extends OpenSearchTestCase { - // Add unit tests for your plugin -} + public void testConstructor() { + APIPlugin plugin = new APIPlugin(); + assertNotNull(plugin); + } +} \ No newline at end of file diff --git a/src/yamlRestTest/java/org/opensearch/api/APIClientYamlTestSuiteIT.java b/src/yamlRestTest/java/org/opensearch/plugin/api/APIClientYamlTestSuiteIT.java similarity index 95% rename from src/yamlRestTest/java/org/opensearch/api/APIClientYamlTestSuiteIT.java rename to src/yamlRestTest/java/org/opensearch/plugin/api/APIClientYamlTestSuiteIT.java index a16f39c..0bfd831 100644 --- a/src/yamlRestTest/java/org/opensearch/api/APIClientYamlTestSuiteIT.java +++ b/src/yamlRestTest/java/org/opensearch/plugin/api/APIClientYamlTestSuiteIT.java @@ -5,14 +5,14 @@ * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ -package org.opensearch.api; +package org.opensearch.plugin.api; import com.carrotsearch.randomizedtesting.annotations.Name; import com.carrotsearch.randomizedtesting.annotations.ParametersFactory; + import org.opensearch.test.rest.yaml.ClientYamlTestCandidate; import org.opensearch.test.rest.yaml.OpenSearchClientYamlSuiteTestCase; - public class APIClientYamlTestSuiteIT extends OpenSearchClientYamlSuiteTestCase { public APIClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandidate) { @@ -23,4 +23,4 @@ public APIClientYamlTestSuiteIT(@Name("yaml") ClientYamlTestCandidate testCandid public static Iterable parameters() throws Exception { return OpenSearchClientYamlSuiteTestCase.createParameters(); } -} +} \ No newline at end of file diff --git a/src/yamlRestTest/resources/rest-api-spec/api/api.json b/src/yamlRestTest/resources/rest-api-spec/api/api.json index 763b201..31abeb7 100644 --- a/src/yamlRestTest/resources/rest-api-spec/api/api.json +++ b/src/yamlRestTest/resources/rest-api-spec/api/api.json @@ -1,20 +1,20 @@ { - "api":{ - "documentation":{ - "url":"", - "description":"Returns REST API spec." - }, - "stability":"experimental", - "url":{ - "paths":[ - { - "path":"/_plugins/api", - "methods":[ - "GET" - ] - } - ] - }, - "params":{} - } - } \ No newline at end of file + "api":{ + "documentation":{ + "url":"", + "description":"Returns REST API spec." + }, + "stability":"experimental", + "url":{ + "paths":[ + { + "path":"/_plugins/api", + "methods":[ + "GET" + ] + } + ] + }, + "params":{} + } +} \ No newline at end of file diff --git a/src/yamlRestTest/resources/rest-api-spec/test/20_api.yml b/src/yamlRestTest/resources/rest-api-spec/test/20_api.yml index 2e62059..b63c794 100644 --- a/src/yamlRestTest/resources/rest-api-spec/test/20_api.yml +++ b/src/yamlRestTest/resources/rest-api-spec/test/20_api.yml @@ -2,5 +2,11 @@ - do: api: {} - - match: { version.distribution: "opensearch" } - - match: { version.number: /.*-SNAPSHOT/ } + - match: { info.title: "opensearch" } + - match: { info.version: /.*-SNAPSHOT/ } + - match: { info.description: "The OpenSearch Project: https://opensearch.org/" } + + - match: { paths./_plugins/api.get: {} } + + - match: { "paths./{index}/_upgrade.post": {} } + - match: { "paths./{index}/_upgrade.get": {} }