Skip to content
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

Smithy Document Shape Support #1320

Merged
merged 2 commits into from
Jul 29, 2021
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ all: generate unit
gen-config-asserts gen-repo-mod-replace gen-mod-replace-smithy gen-mod-dropreplace-smithy gen-aws-ptrs tidy-modules-% \
add-module-license-files sync-models sync-endpoints-model sync-endpoints.json clone-v1-models gen-endpoint-prefix.json \
sync-api-models copy-attributevalue-feature min-go-version-% update-requires smithy-annotate-stable \
update-module-metadata
update-module-metadata download-modules-%

generate: smithy-generate update-requires gen-repo-mod-replace update-module-metadata smithy-annotate-stable \
gen-config-asserts copy-attributevalue-feature gen-mod-dropreplace-smithy min-go-version-. tidy-modules-. \
Expand Down Expand Up @@ -119,6 +119,16 @@ tidy-modules-%:
&& go run . -p $(subst _,/,$(subst tidy-modules-,,$@)) ${EACHMODULE_FLAGS} \
"go mod tidy"

download-modules-%:
@# download command that uses the pattern to define the root path that the
@# module testing will start from. Strips off the "download-modules-" and
@# replaces all "_" with "/".
@#
@# e.g. download-modules-internal_protocoltest
cd ./internal/repotools/cmd/eachmodule \
&& go run . -p $(subst _,/,$(subst download-modules-,,$@)) ${EACHMODULE_FLAGS} \
"go mod download all"

