Skip to content

Commit 5b52ed6

Browse files
committed
feat(codegen): update to Smithy-1.16.3
Includes removal of @JsonName support from AWS JSON protocols, which is a change made to the spec in 1.16.
1 parent 5187be2 commit 5b52ed6

File tree

7 files changed

+39
-22
lines changed

7 files changed

+39
-22
lines changed

codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ allprojects {
3131
version = "0.8.0"
3232
}
3333

34-
extra["smithyVersion"] = "[1.15.0,1.16.0["
34+
extra["smithyVersion"] = "[1.16.3,1.17.0["
3535

3636
// The root project doesn't produce a JAR.
3737
tasks["jar"].enabled = false

codegen/generic-client-test-codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buildscript {
2525
}
2626

2727
plugins {
28-
id("software.amazon.smithy") version "0.5.3"
28+
id("software.amazon.smithy") version "0.6.0"
2929
}
3030

3131
dependencies {

codegen/protocol-test-codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ buildscript {
2525
}
2626

2727
plugins {
28-
id("software.amazon.smithy") version "0.5.3"
28+
id("software.amazon.smithy") version "0.6.0"
2929
}
3030

3131
dependencies {

codegen/sdk-codegen/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ buildscript {
3131
}
3232

3333
plugins {
34-
id("software.amazon.smithy") version "0.5.3"
34+
id("software.amazon.smithy") version "0.6.0"
3535
}
3636

3737
dependencies {

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonRpcProtocolGenerator.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,16 @@ protected Format getDocumentTimestampFormat() {
6464

6565
@Override
6666
protected void generateDocumentBodyShapeSerializers(GenerationContext context, Set<Shape> shapes) {
67-
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeSerVisitor(context));
67+
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes,
68+
// AWS JSON does not support jsonName
69+
new JsonShapeSerVisitor(context, (shape, name) -> name));
6870
}
6971

7072
@Override
7173
protected void generateDocumentBodyShapeDeserializers(GenerationContext context, Set<Shape> shapes) {
72-
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeDeserVisitor(context));
74+
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes,
75+
// AWS JSON does not support jsonName
76+
new JsonShapeDeserVisitor(context, (shape, name) -> name));
7377
}
7478

