diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java index b0c2a713d61..9719532b942 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParser.java @@ -64,8 +64,7 @@ public class ClientYamlSuiteRestApiParser { if ("url".equals(parser.currentName())) { String currentFieldName = "url"; - int innerLevel = -1; - while(parser.nextToken() != XContentParser.Token.END_OBJECT || innerLevel >= 0) { + while(parser.nextToken() != XContentParser.Token.END_OBJECT) { if (parser.currentToken() == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } @@ -108,13 +107,6 @@ public class ClientYamlSuiteRestApiParser { 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--; - } } } diff --git a/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java index cbc1f632617..9ba393966a3 100644 --- a/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java +++ b/test/framework/src/test/java/org/elasticsearch/test/rest/yaml/restspec/ClientYamlSuiteRestApiParserTests.java @@ -91,6 +91,31 @@ public class ClientYamlSuiteRestApiParserTests extends AbstractClientYamlTestFra 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" + " \"count\": {\n" + " \"documentation\": \"http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-count.html\",\n" +