|
18 | 18 | */ |
19 | 19 | package org.elasticsearch.test.rest.yaml.restspec; |
20 | 20 |
|
| 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 | + |
21 | 28 | import java.io.IOException; |
22 | 29 | import java.io.InputStream; |
23 | 30 | import java.io.UncheckedIOException; |
|
30 | 37 | import java.util.Set; |
31 | 38 | import java.util.stream.Stream; |
32 | 39 |
|
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 | | - |
39 | 40 | /** |
40 | 41 | * Holds the specification used to turn {@code do} actions in the YAML suite into REST api calls. |
41 | 42 | */ |
@@ -103,20 +104,25 @@ private static void parseSpecFile(ClientYamlSuiteRestApiParser restApiParser, Pa |
103 | 104 | while (parser.nextToken() != XContentParser.Token.END_OBJECT) { |
104 | 105 | if (parser.currentToken() == XContentParser.Token.FIELD_NAME) { |
105 | 106 | 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(); |
118 | 121 | } |
| 122 | + } else if ("documentation".equals(currentFieldName)) { |
119 | 123 | parser.skipChildren(); |
| 124 | + } else { |
| 125 | + throw new ParsingException(parser.getTokenLocation(), "unsupported field [" + currentFieldName + "]"); |
120 | 126 | } |
121 | 127 | } |
122 | 128 | } |
|
0 commit comments