Skip to content

Commit 33897e4

Browse files
committed
Revert "Add sparse trait support for codegen (#3740)"
This reverts commit 5369472.
1 parent 8f8757c commit 33897e4

35 files changed

Lines changed: 116 additions & 629 deletions

src/aws-cpp-sdk-core/include/aws/core/utils/json/JsonSerializer.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,6 @@ namespace Aws
9494
JsonValue& WithString(const Aws::String& key, const Aws::String& value);
9595
JsonValue& WithString(const char* key, const Aws::String& value);
9696

97-
/**
98-
* Adds a null value to the top level of this node with key.
99-
*/
100-
JsonValue& WithNull(const Aws::String& key);
101-
JsonValue& WithNull(const char* key);
102-
10397
/**
10498
* Converts the current JSON node to a string.
10599
*/

src/aws-cpp-sdk-core/source/utils/json/JsonSerializer.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -153,23 +153,6 @@ JsonValue& JsonValue::WithString(const Aws::String& key, const Aws::String& valu
153153
return WithString(key.c_str(), value);
154154
}
155155

156-
JsonValue& JsonValue::WithNull(const char* key)
157-
{
158-
if (!m_value)
159-
{
160-
m_value = cJSON_AS4CPP_CreateObject();
161-
}
162-
163-
const auto val = cJSON_AS4CPP_CreateNull();
164-
AddOrReplace(m_value, key, val);
165-
return *this;
166-
}
167-
168-
JsonValue& JsonValue::WithNull(const Aws::String& key)
169-
{
170-
return WithNull(key.c_str());
171-
}
172-
173156
JsonValue& JsonValue::AsString(const Aws::String& value)
174157
{
175158
Destroy();

tests/aws-cpp-sdk-core-tests/utils/json/JsonSerializerTest.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -434,39 +434,6 @@ TEST_F(JsonSerializerTest, TestGetAllObjects)
434434
ASSERT_EQ(42, all["Key2"].AsInteger());
435435
}
436436