7579
@Override

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeDeserVisitor.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Map;
1919
import java.util.TreeMap;
20+
import java.util.function.BiFunction;
2021
import software.amazon.smithy.codegen.core.SymbolProvider;
2122
import software.amazon.smithy.model.Model;
2223
import software.amazon.smithy.model.shapes.CollectionShape;
@@ -51,8 +52,19 @@
5152
@SmithyInternalApi
5253
final class JsonShapeDeserVisitor extends DocumentShapeDeserVisitor {
5354

55+
private final BiFunction<MemberShape, String, String> memberNameStrategy;
56+
5457
JsonShapeDeserVisitor(GenerationContext context) {
58+
this(context,
59+
// Use the jsonName trait value if present, otherwise use the member name.
60+
(memberShape, memberName) -> memberShape.getTrait(JsonNameTrait.class)
61+
.map(JsonNameTrait::getValue)
62+
.orElse(memberName));
63+
}
64+
65+
JsonShapeDeserVisitor(GenerationContext context, BiFunction<MemberShape, String, String> memberNameStrategy) {
5566
super(context);
67+
this.memberNameStrategy = memberNameStrategy;
5668
}
5769

5870
private DocumentMemberDeserVisitor getMemberVisitor(MemberShape memberShape, String dataSource) {
@@ -154,10 +166,7 @@ protected void deserializeStructure(GenerationContext context, StructureShape sh
154166
writer.openBlock("return {", "} as any;", () -> {
155167
// Set all the members to undefined to meet type constraints.
156168
members.forEach((memberName, memberShape) -> {
157-
// Use the jsonName trait value if present, otherwise use the member name.
158-
String locationName = memberShape.getTrait(JsonNameTrait.class)
159-
.map(JsonNameTrait::getValue)
160-
.orElse(memberName);
169+
String locationName = memberNameStrategy.apply(memberShape, memberName);
161170
Shape target = context.getModel().expectShape(memberShape.getTarget());
162171

163172
if (usesExpect(target)) {
@@ -195,10 +204,7 @@ protected void deserializeUnion(GenerationContext context, UnionShape shape) {
195204
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
196205
members.forEach((memberName, memberShape) -> {
197206
Shape target = model.expectShape(memberShape.getTarget());
198-
// Use the jsonName trait value if present, otherwise use the member name.
199-
String locationName = memberShape.getTrait(JsonNameTrait.class)
200-
.map(JsonNameTrait::getValue)
201-
.orElse(memberName);
207+
String locationName = memberNameStrategy.apply(memberShape, memberName);
202208

203209
String memberValue = target.accept(getMemberVisitor(memberShape, "output." + locationName));
204210
if (usesExpect(target)) {

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/JsonShapeSerVisitor.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.util.Map;
1919
import java.util.TreeMap;
20+
import java.util.function.BiFunction;
2021
import software.amazon.smithy.codegen.core.SymbolProvider;
2122
import software.amazon.smithy.model.Model;
2223
import software.amazon.smithy.model.shapes.CollectionShape;
@@ -51,10 +52,22 @@
5152
final class JsonShapeSerVisitor extends DocumentShapeSerVisitor {
5253
private static final Format TIMESTAMP_FORMAT = Format.EPOCH_SECONDS;
5354

55+
private final BiFunction<MemberShape, String, String> memberNameStrategy;
56+
5457
JsonShapeSerVisitor(GenerationContext context) {
58+
this(context,
59+
// Use the jsonName trait value if present, otherwise use the member name.
60+
(memberShape, memberName) -> memberShape.getTrait(JsonNameTrait.class)
61+
.map(JsonNameTrait::getValue)
62+
.orElse(memberName));
63+
}
64+
65+
JsonShapeSerVisitor(GenerationContext context, BiFunction<MemberShape, String, String> memberNameStrategy) {
5566
super(context);
67+
this.memberNameStrategy = memberNameStrategy;
5668
}
5769

70+
5871
private DocumentMemberSerVisitor getMemberVisitor(String dataSource) {
5972
return new JsonMemberSerVisitor(getContext(), dataSource, TIMESTAMP_FORMAT);
6073
}
@@ -125,10 +138,7 @@ public void serializeStructure(GenerationContext context, StructureShape shape)
125138
// Use a TreeMap to sort the members.
126139
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
127140
members.forEach((memberName, memberShape) -> {
128-
// Use the jsonName trait value if present, otherwise use the member name.
129-
String locationName = memberShape.getTrait(JsonNameTrait.class)
130-
.map(JsonNameTrait::getValue)
131-
.orElse(memberName);
141+
String locationName = memberNameStrategy.apply(memberShape, memberName);
132142
Shape target = context.getModel().expectShape(memberShape.getTarget());
133143
String inputLocation = "input." + memberName;
134144

@@ -160,10 +170,7 @@ public void serializeUnion(GenerationContext context, UnionShape shape) {
160170
// Use a TreeMap to sort the members.
161171
Map<String, MemberShape> members = new TreeMap<>(shape.getAllMembers());
162172
members.forEach((memberName, memberShape) -> {
163-
// Use the jsonName trait value if present, otherwise use the member name.
164-
String locationName = memberShape.getTrait(JsonNameTrait.class)
165-
.map(JsonNameTrait::getValue)
166-
.orElse(memberName);
173+
String locationName = memberNameStrategy.apply(memberShape, memberName);
167174
Shape target = model.expectShape(memberShape.getTarget());
168175
// Dispatch to the input value provider for any additional handling.
169176
writer.write("$L: value => ({ $S: $L }),", memberName, locationName,

0 commit comments

Comments
 (0)