Skip to content

Commit 4308cab

Browse files
committed
update _common.json format
API spec now use an object for the documentation field. _common was not updated yet. This commit updates _common.json and its corresponding parser. Closes #46744
1 parent 8b764a5 commit 4308cab

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/_common.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
2-
"description": "Parameters that are accepted by all API endpoints.",
3-
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html",
2+
"documentation" : {
3+
"url": "Parameters that are accepted by all API endpoints.",
4+
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html"
5+
},
46
"params": {
57
"pretty": {
68
"type": "boolean",

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestSpec.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
*/
1919
package org.elasticsearch.test.rest.yaml.restspec;
2020

21+
import org.elasticsearch.common.ParsingException;
22+
import org.elasticsearch.common.io.PathUtils;
23+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
24+
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
25+
import org.elasticsearch.common.xcontent.XContentParser;
26+
import org.elasticsearch.common.xcontent.json.JsonXContent;
27+
2128
import java.io.IOException;
2229
import java.io.InputStream;
2330
import java.io.UncheckedIOException;
@@ -30,12 +37,6 @@
3037
import java.util.Set;
3138
import java.util.stream.Stream;
3239

33-
import org.elasticsearch.common.io.PathUtils;
34-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
35-
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
36-
import org.elasticsearch.common.xcontent.XContentParser;
37-
import org.elasticsearch.common.xcontent.json.JsonXContent;
38-
3940
/**
4041
* Holds the specification used to turn {@code do} actions in the YAML suite into REST api calls.
4142
*/
@@ -103,20 +104,25 @@ private static void parseSpecFile(ClientYamlSuiteRestApiParser restApiParser, Pa
103104
while (parser.nextToken() != XContentParser.Token.END_OBJECT) {
104105
if (parser.currentToken() == XContentParser.Token.FIELD_NAME) {
105106
currentFieldName = parser.currentName();
106-
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT
107-
&& "params".equals(currentFieldName)) {
108-
while (parser.nextToken() == XContentParser.Token.FIELD_NAME) {
109-
String param = parser.currentName();
110-
if (restSpec.globalParameters.contains(param)) {
111-
throw new IllegalArgumentException("Found duplicate global param [" + param + "]");
112-
}
113-
restSpec.globalParameters.add(param);
114-
parser.nextToken();
115-
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
116-
throw new IllegalArgumentException("Expected params field in rest api definition to " +
117-
"contain an object");
107+
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
108+
if ("params".equals(currentFieldName)) {
109+
while (parser.nextToken() == XContentParser.Token.FIELD_NAME) {
110+
String param = parser.currentName();
111+
if (restSpec.globalParameters.contains(param)) {
112+
throw new IllegalArgumentException("Found duplicate global param [" + param + "]");
113+
}
114+
restSpec.globalParameters.add(param);
115+
parser.nextToken();
116+
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
117+
throw new IllegalArgumentException("Expected params field in rest api definition to " +
118+
"contain an object");
119+
}
120+
parser.skipChildren();
118121
}
122+
} else if ("documentation".equals(currentFieldName)) {
119123
parser.skipChildren();
124+
} else {
125+
throw new ParsingException(parser.getTokenLocation(), "unsupported field [" + currentFieldName + "]");
120126
}
121127
}
122128
}

0 commit comments

Comments
 (0)