Skip to content

Commit

Permalink
chore(codegen): use SerdeElision knowledge index
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed May 9, 2023
1 parent 326913b commit 5f80e2d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class JsonMemberDeserVisitor extends DocumentMemberDeserVisitor {
super(context, dataSource, defaultTimestampFormat);
this.memberShape = memberShape;
context.getWriter().addImport("_json", null, "@aws-sdk/smithy-client");
serdeElision.setEnabledForModel(!context.getSettings().generateServerSdk());
this.serdeElisionEnabled = !context.getSettings().generateServerSdk();
}

JsonMemberDeserVisitor(GenerationContext context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ final class JsonMemberSerVisitor extends DocumentMemberSerVisitor {
/**
* @inheritDoc
*/
JsonMemberSerVisitor(GenerationContext context, String dataSource, Format defaultTimestampFormat) {
JsonMemberSerVisitor(GenerationContext context, String dataSource, Format defaultTimestampFormat) {
super(context, dataSource, defaultTimestampFormat);
context.getWriter().addImport("_json", null, "@aws-sdk/smithy-client");
serdeElision.setEnabledForModel(!context.getSettings().generateServerSdk());
this.serdeElisionEnabled = !context.getSettings().generateServerSdk();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ protected Format getDocumentTimestampFormat() {
protected void generateDocumentBodyShapeSerializers(GenerationContext context, Set<Shape> shapes) {
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes,
// AWS JSON does not support jsonName
new JsonShapeSerVisitor(context, (shape, name) -> name));
new JsonShapeSerVisitor(context, (shape, name) -> name, enableSerdeElision()));
}

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;
import java.util.TreeMap;
import java.util.function.BiFunction;
import software.amazon.smithy.aws.typescript.codegen.validation.UnaryFunctionCall;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.CollectionShape;
Expand All @@ -41,7 +42,6 @@
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
import software.amazon.smithy.typescript.codegen.integration.DocumentShapeDeserVisitor;
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.typescript.codegen.validation.UnaryFunctionCall;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
Expand All @@ -58,16 +58,19 @@ final class JsonShapeDeserVisitor extends DocumentShapeDeserVisitor {

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

JsonShapeDeserVisitor(GenerationContext context) {
JsonShapeDeserVisitor(GenerationContext context, boolean serdeElisionEnabled) {
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));
.orElse(memberName),
serdeElisionEnabled);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Map;
import java.util.TreeMap;
import java.util.function.BiFunction;
import software.amazon.smithy.aws.typescript.codegen.validation.UnaryFunctionCall;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.CollectionShape;
Expand All @@ -37,7 +38,6 @@
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor;
import software.amazon.smithy.typescript.codegen.integration.DocumentShapeSerVisitor;
import software.amazon.smithy.typescript.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.typescript.codegen.validation.UnaryFunctionCall;
import software.amazon.smithy.utils.SmithyInternalApi;

/**
Expand All @@ -55,16 +55,19 @@ final class JsonShapeSerVisitor extends DocumentShapeSerVisitor {

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

JsonShapeSerVisitor(GenerationContext context) {
JsonShapeSerVisitor(GenerationContext context, boolean serdeElisionEnabled) {
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));
.orElse(memberName),
serdeElisionEnabled);
}

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

Expand Down Expand Up @@ -111,6 +114,9 @@ public void serializeDocument(GenerationContext context, DocumentShape shape) {

@Override
public void serializeMap(GenerationContext context, MapShape shape) {
if (shape.getId().getName().equals("DenseBooleanMap")) {
System.out.println("here");
}
TypeScriptWriter writer = context.getWriter();
Shape target = context.getModel().expectShape(shape.getValue().getTarget());
SymbolProvider symbolProvider = context.getSymbolProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.List;
import java.util.Set;
import software.amazon.smithy.aws.typescript.codegen.validation.UnaryFunctionCall;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.knowledge.HttpBinding;
import software.amazon.smithy.model.shapes.DocumentShape;
Expand All @@ -33,7 +34,6 @@
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberDeserVisitor;
import software.amazon.smithy.typescript.codegen.integration.DocumentMemberSerVisitor;
import software.amazon.smithy.typescript.codegen.integration.HttpBindingProtocolGenerator;
import software.amazon.smithy.typescript.codegen.validation.UnaryFunctionCall;
import software.amazon.smithy.utils.IoUtils;
import software.amazon.smithy.utils.SmithyInternalApi;

Expand Down Expand Up @@ -68,12 +68,14 @@ protected TimestampFormatTrait.Format getDocumentTimestampFormat() {

@Override
protected void generateDocumentBodyShapeSerializers(GenerationContext context, Set<Shape> shapes) {
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeSerVisitor(context));
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeSerVisitor(context,
(!context.getSettings().generateServerSdk() && enableSerdeElision())));
}

@Override
protected void generateDocumentBodyShapeDeserializers(GenerationContext context, Set<Shape> shapes) {
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeDeserVisitor(context));
AwsProtocolUtils.generateDocumentBodyShapeSerde(context, shapes, new JsonShapeDeserVisitor(context,
(!context.getSettings().generateServerSdk() && enableSerdeElision())));
}

@Override
Expand Down

0 comments on commit 5f80e2d

Please sign in to comment.