Skip to content
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
  •  
  •  
  •  
3 changes: 1 addition & 2 deletions SMITHY_GO_CODEGEN_VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
a27260fac103bb3e98839df5d562bc36596e3c0d

a46ced700b2b64c1db83ace21668b666dd901980
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.go.codegen.GoSettings;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.ChainWritable;
import software.amazon.smithy.go.codegen.Writable;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
import software.amazon.smithy.go.codegen.SymbolUtils;
import software.amazon.smithy.go.codegen.TriConsumer;
import software.amazon.smithy.go.codegen.endpoints.EndpointResolutionGenerator;
import software.amazon.smithy.go.codegen.integration.ConfigField;
import software.amazon.smithy.go.codegen.integration.ConfigFieldResolver;
import software.amazon.smithy.go.codegen.integration.GoIntegration;
import software.amazon.smithy.go.codegen.integration.RuntimeClientPlugin;
Expand All @@ -48,18 +46,6 @@ public class AwsEndpointResolverInitializerGenerator implements GoIntegration {

private Map<String, Object> commonCodegenArgs;


private static final ConfigField EndpointResolverV2 = ConfigField.builder()
.name(EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME)
.type(buildPackageSymbol(EndpointResolutionGenerator.RESOLVER_INTERFACE_NAME))
.documentation(String.format("""
Resolves the endpoint used for a particular service operation.
This should be used over the deprecated %s.
""", EndpointGenerator.RESOLVER_INTERFACE_NAME)
)
.withHelper(true)
.build();

private static final ConfigFieldResolver ResolveEndpointResolverV2 = ConfigFieldResolver.builder()
.resolver(buildPackageSymbol(RESOLVE_ENDPOINT_RESOLVER_V2))
.location(ConfigFieldResolver.Location.CLIENT)
Expand Down Expand Up @@ -150,7 +136,6 @@ private Writable generateResolveMethod() {
public List<RuntimeClientPlugin> getClientPlugins() {
return ListUtils.of(
RuntimeClientPlugin.builder()
.addConfigField(EndpointResolverV2)
.addConfigFieldResolver(ResolveEndpointResolverV2)
.build()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,10 @@

package software.amazon.smithy.aws.go.codegen;

import java.util.Set;
import java.util.TreeSet;

import software.amazon.smithy.aws.go.codegen.customization.AwsCustomGoDependency;
import software.amazon.smithy.codegen.core.Symbol;
import software.amazon.smithy.go.codegen.GoWriter;
import software.amazon.smithy.go.codegen.SmithyGoDependency;
import software.amazon.smithy.go.codegen.SymbolUtils;
import software.amazon.smithy.go.codegen.integration.HttpProtocolTestGenerator;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestGenerator;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestGenerator.ConfigValue;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestRequestGenerator;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestResponseErrorGenerator;
import software.amazon.smithy.go.codegen.integration.HttpProtocolUnitTestResponseGenerator;
import software.amazon.smithy.go.codegen.integration.IdempotencyTokenMiddlewareGenerator;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator.GenerationContext;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.utils.SetUtils;

/**
* Utility methods for generating AWS protocols.
Expand All @@ -42,215 +27,6 @@ public final class AwsProtocolUtils {
private AwsProtocolUtils() {
}

/**
* Generates HTTP protocol tests with all required AWS-specific configuration set.
*
* @param context The generation context.
*/
public static void generateHttpProtocolTests(GenerationContext context) {
Set<HttpProtocolUnitTestGenerator.ConfigValue> configValues = new TreeSet<>(SetUtils.of(
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.REGION_CONFIG_NAME)
.value(writer -> writer.write("$S,", "us-west-2"))
.build(),
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.ENDPOINT_RESOLVER_CONFIG_NAME)
.value(writer -> {
writer.addUseImports(AwsGoDependency.AWS_CORE);
writer.openBlock("$L(func(region string, options $L) (e aws.Endpoint, err error) {", "}),",
EndpointGenerator.RESOLVER_FUNC_NAME, EndpointGenerator.RESOLVER_OPTIONS, () -> {
writer.write("e.URL = serverURL");
writer.write("e.SigningRegion = \"us-west-2\"");
writer.write("return e, err");
});
})
.build(),
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name("APIOptions")
.value(writer -> {
Symbol stackSymbol = SymbolUtils.createPointableSymbolBuilder("Stack",
SmithyGoDependency.SMITHY_MIDDLEWARE).build();
writer.openBlock("[]func($P) error{", "},", stackSymbol, () -> {
writer.openBlock("func(s $P) error {", "},", stackSymbol, () -> {
writer.write("s.Finalize.Clear()");
writer.write("s.Initialize.Remove(`OperationInputValidation`)");
writer.write("return nil");
});
});
})
.build()
));

// TODO can this check be replaced with a lookup into the runtime plugins?
if (IdempotencyTokenMiddlewareGenerator.hasOperationsWithIdempotencyToken(context.getModel(),
context.getService())) {
configValues.add(
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(IdempotencyTokenMiddlewareGenerator.IDEMPOTENCY_CONFIG_NAME)
.value(writer -> {
writer.addUseImports(SmithyGoDependency.SMITHY_RAND);
writer.addUseImports(SmithyGoDependency.SMITHY_TESTING);
writer.write("smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}),");
})
.build()
);
}

Set<ConfigValue> inputConfigValues = new TreeSet<>(configValues);
inputConfigValues.add(HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.HTTP_CLIENT_CONFIG_NAME)
.value(writer -> {
writer.addUseImports(AwsGoDependency.AWS_PROTOCOL_TEST_HTTP_CLIENT);
writer.write("protocoltesthttp.NewClient(),");
})
.build());

// skip request compression tests, not yet implemented in the SDK
Set<HttpProtocolUnitTestGenerator.SkipTest> inputSkipTests = new TreeSet<>(SetUtils.of(
// CBOR default value serialization (SHOULD)
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#OperationWithDefaults"))
.addTestName("RpcV2CborClientPopulatesDefaultValuesInInput")
.addTestName("RpcV2CborClientSkipsTopLevelDefaultValuesInInput")
.addTestName("RpcV2CborClientUsesExplicitlyProvidedMemberValuesOverDefaults")
.addTestName("RpcV2CborClientUsesExplicitlyProvidedValuesInTopLevel")
.addTestName("RpcV2CborClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional")
.build(),

HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restxml#RestXml"))
.operation(ShapeId.from("aws.protocoltests.restxml#HttpPayloadWithUnion"))
.addTestName("RestXmlHttpPayloadWithUnion")
.addTestName("RestXmlHttpPayloadWithUnsetUnion")
.build(),

// REST-JSON default value serialization
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithDefaults"))
.addTestName("RestJsonClientPopulatesDefaultValuesInInput")
.addTestName("RestJsonClientUsesExplicitlyProvidedValuesInTopLevel")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithNestedStructure"))
.addTestName("RestJsonClientPopulatesNestedDefaultValuesWhenMissing")
.build(),

HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithDefaults"))
.addTestName("AwsJson10ClientPopulatesDefaultValuesInInput")
.addTestName("AwsJson10ClientSkipsTopLevelDefaultValuesInInput")
.addTestName("AwsJson10ClientUsesExplicitlyProvidedMemberValuesOverDefaults")
.addTestName("AwsJson10ClientUsesExplicitlyProvidedValuesInTopLevel")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithNestedStructure"))
.addTestName("AwsJson10ClientPopulatesNestedDefaultValuesWhenMissing")
.build()
));

Set<HttpProtocolUnitTestGenerator.SkipTest> outputSkipTests = new TreeSet<>(SetUtils.of(
// CBOR default value deserialization (SHOULD)
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#OperationWithDefaults"))
.addTestName("RpcV2CborClientPopulatesDefaultsValuesWhenMissingInResponse")
.addTestName("RpcV2CborClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"))
.operation(ShapeId.from("smithy.protocoltests.rpcv2Cbor#RpcV2CborDenseMaps"))
.addTestName("RpcV2CborDeserializesDenseSetMapAndSkipsNull")
.build(),

// REST-JSON optional (SHOULD) test cases
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#JsonMaps"))
.addTestName("RestJsonDeserializesDenseSetMapAndSkipsNull")
.build(),

// REST-JSON default value deserialization
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithDefaults"))
.addTestName("RestJsonClientPopulatesDefaultsValuesWhenMissingInResponse")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#OperationWithNestedStructure"))
.addTestName("RestJsonClientPopulatesNestedDefaultsWhenMissingInResponseBody")
.build(),

// REST-XML opinionated test - prefix headers as empty vs nil map
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restxml#RestXml"))
.operation(ShapeId.from("aws.protocoltests.restxml#HttpPrefixHeaders"))
.addTestName("HttpPrefixHeadersAreNotPresent")
.build(),

HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.restjson#RestJson"))
.operation(ShapeId.from("aws.protocoltests.restjson#JsonUnions"))
.addTestName("RestJsonDeserializeIgnoreType")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#JsonUnions"))
.addTestName("AwsJson10DeserializeIgnoreType")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json#JsonProtocol"))
.operation(ShapeId.from("aws.protocoltests.json#JsonUnions"))
.addTestName("AwsJson11DeserializeIgnoreType")
.build(),

HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithDefaults"))
.addTestName("AwsJson10ClientPopulatesDefaultsValuesWhenMissingInResponse")
.addTestName("AwsJson10ClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse")
.build(),
// We don't populate default values if none are sent by the server
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithNestedStructure"))
.addTestName("AwsJson10ClientPopulatesNestedDefaultsWhenMissingInResponseBody")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithRequiredMembers"))
.addTestName("AwsJson10ClientErrorCorrectsWhenServerFailsToSerializeRequiredValues")
.build(),
HttpProtocolUnitTestGenerator.SkipTest.builder()
.service(ShapeId.from("aws.protocoltests.json10#JsonRpc10"))
.operation(ShapeId.from("aws.protocoltests.json10#OperationWithRequiredMembersWithDefaults"))
.addTestName("AwsJson10ClientErrorCorrectsWithDefaultValuesWhenServerFailsToSerializeRequiredValues")
.build()
));

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 initializeJsonDecoder(GoWriter writer, String bodyLocation) {
// Use a ring buffer and tee reader to help in pinpointing any deserialization errors.
writer.addUseImports(SmithyGoDependency.SMITHY_IO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
XmlProtocolUtils.writeXmlErrorMessageCodeDeserializer(context);
}

@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
public Map<String, ShapeId> getOperationErrors(GenerationContext context, OperationShape operation) {
Map<String, ShapeId> errors = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,6 @@ protected void deserializeError(GenerationContext context, StructureShape shape)
writer.write("return output");
}

@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
protected void writeErrorMessageCodeDeserializer(GenerationContext context) {
var tmpl = goTemplate("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,11 +513,6 @@ public void generateSharedDeserializerComponents(GenerationContext context) {
super.generateSharedDeserializerComponents(context);
}

@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
public void generateProtocolDocumentMarshalerUnmarshalDocument(GenerationContext context) {
JsonProtocolDocumentUtils.generateProtocolDocumentMarshalerUnmarshalDocument(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ abstract class RestXmlProtocolGenerator extends HttpBindingProtocolGenerator {
super(true);
}

@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
protected TimestampFormatTrait.Format getDocumentTimestampFormat() {
return TimestampFormatTrait.Format.DATE_TIME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
* a 2000+ line dumpster fire in this repo.
*/
public final class AwsRpc2CborProtocolGenerator extends Rpc2CborProtocolGenerator {
@Override
public void generateProtocolTests(GenerationContext context) {
AwsProtocolUtils.generateHttpProtocolTests(context);
}

@Override
public void generateEventStreamComponents(GenerationContext context) {
// This automagically wires up ALL the framing logic for both directions of streams. All we have to do is fill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func TestCredentialRefreshRetry(t *testing.T) {
Credentials: &mockCredentials{
credentials: credvalues,
},
EndpointResolverV2: &endpointResolver{},
})

_, err := svc.GetItem(context.Background(), nil)
Expand Down
Loading
Loading