437-
TEST_F(JsonSerializerTest, TestWithNull)
438-
{
439-
JsonValue value;
440-
value.WithString("Key1", "value1");
441-
value.WithNull("Key2");
442-
value.WithNull(Aws::String("Key3"));
443-
value.WithInteger("Key4", 42);
444-
445-
auto view = value.View();
446-
447-
ASSERT_TRUE(view.KeyExists("Key2"));
448-
ASSERT_FALSE(view.ValueExists("Key2"));
449-
ASSERT_TRUE(view.GetObject("Key2").IsNull());
450-
451-
ASSERT_TRUE(view.KeyExists("Key3"));
452-
ASSERT_FALSE(view.ValueExists("Key3"));
453-
ASSERT_TRUE(view.GetObject("Key3").IsNull());
454-
455-
ASSERT_STREQ("value1", view.GetString("Key1").c_str());
456-
ASSERT_EQ(42, view.GetInteger("Key4"));
457-
458-
Aws::String serialized = view.WriteCompact();
459-
JsonValue reparsed(serialized);
460-
ASSERT_TRUE(reparsed.WasParseSuccessful());
461-
auto reparsedView = reparsed.View();
462-
ASSERT_TRUE(reparsedView.KeyExists("Key2"));
463-
ASSERT_FALSE(reparsedView.ValueExists("Key2"));
464-
ASSERT_TRUE(reparsedView.GetObject("Key2").IsNull());
465-
ASSERT_TRUE(reparsedView.KeyExists("Key3"));
466-
ASSERT_FALSE(reparsedView.ValueExists("Key3"));
467-
ASSERT_TRUE(reparsedView.GetObject("Key3").IsNull());
468-
}
469-
470437
TEST_F(JsonSerializerTest, TestEquality)
471438
{
472439
auto input = R"({"AWS" : {

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/c2j/C2jShape.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,4 @@ public class C2jShape {
3636
private boolean sensitive;
3737
private boolean document;
3838
private Map<String, Boolean> retryable;
39-
private boolean sparse;
4039
}

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/Shape.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ public class Shape {
6363
private boolean overrideStreaming = false;
6464
private boolean requestCompressionRequired=false;
6565
private boolean requestCompressionRequiredGzip=false;
66-
private boolean sparse=false;
6766

6867
public boolean isMap() {
6968
return "map".equals(type.toLowerCase());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp;
2+
3+
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.Shape;
4+
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.ShapeMember;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
public class CppCborViewHelper extends CppViewHelper {
10+
private static final Map<String, String> CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING = new HashMap<>();
11+
12+
static {
13+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("long", "long long");
14+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("integer", "int64_t");
15+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("string", "Aws::String");
16+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("timestamp", "Aws::Utils::DateTime");
17+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("boolean", "bool");
18+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_boolean", "bool");
19+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("double", "double");
20+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("float", "double");
21+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("blob", "Aws::Utils::ByteBuffer");
22+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_blob", "Aws::Utils::CryptoBuffer");
23+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_long", "long long");
24+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_integer", "int64_t");
25+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_float", "double");
26+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_double", "double");
27+
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_timestamp", "Aws::Utils::DateTime");
28+
}
29+
30+
public static String computeCppType(Shape shape) {
31+
return computeCppTypeInternal(shape, CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING);
32+
}
33+
34+
public static String computeCppType(Shape parent, String member) {
35+
if (!parent.getMembers().containsKey(member)) {
36+
throw new RuntimeException("Parent shape " + parent.getName() +
37+
" does not contain member key " + member);
38+
}
39+
ShapeMember shapeMember = parent.getMembers().get(member);
40+
Shape childShape = shapeMember.getShape();
41+
42+
if (parent.getPayload() != null && parent.getPayload().equals(member) && parent.isResult()) {
43+
if (shapeMember.isStreaming() || childShape.isBlob() || childShape.isString()) {
44+
return "Aws::Utils::Stream::ResponseStream";
45+
}
46+
}
47+
return computeCppType(childShape);
48+
}
49+
}

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/domainmodels/codegeneration/cpp/CppViewHelper.java

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.lang.RuntimeException;
1616

1717
import java.util.Collection;
18-
import java.util.Collections;
1918
import java.util.HashMap;
2019
import java.util.LinkedHashSet;
2120
import java.util.LinkedList;
@@ -27,7 +26,6 @@
2726

2827
public class CppViewHelper {
2928
private static final Map<String, String> CORAL_TYPE_TO_CPP_TYPE_MAPPING = new HashMap<>();
30-
private static final Map<String, String> CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING = new HashMap<>();
3129
private static final Map<String, String> CORAL_TYPE_TO_JSON_CPP_TYPE_MAPPING = new HashMap<>();
3230
private static final Map<String, String> CORAL_TYPE_TO_XML_CONVERSION_MAPPING = new HashMap<>();
3331
private static final Map<String, String> CORAL_TYPE_TO_DEFAULT_VALUES = new HashMap<>();
@@ -58,9 +56,6 @@ public class CppViewHelper {
5856
CORAL_TYPE_TO_CPP_TYPE_MAPPING.put("sensitive_double", "double");
5957
CORAL_TYPE_TO_CPP_TYPE_MAPPING.put("sensitive_timestamp", "Aws::Utils::DateTime");
6058

61-
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("integer", "int64_t");
62-
CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING.put("sensitive_integer", "int64_t");
63-
6459
CORAL_TYPE_TO_JSON_CPP_TYPE_MAPPING.put("long", "Int64");
6560
CORAL_TYPE_TO_JSON_CPP_TYPE_MAPPING.put("integer", "Integer");
6661
CORAL_TYPE_TO_JSON_CPP_TYPE_MAPPING.put("string", "String");
@@ -210,12 +205,8 @@ public static String computeJsonizeString(Shape shape) {
210205
}
211206

212207
static String computeCppTypeInternal(Shape shape, Map<String, String> typeMapping) {
213-
return computeCppTypeInternal(shape, typeMapping, Collections.emptyMap());
214-
}
215-
216-
static String computeCppTypeInternal(Shape shape, Map<String, String> typeMapping, Map<String, String> overrideMapping) {
217208
String sensitivePrefix = shape.isSensitive() ? "sensitive_" : "";
218-
String cppType = overrideMapping.getOrDefault(sensitivePrefix + shape.getType(), typeMapping.get(sensitivePrefix + shape.getType()));
209+
String cppType = typeMapping.get(sensitivePrefix + shape.getType());
219210

220211
//enum types show up as string
221212
if(cppType != null && !shape.isEnum()) {
@@ -233,15 +224,13 @@ else if(shape.isStructure() || shape.isEnum())
233224
}
234225

235226
else if(shape.isList()) {
236-
String type = computeCppTypeInternal(shape.getListMember().getShape(), typeMapping, overrideMapping);
237-
type = shape.isSparse() ? String.format("Aws::Crt::Optional<%s>", type) : type;
227+
String type = computeCppTypeInternal(shape.getListMember().getShape(), typeMapping);
238228
return String.format("Aws::Vector<%s>", type);
239229
}
240230

241231
else if(shape.isMap()) {
242-
String key = computeCppTypeInternal(shape.getMapKey().getShape(), typeMapping, overrideMapping);
243-
String value = computeCppTypeInternal(shape.getMapValue().getShape(), typeMapping, overrideMapping);
244-
value = shape.isSparse() ? String.format("Aws::Crt::Optional<%s>", value) : value;
232+
String key = computeCppTypeInternal(shape.getMapKey().getShape(), typeMapping);
233+
String value = computeCppTypeInternal(shape.getMapValue().getShape(), typeMapping);
245234
return String.format("Aws::Map<%s, %s>", key, value);
246235
}
247236

@@ -254,16 +243,6 @@ public static String computeCppType(Shape shape) {
254243
return computeCppTypeInternal(shape, CORAL_TYPE_TO_CPP_TYPE_MAPPING);
255244
}
256245

257-
public static String computeCborCppType(Shape shape) {
258-
return computeCppTypeInternal(shape, CORAL_TYPE_TO_CPP_TYPE_MAPPING, CORAL_TYPE_TO_CBOR_CPP_TYPE_MAPPING);
259-
}
260-
261-
public static String computeResultCppType(Shape shape, String protocol) {
262-
return "smithy-rpc-v2-cbor".equals(protocol)
263-
? computeCborCppType(shape)
264-
: computeCppType(shape);
265-
}
266-
267246
public static boolean isStreamingPayloadMember(Shape parent, String member) {
268247
if (!parent.getMembers().containsKey(member)) {
269248
throw new RuntimeException("Parent shape " + parent.getName() +
@@ -296,22 +275,6 @@ public static String computeCppType(Shape parent, String member) {
296275
return computeCppType(childShape);
297276
}
298277

299-
public static String computeCborCppType(Shape parent, String member) {
300-
if (!parent.getMembers().containsKey(member)) {
301-
throw new RuntimeException("Parent shape " + parent.getName() +
302-
" does not contain member key " + member);
303-
}
304-
ShapeMember shapeMember = parent.getMembers().get(member);
305-
Shape childShape = shapeMember.getShape();
306-
307-
if (parent.getPayload() != null && parent.getPayload().equals(member) && parent.isResult()) {
308-
if (shapeMember.isStreaming() || childShape.isBlob() || childShape.isString()) {
309-
return "Aws::Utils::Stream::ResponseStream";
310-
}
311-
}
312-
return computeCborCppType(childShape);
313-
}
314-
315278
public static String computeJsonCppType(Shape shape) {
316279
if(shape.isTimeStamp() && shape.getTimestampFormat() != null) {
317280
return CORAL_TYPE_TO_JSON_CPP_TYPE_MAPPING.get(shape.getTimestampFormat().toLowerCase());
@@ -424,9 +387,6 @@ public static Set<String> computeHeaderIncludes(String projectName, Shape shape)
424387
headers.add(formatModelIncludeName(projectName, shapeInList));
425388
}
426389
}
427-
if (next.isSparse()) {
428-
headers.add("<aws/crt/Optional.h>");
429-
}
430390
if(!next.isPrimitive()) {
431391
if (next.isException() && !next.isModeledException()) {
432392
// C++ SDK code generator skips generating exceptions that can be expressed using

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/generators/cpp/CborCppClientGenerator.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.ServiceModel;
1111
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.Shape;
1212
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.ShapeMember;
13+
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp.CppCborViewHelper;
1314
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp.CppShapeInformation;
1415
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp.CppViewHelper;
1516
import org.apache.velocity.Template;
@@ -34,7 +35,7 @@ protected SdkFileEntry generateErrorMarshallerHeaderFile(ServiceModel serviceMod
3435
Template template = velocityEngine.getTemplate("/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborErrorMarshallerHeader.vm", StandardCharsets.UTF_8.name());
3536

3637
VelocityContext context = createContext(serviceModel);
37-
context.put("CppViewHelper", CppViewHelper.class);
38+
context.put("CppViewHelper", CppCborViewHelper.class);
3839

3940
String fileName = String.format("include/aws/%s/%sErrorMarshaller.h",
4041
serviceModel.getMetadata().getProjectName(), serviceModel.getMetadata().getClassNamePrefix());
@@ -78,7 +79,7 @@ protected SdkFileEntry generateModelHeaderFile(ServiceModel serviceModel, Map.En
7879

7980
context.put("shape", shape);
8081
context.put("typeInfo", new CppShapeInformation(shape, serviceModel));
81-
context.put("CppViewHelper", CppViewHelper.class);
82+
context.put("CppViewHelper", CppCborViewHelper.class);
8283

8384
String fileName = String.format("include/aws/%s/model/%s.h", serviceModel.getMetadata().getProjectName(),
8485
shapeEntry.getKey());
@@ -146,7 +147,7 @@ else if (shape.isResult()) {
146147

147148
context.put("shape", shape);
148149
context.put("typeInfo", new CppShapeInformation(shape, serviceModel));
149-
context.put("CppViewHelper", CppViewHelper.class);
150+
context.put("CppViewHelper", CppCborViewHelper.class);
150151

151152
String fileName = String.format("source/model/%s.cpp", shapeEntry.getKey());
152153

@@ -165,7 +166,7 @@ protected SdkFileEntry generateClientHeaderFile(final ServiceModel serviceModel)
165166
Template template = velocityEngine.getTemplate("/com/amazonaws/util/awsclientgenerator/velocity/cpp/cbor/CborServiceClientHeader.vm", StandardCharsets.UTF_8.name());
166167

167168
VelocityContext context = createContext(serviceModel);
168-
context.put("CppViewHelper", CppViewHelper.class);
169+
context.put("CppViewHelper", CppCborViewHelper.class);
169170
context.put("RequestlessOperations", requestlessOperations);
170171

171172
String fileName = String.format("include/aws/%s/%sClient.h", serviceModel.getMetadata().getProjectName(),

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/generators/cpp/CppProtocolTestGenerator.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.Shape;
1313
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.ShapeMember;
14+
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp.CppCborViewHelper;
1415
import com.amazonaws.util.awsclientgenerator.domainmodels.codegeneration.cpp.CppViewHelper;
1516
import com.amazonaws.util.awsclientgenerator.domainmodels.protocol_test.ProtocolTestModel;
1617
import com.amazonaws.util.awsclientgenerator.domainmodels.protocol_test.ProtocolTestSuite;
@@ -114,7 +115,11 @@ protected final VelocityContext createContext() {
114115
context.put("testModel", testModel);
115116
context.put("input.encoding", StandardCharsets.UTF_8.name());
116117
context.put("output.encoding", StandardCharsets.UTF_8.name());
117-
context.put("CppViewHelper", CppViewHelper.class);
118+
if(serviceModel.getMetadata().getProtocol().equals("smithy-rpc-v2-cbor")){
119+
context.put("CppViewHelper", CppCborViewHelper.class);
120+
} else {
121+
context.put("CppViewHelper", CppViewHelper.class);
122+
}
118123
return context;
119124
}
120125

tools/code-generation/generator/src/main/java/com/amazonaws/util/awsclientgenerator/transform/C2jModelToGeneratorModelTransformer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,10 +439,6 @@ Shape convertShapeBasics(C2jShape c2jShape, String shapeName) {
439439
shape.setEvent(c2jShape.isEvent());
440440
shape.setException(c2jShape.isException());
441441
shape.setDocument(c2jShape.isDocument());
442-
shape.setSparse(c2jShape.isSparse());
443-
if (shape.isSparse() && !shape.isList() && !shape.isMap()) {
444-
throw new SourceGenerationFailedException("The sparse trait is only applicable to list and map shapes, but was found on shape: " + shape.getName());
445-
}
446442

447443
if (c2jShape.getXmlNamespace() != null) {
448444
XmlNamespace xmlns = new XmlNamespace();
@@ -854,7 +850,6 @@ Shape cloneShape(Shape shape) {
854850
cloned.setException(shape.isException());
855851
cloned.setXmlNamespace(shape.getXmlNamespace());
856852
cloned.setDocument(shape.isDocument());
857-
cloned.setSparse(shape.isSparse());
858853
return cloned;
859854
}
860855

0 commit comments

Comments
 (0)