diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/knn_search.json b/rest-api-spec/src/main/resources/rest-api-spec/api/knn_search.json index f1f888e02bbbf..6faee49d480be 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/knn_search.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/knn_search.json @@ -5,6 +5,10 @@ "description":"Performs a kNN search." }, "stability":"experimental", + "deprecated" : { + "version" : "8.4.0", + "description" : "The kNN search API has been replaced by the `knn` option in the search API." + }, "visibility":"public", "headers":{ "accept": [ "application/json"], diff --git a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApi.java b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApi.java index c936ff951664b..c68b54ca33f8a 100644 --- a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApi.java +++ b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApi.java @@ -28,12 +28,13 @@ public class ClientYamlSuiteRestApi { private final String location; private final String name; - private Set paths = new LinkedHashSet<>(); - private Map params = new HashMap<>(); + private final Set paths = new LinkedHashSet<>(); + private final Map params = new HashMap<>(); private Body body = Body.NOT_SUPPORTED; private Stability stability; private Visibility visibility; private String featureFlag; + private List responseMimeTypes; private List requestMimeTypes; diff --git a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java index 9dfa28f1d2b2d..43b50fb8b7400 100644 --- a/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java +++ b/test/yaml-rest-runner/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java @@ -86,6 +86,14 @@ public ClientYamlSuiteRestApi parse(String location, XContentParser parser) thro } else if ("feature_flag".equals(parser.currentName())) { parser.nextToken(); restApi.setFeatureFlag(parser.textOrNull()); + } else if ("deprecated".equals(parser.currentName())) { + if (parser.nextToken() != XContentParser.Token.START_OBJECT) { + throw new ParsingException( + parser.getTokenLocation(), + apiName + " API: expected [deprecated] field in rest api definition to hold an object" + ); + } + parser.skipChildren(); } else if ("url".equals(parser.currentName())) { String currentFieldName = null; assert parser.nextToken() == XContentParser.Token.START_OBJECT; diff --git a/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java b/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java index 36babefd2fdd5..38c6042d40e2b 100644 --- a/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java +++ b/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserFailingTests.java @@ -88,6 +88,14 @@ public void testBrokenSpecShouldThrowUsefulExceptionWhenParsingFailsOnParams() t ); } + public void testBrokenSpecShouldThrowUsefulExceptionWhenParsingFailsOnDeprecated() throws Exception { + parseAndExpectParsingException( + BROKEN_DEPRECATED_DEF, + "indices.get_template.json", + "indices.get_template API: expected [deprecated] field in rest api definition to hold an object" + ); + } + public void testBrokenSpecShouldThrowUsefulExceptionWhenParsingFailsOnParts() throws Exception { parseAndExpectParsingException( BROKEN_SPEC_PARTS, @@ -164,4 +172,42 @@ private void parseAndExpectIllegalArgumentException(String brokenJson, String lo } } """; + + // deprecated needs to be an object + private static final String BROKEN_DEPRECATED_DEF = """ + { + "indices.get_template":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", + "description":"Returns an index template." + }, + "headers": { "accept": ["application/json"] }, + "stability": "stable", + "visibility": "public", + "deprecated" : true, + "url":{ + "paths":[ + { + "path":"/_template", + "methods":[ + "GET" + ] + }, + { + "path":"/_template/{name}", + "methods":[ + "GET" + ], + "parts":{ + "name":{ + "type":"list", + "description":"The comma separated names of the index templates" + } + } + } + ] + } + } + } + """; } diff --git a/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java b/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java index 8937d124d4452..ca0fb29104f52 100644 --- a/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java +++ b/test/yaml-rest-runner/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java @@ -156,6 +156,35 @@ public void testRequiredBodyWithoutUrlParts() throws Exception { assertThat(restApi.isBodyRequired(), equalTo(true)); } + public void testParseRestSpecDeprecatedApi() throws Exception { + parser = createParser(YamlXContent.yamlXContent, REST_SPEC_DEPRECATED_ENDPOINT); + ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("indices.get_template.json", parser); + assertThat(restApi, notNullValue()); + assertThat(restApi.getName(), equalTo("indices.get_template")); + assertThat(restApi.getPaths().size(), equalTo(2)); + Iterator iterator = restApi.getPaths().iterator(); + { + ClientYamlSuiteRestApi.Path next = iterator.next(); + assertThat(next.path(), equalTo("/_template")); + assertThat(next.methods().length, equalTo(1)); + assertThat(next.methods()[0], equalTo("GET")); + assertEquals(0, next.parts().size()); + } + { + ClientYamlSuiteRestApi.Path next = iterator.next(); + assertThat(next.path(), equalTo("/_template/{name}")); + assertThat(next.methods().length, equalTo(1)); + assertThat(next.methods()[0], equalTo("GET")); + assertThat(next.parts().size(), equalTo(1)); + assertThat(next.parts(), contains("name")); + } + assertThat(restApi.getParams().size(), equalTo(0)); + assertThat(restApi.isBodySupported(), equalTo(false)); + assertThat(restApi.isBodyRequired(), equalTo(false)); + assertThat(restApi.getRequestMimeTypes(), nullValue()); + assertThat(restApi.getResponseMimeTypes(), containsInAnyOrder("application/json")); + } + private static final String REST_SPEC_COUNT_API = """ { "count":{ @@ -353,4 +382,44 @@ public void testRequiredBodyWithoutUrlParts() throws Exception { } } """; + + private static final String REST_SPEC_DEPRECATED_ENDPOINT = """ + { + "indices.get_template":{ + "documentation":{ + "url":"https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-templates.html", + "description":"Returns an index template." + }, + "headers": { "accept": ["application/json"] }, + "stability": "stable", + "visibility": "public", + "deprecated" : { + "description" : "deprecated api", + "version" : "8.4.0" + }, + "url":{ + "paths":[ + { + "path":"/_template", + "methods":[ + "GET" + ] + }, + { + "path":"/_template/{name}", + "methods":[ + "GET" + ], + "parts":{ + "name":{ + "type":"list", + "description":"The comma separated names of the index templates" + } + } + } + ] + } + } + } + """; }