Skip to content

Commit d58ca55

Browse files
committed
fix empty servicePath in discovery
The discovery test was not catching this issue in part because it wasn't using the exact same JSON serialization as it does at runtime. That has also been fixed. This change will likely reintroduce empty maps in serialization, but this is currently the best workaround to allow empty strings inside maps, which we need to serialize the discovery document correctly.
1 parent fa30223 commit d58ca55

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

endpoints-framework/src/main/java/com/google/api/server/spi/ObjectMapperUtil.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import com.google.api.server.spi.config.annotationreader.ApiAnnotationIntrospector;
1919
import com.google.api.server.spi.config.model.ApiSerializationConfig;
2020

21-
import com.fasterxml.jackson.annotation.JsonInclude;
2221
import com.fasterxml.jackson.core.JsonGenerator;
2322
import com.fasterxml.jackson.core.JsonParser;
2423
import com.fasterxml.jackson.databind.AnnotationIntrospector;
@@ -107,10 +106,9 @@ public JsonSerializer<?> modifyCollectionSerializer(SerializationConfig config,
107106
public JsonSerializer<?> modifyMapSerializer(SerializationConfig config, MapType valueType,
108107
BeanDescription beanDesc, JsonSerializer<?> serializer) {
109108
if (serializer instanceof MapSerializer) {
110-
// For some reason, NON_EMPTY is not being propagated to MapSerializer, so we replace it
111-
// with one that has it set.
112-
return new DeepEmptyCheckingSerializer<>(
113-
((MapSerializer) serializer).withContentInclusion(JsonInclude.Include.NON_EMPTY));
109+
// TODO: We should probably be propagating the NON_EMPTY inclusion here, but it's breaking
110+
// discovery.
111+
return new DeepEmptyCheckingSerializer<>(serializer);
114112
}
115113
return serializer;
116114
}

endpoints-framework/src/test/java/com/google/api/server/spi/discovery/DiscoveryGeneratorTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.google.api.client.json.jackson2.JacksonFactory;
2121
import com.google.api.server.spi.IoUtil;
22+
import com.google.api.server.spi.ObjectMapperUtil;
2223
import com.google.api.server.spi.ServiceContext;
2324
import com.google.api.server.spi.TypeLoader;
2425
import com.google.api.server.spi.config.ApiConfigLoader;
@@ -47,16 +48,14 @@
4748
import org.junit.runner.RunWith;
4849
import org.junit.runners.JUnit4;
4950

50-
import io.swagger.util.Json;
51-
5251
/**
5352
* Tests for {@link DiscoveryGenerator}.
5453
*/
5554
@RunWith(JUnit4.class)
5655
public class DiscoveryGeneratorTest {
5756
private final DiscoveryContext context = new DiscoveryContext()
5857
.setApiRoot("https://discovery-test.appspot.com/api");
59-
private final ObjectMapper mapper = Json.mapper();
58+
private final ObjectMapper mapper = ObjectMapperUtil.createStandardObjectMapper();
6059
private DiscoveryGenerator generator;
6160
private ApiConfigLoader configLoader;
6261
private SchemaRepository schemaRepository;

endpoints-framework/src/test/resources/com/google/api/server/spi/discovery/absolute_path_endpoint.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,15 @@
2323
"absolutepath": {
2424
"httpMethod": "POST",
2525
"id": "absolutepath.absolutepath",
26-
"path": "absolutepathmethod",
26+
"path": "absolutepathmethod/v1",
27+
"scopes": [
28+
"https://www.googleapis.com/auth/userinfo.email"
29+
]
30+
},
31+
"absolutepath2": {
32+
"httpMethod": "POST",
33+
"id": "absolutepath.absolutepath2",
34+
"path": "absolutepathmethod2/v1",
2735
"scopes": [
2836
"https://www.googleapis.com/auth/userinfo.email"
2937
]

endpoints-framework/src/test/resources/com/google/api/server/spi/swagger/absolute_path_endpoint.swagger

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
}
3131
}
3232
},
33-
"/absolutepathmethod": {
33+
"/absolutepathmethod/v1": {
3434
"post": {
3535
"operationId": "AbsolutepathAbsolutePath",
3636
"parameters": [],
@@ -40,6 +40,17 @@
4040
}
4141
}
4242
}
43+
},
44+
"/absolutepathmethod2/v1": {
45+
"post": {
46+
"operationId": "AbsolutepathAbsolutePath2",
47+
"parameters": [],
48+
"responses": {
49+
"200": {
50+
"description": "A successful response"
51+
}
52+
}
53+
}
4354
}
4455
},
4556
"definitions": {

test-utils/src/main/java/com/google/api/server/spi/testing/AbsolutePathEndpoint.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public Foo createFoo() {
1313
return null;
1414
}
1515

16-
@ApiMethod(name = "absolutepath", path = "/absolutepathmethod")
16+
@ApiMethod(name = "absolutepath", path = "/absolutepathmethod/v1")
1717
public void absolutePath() { }
18+
19+
@ApiMethod(name = "absolutepath2", path = "/absolutepathmethod2/v1")
20+
public void absolutePath2() { }
1821
}

0 commit comments

Comments
 (0)