Skip to content

Commit d127196

Browse files
author
Christoph Büscher
committed
iter
1 parent db10c80 commit d127196

File tree

5 files changed

+31
-13
lines changed

5 files changed

+31
-13
lines changed

rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/11_basic_with_types.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,20 @@ setup:
1313
mappings:
1414
doc: {}
1515
---
16+
"Get /{index}/_mapping with empty mappings":
1617

18+
- do:
19+
indices.create:
20+
index: t
21+
22+
- do:
23+
indices.get_mapping:
24+
include_type_name: true
25+
index: t
26+
27+
- match: { t.mappings: {}}
28+
29+
---
1730
"Get /_mapping":
1831

1932
- do:

rest-api-spec/src/main/resources/rest-api-spec/test/indices.get_mapping/60_empty.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
---
22
setup:
3-
- skip:
4-
version: " - 6.99.99"
5-
reason: include_type_name defaults to true before 7.0
63
- do:
74
indices.create:
85
index: test_1

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
9393
throw new IllegalArgumentException("Types cannot be provided in get mapping requests, unless" +
9494
" include_type_name is set to true.");
9595
}
96-
// TODO q: do we want to deprecate any use of the parameter or just "true"
97-
if (includeTypeName == true) {
96+
if (request.hasParam(INCLUDE_TYPE_NAME_PARAMETER)) {
9897
deprecationLogger.deprecatedAndMaybeLog("get_mapping_with_types", TYPES_DEPRECATION_MESSAGE);
9998
}
10099

server/src/test/java/org/elasticsearch/action/admin/indices/mapping/get/GetMappingsResponseTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ protected GetMappingsResponse createXContextTestInstance(XContentType xContentTy
172172

173173
/**
174174
* check that the "old" legacy response format with types works as expected
175-
* @throws IOException
176175
*/
177176
public void testToXContentWithTypes() throws IOException {
178177
Params params = new ToXContent.MapParams(Collections.singletonMap(BaseRestHandler.INCLUDE_TYPE_NAME_PARAMETER, "true"));
179-
xContentTester(this::createParser, t -> createTestInstance(), params, this::fromXContentLegacy)
178+
xContentTester(this::createParser, t -> createTestInstance(), params, this::fromXContentWithTypes)
180179
.numberOfTestRuns(NUMBER_OF_TEST_RUNS)
181180
.supportsUnknownFields(supportsUnknownFields())
182181
.shuffleFieldsExceptions(getShuffleFieldsExceptions())
@@ -190,7 +189,7 @@ public void testToXContentWithTypes() throws IOException {
190189
* including the pre-7.0 parsing code here to test that older HLRC clients using this can parse the responses that are
191190
* returned when "include_type_name=true"
192191
*/
193-
private GetMappingsResponse fromXContentLegacy(XContentParser parser) throws IOException {
192+
private GetMappingsResponse fromXContentWithTypes(XContentParser parser) throws IOException {
194193
if (parser.currentToken() == null) {
195194
parser.nextToken();
196195
}

server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingActionTests.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.elasticsearch.test.rest.FakeRestChannel;
2929
import org.elasticsearch.test.rest.FakeRestRequest;
3030
import org.elasticsearch.test.rest.RestActionTestCase;
31+
import org.junit.Before;
3132

3233
import java.util.HashMap;
3334
import java.util.Map;
@@ -37,6 +38,11 @@
3738

3839
public class RestGetMappingActionTests extends RestActionTestCase {
3940

41+
@Before
42+
public void setUpAction() {
43+
new RestGetMappingAction(Settings.EMPTY, controller());
44+
}
45+
4046
public void testTypeExistsDeprecation() throws Exception {
4147
Map<String, String> params = new HashMap<>();
4248
params.put("type", "_doc");
@@ -70,17 +76,21 @@ public void testTypeInPath() {
7076
assertEquals(RestStatus.BAD_REQUEST, channel.capturedResponse().status());
7177
}
7278

73-
public void testTypeUrlParamerterDeprecation() throws Exception {
79+
/**
80+
* Setting "include_type_name" to true or false should cause a deprecation warning starting in 7.0
81+
*/
82+
public void testTypeUrlParameterDeprecation() throws Exception {
7483
Map<String, String> params = new HashMap<>();
75-
params.put(INCLUDE_TYPE_NAME_PARAMETER, "true");
84+
params.put(INCLUDE_TYPE_NAME_PARAMETER, Boolean.toString(randomBoolean()));
7685
RestRequest request = new FakeRestRequest.Builder(xContentRegistry())
7786
.withMethod(RestRequest.Method.GET)
7887
.withParams(params)
79-
.withPath("some_index/some_type/_mapping/some_field")
88+
.withPath("/some_index/_mappings")
8089
.build();
8190

82-
RestGetMappingAction handler = new RestGetMappingAction(Settings.EMPTY, mock(RestController.class));
83-
handler.prepareRequest(request, mock(NodeClient.class));
91+
FakeRestChannel channel = new FakeRestChannel(request, false, 1);
92+
ThreadContext threadContext = new ThreadContext(Settings.EMPTY);
93+
controller().dispatchRequest(request, channel, threadContext);
8494

8595
assertWarnings(RestGetMappingAction.TYPES_DEPRECATION_MESSAGE);
8696
}

0 commit comments

Comments
 (0)