Skip to content

feat(codegen): update to Smithy-1.16.3 #3215

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ allprojects {
version = "0.8.0"
}

extra["smithyVersion"] = "[1.15.0,1.16.0["
extra["smithyVersion"] = "[1.16.3,1.17.0["

// The root project doesn't produce a JAR.
tasks["jar"].enabled = false
Expand Down
2 changes: 1 addition & 1 deletion codegen/generic-client-test-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buildscript {
}

plugins {
id("software.amazon.smithy") version "0.5.3"
id("software.amazon.smithy") version "0.6.0"
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion codegen/protocol-test-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ buildscript {
}

plugins {
id("software.amazon.smithy") version "0.5.3"
id("software.amazon.smithy") version "0.6.0"
}

dependencies {
Expand Down
2 changes: 1 addition & 1 deletion codegen/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ buildscript {
}

plugins {
id("software.amazon.smithy") version "0.5.3"
id("software.amazon.smithy") version "0.6.0"
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,6 @@ private static boolean filterProtocolTests(
return true;
}

// TODO: remove when there's a decision on behavior for list of timestamps.
// https://github.com/awslabs/smithy/issues/1015
if (testCase.getId().equals("RestJsonInputAndOutputWithTimestampHeaders")) {
return true;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ protected Format getDocumentTimestampFormat() {

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

@Override
protected void generateDocumentBodyShapeDeserializers(GenerationContext context, Set<Shape> shapes) {
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeDeserVisitor(context));
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes,
// AWS JSON does not support jsonName
new JsonShapeDeserVisitor(context, (shape, name) -> name));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Map;
import java.util.TreeMap;
import java.util.function.BiFunction;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.CollectionShape;
Expand Down Expand Up @@ -51,8 +52,19 @@
@SmithyInternalApi
final class JsonShapeDeserVisitor extends DocumentShapeDeserVisitor {

private final BiFunction<MemberShape, String, String> memberNameStrategy;

JsonShapeDeserVisitor(GenerationContext context) {
this(context,
// Use the jsonName trait value if present, otherwise use the member name.
(memberShape, memberName) -> memberShape.getTrait(JsonNameTrait.class)
.map(JsonNameTrait::getValue)
.orElse(memberName));
}

JsonShapeDeserVisitor(GenerationContext context, BiFunction<MemberShape, String, String> memberNameStrategy) {
super(context);
this.memberNameStrategy = memberNameStrategy;
}

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

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

String memberValue = target.accept(getMemberVisitor(memberShape, "output." + locationName));
if (usesExpect(target)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.Map;
import java.util.TreeMap;
import java.util.function.BiFunction;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.CollectionShape;
Expand Down Expand Up @@ -51,10 +52,22 @@
final class JsonShapeSerVisitor extends DocumentShapeSerVisitor {
private static final Format TIMESTAMP_FORMAT = Format.EPOCH_SECONDS;

private final BiFunction<MemberShape, String, String> memberNameStrategy;

JsonShapeSerVisitor(GenerationContext context) {
this(context,
// Use the jsonName trait value if present, otherwise use the member name.
(memberShape, memberName) -> memberShape.getTrait(JsonNameTrait.class)
.map(JsonNameTrait::getValue)
.orElse(memberName));
}

JsonShapeSerVisitor(GenerationContext context, BiFunction<MemberShape, String, String> memberNameStrategy) {
super(context);
this.memberNameStrategy = memberNameStrategy;
}


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

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