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

Add support for json rpc protocol serde #599

Merged
merged 16 commits into from
Jul 13, 2020
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/smithy-aws-go-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tasks.withType<Test> {
}

dependencies {
api("software.amazon.smithy:smithy-aws-traits:1.0.2")
api("software.amazon.smithy:smithy-aws-traits:[1.0.2,1.1.0[")
api("software.amazon.smithy:smithy-go-codegen:0.1.0")
testCompile("org.junit.jupiter:junit-jupiter-api:5.4.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.4.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class AddAwsConfigFields implements GoIntegration {
public static final String LOG_LEVEL_CONFIG_NAME = "LogLevel";
public static final String RETRYER_CONFIG_NAME = "Retryer";
public static final String HTTP_SIGNER_CONFIG_NAME = "HTTPSigner";
public static final String IDEMPOTENCY_TOKEN_PROVIDER = "IdempotencyTokenProvider";


private static final List<ConfigField> UNIVERSAL_FIELDS = new ArrayList<>(SetUtils.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public byte getOrder() {

@Override
public List<ProtocolGenerator> getProtocolGenerators() {
return ListUtils.of(new AwsRestJson1(), new AwsRestXml());
return ListUtils.of(new AwsRestJson1(), new AwsJsonRpc1_0(), new AwsJsonRpc1_1(), new AwsRestXml());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

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

import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait;
import software.amazon.smithy.model.shapes.ShapeId;

/**
* Handles generating the awsJson1_0 protocol for services.
*
* @inheritDoc
*
* @see JsonRpcProtocolGenerator
*/
final class AwsJsonRpc1_0 extends JsonRpcProtocolGenerator {

@Override
protected String getDocumentContentType() {
return "application/x-amz-json-1.0";
}

@Override
public ShapeId getProtocol() {
return AwsJson1_0Trait.ID;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

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

import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait;
import software.amazon.smithy.model.shapes.ShapeId;

/**
* Handles generating the awsJson1_1 protocol for services.
*
* @inheritDoc
*
* @see JsonRpcProtocolGenerator
*/
public class AwsJsonRpc1_1 extends JsonRpcProtocolGenerator {

@Override
protected String getDocumentContentType() {
return "application/x-amz-json-1.1";
}

@Override
public ShapeId getProtocol() {
return AwsJson1_1Trait.ID;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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.Model;
import software.amazon.smithy.model.shapes.MemberShape;
Expand All @@ -49,13 +50,6 @@ static void generateHttpProtocolTests(GenerationContext context) {
.name(AddAwsConfigFields.REGION_CONFIG_NAME)
.value(writer -> writer.write("$S,", "us-west-2"))
.build(),
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.IDEMPOTENCY_TOKEN_PROVIDER)
JordonPhillips marked this conversation as resolved.
Show resolved Hide resolved
.value(writer -> {
writer.addUseImports(SmithyGoDependency.SMITHY_RAND);
writer.addUseImports(SmithyGoDependency.SMITHY_TESTING);
writer.write("smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}),");
}).build(),
HttpProtocolUnitTestGenerator.ConfigValue.builder()
.name(AddAwsConfigFields.HTTP_CLIENT_CONFIG_NAME)
.value(writer -> {
Expand Down Expand Up @@ -91,6 +85,20 @@ static void generateHttpProtocolTests(GenerationContext context) {
.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)
JordonPhillips marked this conversation as resolved.
Show resolved Hide resolved
.value(writer -> {
writer.addUseImports(SmithyGoDependency.SMITHY_RAND);
writer.addUseImports(SmithyGoDependency.SMITHY_TESTING);
writer.write("smithyrand.NewUUIDIdempotencyToken(&smithytesting.ByteLoop{}),");
})
.build()
);
}

new HttpProtocolTestGenerator(context,
(HttpProtocolUnitTestRequestGenerator.Builder) new HttpProtocolUnitTestRequestGenerator
.Builder()
Expand Down
Loading