add-module-license-files:
cd internal/repotools/cmd/eachmodule && \
go run . -skip-root \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import java.util.Set;
import java.util.TreeSet;
import java.util.function.Consumer;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
Expand Down Expand Up @@ -185,25 +184,6 @@ static void generateHttpProtocolTests(GenerationContext context) {
.addTestName("RestXmlEndpointTraitWithHostLabel")
.build(),


// REST-JSON Documents
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#InlineDocument"))
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#InlineDocumentAsPayload"))
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#DocumentType"))
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#DocumentTypeAsPayload"))
.build(),

// Null lists/maps without sparse tag
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
Expand All @@ -222,12 +202,6 @@ static void generateHttpProtocolTests(GenerationContext context) {
.addTestName("AwsJson11ListsSerializeNull")
.build(),

// JSON RPC Documents
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json#JsonProtocol"))
.operation(ShapeId.from("aws.protocoltests.json#PutAndGetInlineDocuments"))
.build(),

// JSON RPC serialize empty modeled input should always serialize something
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
Expand Down Expand Up @@ -255,20 +229,23 @@ static void generateHttpProtocolTests(GenerationContext context) {
new HttpProtocolTestGenerator(context,
(HttpProtocolUnitTestRequestGenerator.Builder) new HttpProtocolUnitTestRequestGenerator
.Builder()
.settings(context.getSettings())
.addSkipTests(inputSkipTests)
.addClientConfigValues(inputConfigValues),
(HttpProtocolUnitTestResponseGenerator.Builder) new HttpProtocolUnitTestResponseGenerator
.Builder()
.settings(context.getSettings())
.addSkipTests(outputSkipTests)
.addClientConfigValues(configValues),
(HttpProtocolUnitTestResponseErrorGenerator.Builder) new HttpProtocolUnitTestResponseErrorGenerator
.Builder()
.settings(context.getSettings())
.addClientConfigValues(configValues)
).generateProtocolTests();
}

public static void writeJsonErrorMessageCodeDeserializer(GenerationContext context) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
// The error code could be in the headers, even though for this protocol it should be in the body.
writer.write("code := response.Header.Get(\"X-Amzn-ErrorType\")");
writer.write("if len(code) != 0 { errorCode = restjson.SanitizeErrorCode(code) }");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected void generateDocumentBodyShapeSerializers(GenerationContext context, S

@Override
protected void serializeInputDocument(GenerationContext context, OperationShape operation) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
ServiceShape service = context.getService();
StructureShape input = ProtocolUtils.expectInput(context.getModel(), operation);
String functionName = ProtocolGenerator.getDocumentSerializerFunctionName(
Expand Down Expand Up @@ -97,7 +97,7 @@ protected void generateDocumentBodyShapeDeserializers(GenerationContext context,

@Override
protected void deserializeOutputDocument(GenerationContext context, OperationShape operation) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
StructureShape output = ProtocolUtils.expectOutput(context.getModel(), operation);
String functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
output, context.getService(), getProtocolName());
Expand All @@ -109,7 +109,7 @@ protected void deserializeOutputDocument(GenerationContext context, OperationSha

@Override
protected void deserializeError(GenerationContext context, StructureShape shape) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
Symbol symbol = context.getSymbolProvider().toSymbol(shape);

writer.write("output := &$T{}", symbol);
Expand All @@ -129,7 +129,7 @@ protected void deserializeError(GenerationContext context, StructureShape shape)
}

protected void unwrapOutputDocument(GenerationContext context, OperationShape shape) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
ServiceShape service = context.getService();
writer.write("t, err = decoder.GetElement(\"$LResult\")", shape.getId().getName(service));
handleDecodeError(writer, "out, metadata, ");
Expand All @@ -139,7 +139,7 @@ protected void unwrapOutputDocument(GenerationContext context, OperationShape sh
}

protected void unwrapErrorElement(GenerationContext context) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
writer.write("t, err = decoder.GetElement(\"Error\")");
XmlProtocolUtils.handleDecodeError(writer, "");
Symbol wrapNodeDecoder = SymbolUtils.createValueSymbolBuilder("WrapNodeDecoder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,49 +79,49 @@ public DocumentMemberSerVisitor(
@Override
public Void blobShape(BlobShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
context.getWriter().write("$L.Base64EncodeBytes($L)", dataDest, source);
context.getWriter().get().write("$L.Base64EncodeBytes($L)", dataDest, source);
return null;
}

@Override
public Void booleanShape(BooleanShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
context.getWriter().write("$L.Boolean($L)", dataDest, source);
context.getWriter().get().write("$L.Boolean($L)", dataDest, source);
return null;
}

@Override
public Void byteShape(ByteShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
context.getWriter().write("$L.Byte($L)", dataDest, source);
context.getWriter().get().write("$L.Byte($L)", dataDest, source);
return null;
}

@Override
public Void shortShape(ShortShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
context.getWriter().write("$L.Short($L)", dataDest, source);
context.getWriter().get().write("$L.Short($L)", dataDest, source);
return null;
}

@Override
public Void integerShape(IntegerShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
context.getWriter().write("$L.Integer($L)", dataDest, source);
context.getWriter().get().write("$L.Integer($L)", dataDest, source);
return null;
}

@Override
public Void longShape(LongShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
context.getWriter().write("$L.Long($L)", dataDest, source);
context.getWriter().get().write("$L.Long($L)", dataDest, source);
return null;
}

@Override
public Void floatShape(FloatShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
handleDecimal(writer, dataDest, "float64(" + source + ")",
() -> writer.write("$L.Float($L)", dataDest, source));
return null;
Expand All @@ -130,7 +130,7 @@ public Void floatShape(FloatShape shape) {
@Override
public Void doubleShape(DoubleShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
handleDecimal(writer, dataDest, source, () -> writer.write("$L.Double($L)", dataDest, source));
return null;
}
Expand All @@ -154,7 +154,7 @@ private void handleDecimal(GoWriter writer, String dataDest, String source, Runn
@Override
public Void timestampShape(TimestampShape shape) {
String source = CodegenUtils.getAsValueIfDereferencable(pointableIndex, member, dataSource);
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
writer.addUseImports(SmithyGoDependency.SMITHY_TIME);

switch (timestampFormat) {
Expand All @@ -179,7 +179,7 @@ public Void stringShape(StringShape shape) {
if (shape.hasTrait(EnumTrait.class)) {
source = String.format("string(%s)", source);
}
context.getWriter().write("$L.String($L)", dataDest, source);
context.getWriter().get().write("$L.String($L)", dataDest, source);
return null;
}

Expand Down Expand Up @@ -260,7 +260,7 @@ public Void mapShape(MapShape shape) {

private void writeDelegateFunction(Shape shape) {
String serFunctionName = ProtocolGenerator.getDocumentSerializerFunctionName(shape, context.getService(), context.getProtocolName());
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();

ProtocolUtils.writeSerDelegateFunction(context, writer, member, dataSource, (srcVar) -> {
writer.openBlock("if err := $L($L, $L); err != nil {", "}", serFunctionName, srcVar, dataDest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected void generateDocumentBodyShapeDeserializers(GenerationContext context,

@Override
protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
writer.addUseImports(AwsGoDependency.AWS_EC2QUERY_PROTOCOL);
writer.write("errorComponents, err := ec2query.GetErrorResponseComponents(errorBody)");
writer.write("if err != nil { return err }");
Expand All @@ -64,7 +64,7 @@ protected void unwrapOutputDocument(GenerationContext context, OperationShape sh
protected void unwrapErrorElement(GenerationContext context) {
Symbol wrapNodeDecoder = SymbolUtils.createValueSymbolBuilder("WrapNodeDecoder",
SmithyGoDependency.SMITHY_XML).build();
GoWriter writer = context.getWriter();
GoWriter writer = context.getWriter().get();
Consumer<String> unwrapElement = (String element) -> {
writer.write("t, err = decoder.GetElement($S)", element);
XmlProtocolUtils.handleDecodeError(writer, "");
Expand Down
Loading