[TEST] ClientYamlSuiteRestApiParser to parse spec without path parts (#33720)
Previously ClientYamlSuiteRestApiParser threw an exception when an api spec contained neither path parts nor url parameter sections. Closes #31649
This commit is contained in:
parent
bf0a0f74da
commit
b48d5a8942
|
@ -64,8 +64,7 @@ public class ClientYamlSuiteRestApiParser {
|
||||||
|
|
||||||
if ("url".equals(parser.currentName())) {
|
if ("url".equals(parser.currentName())) {
|
||||||
String currentFieldName = "url";
|
String currentFieldName = "url";
|
||||||
int innerLevel = -1;
|
while(parser.nextToken() != XContentParser.Token.END_OBJECT) {
|
||||||
while(parser.nextToken() != XContentParser.Token.END_OBJECT || innerLevel >= 0) {
|
|
||||||
if (parser.currentToken() == XContentParser.Token.FIELD_NAME) {
|
if (parser.currentToken() == XContentParser.Token.FIELD_NAME) {
|
||||||
currentFieldName = parser.currentName();
|
currentFieldName = parser.currentName();
|
||||||
}
|
}
|
||||||
|
@ -108,13 +107,6 @@ public class ClientYamlSuiteRestApiParser {
|
||||||
restApi.addParam(param, PARAMETER_PARSER.parse(parser, null).isRequired());
|
restApi.addParam(param, PARAMETER_PARSER.parse(parser, null).isRequired());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
|
|
||||||
innerLevel++;
|
|
||||||
}
|
|
||||||
if (parser.currentToken() == XContentParser.Token.END_OBJECT) {
|
|
||||||
innerLevel--;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,31 @@ public class ClientYamlSuiteRestApiParserTests extends AbstractClientYamlTestFra
|
||||||
assertThat(restApi.isBodyRequired(), equalTo(false));
|
assertThat(restApi.isBodyRequired(), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRequiredBodyWithoutUrlParts() throws Exception {
|
||||||
|
String spec = "{\n" +
|
||||||
|
" \"count\": {\n" +
|
||||||
|
" \"documentation\": \"whatever\",\n" +
|
||||||
|
" \"methods\": [ \"GET\", \"POST\" ],\n" +
|
||||||
|
" \"url\": {\n" +
|
||||||
|
" \"path\": \"/whatever\",\n" +
|
||||||
|
" \"paths\": [ \"/whatever\" ]\n" +
|
||||||
|
" },\n" +
|
||||||
|
" \"body\": {\n" +
|
||||||
|
" \"description\" : \"whatever\",\n" +
|
||||||
|
" \"required\" : true\n" +
|
||||||
|
" }\n" +
|
||||||
|
" }\n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
parser = createParser(YamlXContent.yamlXContent, spec);
|
||||||
|
ClientYamlSuiteRestApi restApi = new ClientYamlSuiteRestApiParser().parse("count.json", parser);
|
||||||
|
|
||||||
|
assertThat(restApi, notNullValue());
|
||||||
|
assertThat(restApi.getPathParts().isEmpty(), equalTo(true));
|
||||||
|
assertThat(restApi.getParams().isEmpty(), equalTo(true));
|
||||||
|
assertThat(restApi.isBodyRequired(), equalTo(true));
|
||||||
|
}
|
||||||
|
|
||||||
private static final String REST_SPEC_COUNT_API = "{\n" +
|
private static final String REST_SPEC_COUNT_API = "{\n" +
|
||||||
" \"count\": {\n" +
|
" \"count\": {\n" +
|
||||||
" \"documentation\": \"http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html\",\n" +
|
" \"documentation\": \"http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html\",\n" +
|
||||||
|
|
Loading…
Reference in New Issue