Skip to content

Commit e623f61

Browse files
committed
remove default _all for type and index if these are missing in REST tests
If a type or path is missing in the REST test yaml file, it is automatically replaced with _all. This makes it hard to test changes in the api, for example adding the possibility to leave the index blank in addition to _all and * in the uri. closes elastic#4657
1 parent 0b2ff1e commit e623f61

File tree

11 files changed

+19
-19
lines changed

11 files changed

+19
-19
lines changed

rest-api-spec/api/exists.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"type": {
2020
"type" : "string",
21-
"required" : false,
22-
"default" : "_all",
21+
"required" : true,
2322
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
2423
}
2524
},

rest-api-spec/api/get.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"type": {
2020
"type" : "string",
21-
"required" : false,
22-
"default" : "_all",
21+
"required" : true,
2322
"description" : "The type of the document (use `_all` to fetch the first document matching the ID across all types)"
2423
}
2524
},

rest-api-spec/api/get_source.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
},
1919
"type": {
2020
"type" : "string",
21-
"required" : false,
22-
"default" : "_all",
21+
"required" : true,
2322
"description" : "The type of the document; use `_all` to fetch the first document matching the ID across all types"
2423
}
2524
},

rest-api-spec/api/search.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"parts": {
99
"index": {
1010
"type" : "list",
11-
"default" : "_all",
1211
"description" : "A comma-separated list of index names to search; use `_all` or empty string to perform the operation on all indices"
1312
},
1413
"type": {

rest-api-spec/test/exists/70_defaults.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- do:
1212
exists:
1313
index: test_1
14+
type: _all
1415
id: 1
1516

1617
- is_true: ''

rest-api-spec/test/get/10_basic.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
- do:
2323
get:
2424
index: test_1
25+
type: _all
2526
id: 中文
2627

2728
- match: { _index: test_1 }

rest-api-spec/test/get/15_default_values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- do:
1212
get:
1313
index: test_1
14+
type: _all
1415
id: 1
1516

1617
- match: { _index: test_1 }

rest-api-spec/test/get_source/10_basic.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- do:
2424
get_source:
2525
index: test_1
26+
type: _all
2627
id: 1
2728

2829
- match: { '': { foo: bar } }

rest-api-spec/test/get_source/15_default_values.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- do:
1616
get_source:
1717
index: test_1
18+
type: _all
1819
id: 1
1920

2021
- match: { '': { foo: bar } }

rest-api-spec/test/search/20_default_values.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
- do:
2828
search:
29-
type: test
29+
index: _all
30+
type: test
3031
body:
3132
query:
3233
match:

src/test/java/org/elasticsearch/test/rest/spec/RestApi.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
*/
3737
public class RestApi {
3838

39-
private static final String ALL = "_all";
40-
4139
private final String name;
4240
private List<String> methods = Lists.newArrayList();
4341
private List<String> paths = Lists.newArrayList();
@@ -123,18 +121,18 @@ public String getFinalPath(Map<String, String> pathParams) {
123121
RestPath matchingRestPath = findMatchingRestPath(pathParams.keySet());
124122
String path = matchingRestPath.path;
125123
for (Map.Entry<String, String> paramEntry : matchingRestPath.params.entrySet()) {
126-
//replace path placeholders with actual values
124+
// replace path placeholders with actual values
127125
String value = pathParams.get(paramEntry.getValue());
128126
if (value == null) {
129-
//there might be additional placeholder to replace, not available as input params
130-
//it can only be {index} or {type} to be replaced with _all
131-
if (paramEntry.getValue().equals("index") || paramEntry.getValue().equals("type")) {
132-
value = ALL;
133-
} else {
134-
throw new IllegalArgumentException("path [" + path + "] contains placeholders that weren't replaced with proper values");
135-
}
127+
// if a value is missing, we got the wrong path or the test was
128+
// specified incorrectly
129+
// TODO: What if more than one path exists? for example: PUT
130+
// index/type/_mapping vs. PUT index/_maping/type? Should we
131+
// randomize?
132+
throw new IllegalArgumentException("parameter [" + paramEntry.getValue() + "] missing");
133+
} else {
134+
path = path.replace(paramEntry.getKey(), value);
136135
}
137-
path = path.replace(paramEntry.getKey(), value);
138136
}
139137
return path;
140138
}

0 commit comments

Comments
 (0)