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

Migrate to smithy 1.7 and generate APIGateway service #1240

Merged
merged 11 commits into from
May 5, 2021
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ smithy-go-publish-local:

gen-config-asserts:
@echo "Generating SDK config package implementor assertions"
cd config && go generate
cd config \
&& go mod tidy \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does mod tidy need to be mixed into these tasks? mod tidy has a separate task that will be run by make generate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to run go mod tidy, when we cd into Config. Or we get an error related to go sum entry not found.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah i see, could also set GOFLAGS=-mod=mod here as well potentially instead of running mod tidy.

&& go generate

gen-repo-mod-replace:
@echo "Generating go.mod replace for repo modules"
Expand Down Expand Up @@ -140,6 +142,7 @@ copy-attributevalue-feature:
sed -i.bk 's:ddbtypes\.:ddb.:g' "convert.go" &&\
sed -i.bk 's:Streams::g' "convert.go" && \
rm -rf ./*.bk && \
go mod tidy && \
gofmt -w -s . && \
go test .

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 @@ -20,7 +20,7 @@ plugins {
}

dependencies {
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.6.1,1.7.0[")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.6.0,2.0.0[")
compile(project(":smithy-aws-go-codegen"))
}

Expand Down
46 changes: 41 additions & 5 deletions codegen/sdk-codegen/aws-models/apigateway.2015-07-09.json
Original file line number Diff line number Diff line change
Expand Up @@ -5251,7 +5251,8 @@
"parameters": {
"target": "com.amazonaws.apigateway#MapOfStringToString",
"traits": {
"smithy.api#documentation": "<p>A key-value map of query string parameters that specify properties of the export, depending on the requested <code>exportType</code>. For <code>exportType</code> <code>oas30</code> and <code>swagger</code>, any combination of the following parameters are supported: <code>extensions='integrations'</code> or <code>extensions='apigateway'</code> will export the API with x-amazon-apigateway-integration extensions. <code>extensions='authorizers'</code> will export the API with x-amazon-apigateway-authorizer extensions. <code>postman</code> will export the API with Postman extensions, allowing for import to the Postman tool</p>"
"smithy.api#documentation": "<p>A key-value map of query string parameters that specify properties of the export, depending on the requested <code>exportType</code>. For <code>exportType</code> <code>oas30</code> and <code>swagger</code>, any combination of the following parameters are supported: <code>extensions='integrations'</code> or <code>extensions='apigateway'</code> will export the API with x-amazon-apigateway-integration extensions. <code>extensions='authorizers'</code> will export the API with x-amazon-apigateway-authorizer extensions. <code>postman</code> will export the API with Postman extensions, allowing for import to the Postman tool</p>",
"smithy.api#httpQueryParams": {}
}
},
"accepts": {
Expand Down Expand Up @@ -6226,7 +6227,8 @@
"parameters": {
"target": "com.amazonaws.apigateway#MapOfStringToString",
"traits": {
"smithy.api#documentation": "<p>A string-to-string key-value map of query parameters <code>sdkType</code>-dependent properties of the SDK. For <code>sdkType</code> of <code>objectivec</code> or <code>swift</code>, a parameter named <code>classPrefix</code> is required. For <code>sdkType</code> of <code>android</code>, parameters named <code>groupId</code>, <code>artifactId</code>, <code>artifactVersion</code>, and <code>invokerPackage</code> are required. For <code>sdkType</code> of <code>java</code>, parameters named <code>serviceName</code> and <code>javaPackageName</code> are required. </p>"
"smithy.api#documentation": "<p>A string-to-string key-value map of query parameters <code>sdkType</code>-dependent properties of the SDK. For <code>sdkType</code> of <code>objectivec</code> or <code>swift</code>, a parameter named <code>classPrefix</code> is required. For <code>sdkType</code> of <code>android</code>, parameters named <code>groupId</code>, <code>artifactId</code>, <code>artifactVersion</code>, and <code>invokerPackage</code> are required. For <code>sdkType</code> of <code>java</code>, parameters named <code>serviceName</code> and <code>javaPackageName</code> are required. </p>",
"smithy.api#httpQueryParams": {}
}
}
},
Expand Down Expand Up @@ -6965,6 +6967,14 @@
"com.amazonaws.apigateway#ImportApiKeysRequest": {
"type": "structure",
"members": {
"body": {
"target": "com.amazonaws.apigateway#Blob",
"traits": {
"smithy.api#documentation": "<p>The payload of the POST request to import API keys. For the payload format, see <a href=\"https://docs.aws.amazon.com/apigateway/latest/developerguide/api-key-file-format.html\">API Key File Format</a>.</p>",
"smithy.api#httpPayload": {},
"smithy.api#required": {}
}
},
"format": {
"target": "com.amazonaws.apigateway#ApiKeysFormat",
"traits": {
Expand Down Expand Up @@ -7042,6 +7052,14 @@
"smithy.api#documentation": "<p>A query parameter to specify whether to rollback the documentation importation (<code>true</code>) or not (<code>false</code>) when a warning is encountered. The default value is <code>false</code>.</p>",
"smithy.api#httpQuery": "failonwarnings"
}
},
"body": {
"target": "com.amazonaws.apigateway#Blob",
"traits": {
"smithy.api#documentation": "<p>[Required] Raw byte array representing the to-be-imported documentation parts. To import from an OpenAPI file, this is a JSON object.</p>",
"smithy.api#httpPayload": {},
"smithy.api#required": {}
}
}
},
"traits": {
Expand Down Expand Up @@ -7095,7 +7113,16 @@
"parameters": {
"target": "com.amazonaws.apigateway#MapOfStringToString",
"traits": {
"smithy.api#documentation": "<p>A key-value map of context-specific query string parameters specifying the behavior of different API importing operations. The following shows operation-specific parameters and their supported values.</p>\n <p> To exclude <a>DocumentationParts</a> from the import, set <code>parameters</code> as <code>ignore=documentation</code>.</p>\n <p> To configure the endpoint type, set <code>parameters</code> as <code>endpointConfigurationTypes=EDGE</code>, <code>endpointConfigurationTypes=REGIONAL</code>, or <code>endpointConfigurationTypes=PRIVATE</code>. The default endpoint type is <code>EDGE</code>.</p>\n <p> To handle imported <code>basepath</code>, set <code>parameters</code> as <code>basepath=ignore</code>, <code>basepath=prepend</code> or <code>basepath=split</code>.</p>\n <p>For example, the AWS CLI command to exclude documentation from the imported API is:</p> \n <pre><code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code></pre>\n <p>The AWS CLI command to set the regional endpoint on the imported API is:</p>\n <pre><code>aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'</code></pre>"
"smithy.api#documentation": "<p>A key-value map of context-specific query string parameters specifying the behavior of different API importing operations. The following shows operation-specific parameters and their supported values.</p>\n <p> To exclude <a>DocumentationParts</a> from the import, set <code>parameters</code> as <code>ignore=documentation</code>.</p>\n <p> To configure the endpoint type, set <code>parameters</code> as <code>endpointConfigurationTypes=EDGE</code>, <code>endpointConfigurationTypes=REGIONAL</code>, or <code>endpointConfigurationTypes=PRIVATE</code>. The default endpoint type is <code>EDGE</code>.</p>\n <p> To handle imported <code>basepath</code>, set <code>parameters</code> as <code>basepath=ignore</code>, <code>basepath=prepend</code> or <code>basepath=split</code>.</p>\n <p>For example, the AWS CLI command to exclude documentation from the imported API is:</p> \n <pre><code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code></pre>\n <p>The AWS CLI command to set the regional endpoint on the imported API is:</p>\n <pre><code>aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'</code></pre>",
"smithy.api#httpQueryParams": {}
}
},
"body": {
"target": "com.amazonaws.apigateway#Blob",
"traits": {
"smithy.api#documentation": "<p>[Required] The POST request body containing external API definitions. Currently, only OpenAPI definition JSON/YAML files are supported. The maximum size of the API definition file is 6MB.</p>",
"smithy.api#httpPayload": {},
"smithy.api#required": {}
}
}
},
Expand Down Expand Up @@ -8569,7 +8596,16 @@
"parameters": {
"target": "com.amazonaws.apigateway#MapOfStringToString",
"traits": {
"smithy.api#documentation": "<p>Custom header parameters as part of the request. For example, to exclude <a>DocumentationParts</a> from an imported API, set <code>ignore=documentation</code> as a <code>parameters</code> value, as in the AWS CLI command of <code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code>.</p>"
"smithy.api#documentation": "<p>Custom header parameters as part of the request. For example, to exclude <a>DocumentationParts</a> from an imported API, set <code>ignore=documentation</code> as a <code>parameters</code> value, as in the AWS CLI command of <code>aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'</code>.</p>",
"smithy.api#httpQueryParams": {}
}
},
"body": {
"target": "com.amazonaws.apigateway#Blob",
"traits": {
"smithy.api#documentation": "<p>[Required] The PUT request body containing external API definitions. Currently, only OpenAPI definition JSON/YAML files are supported. The maximum size of the API definition file is 6MB.</p>",
"smithy.api#httpPayload": {},
"smithy.api#required": {}
}
}
},
Expand Down Expand Up @@ -9862,7 +9898,7 @@
"basePath": {
"target": "com.amazonaws.apigateway#String",
"traits": {
"smithy.api#documentation": "<p>[Required] The base path of the <a>BasePathMapping</a> resource to change.</p>\n <p>To specify an empty base path, set this parameter to <code>'(none)'</code>.</p>",
"smithy.api#documentation": "<p>[Required] The base path of the <a>BasePathMappipDocumentGetSdkInputng</a> resource to change.</p>\n <p>To specify an empty base path, set this parameter to <code>'(none)'</code>.</p>",
"smithy.api#httpLabel": {},
"smithy.api#required": {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
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.SyntheticClone;
import software.amazon.smithy.go.codegen.integration.HttpRpcProtocolGenerator;
import software.amazon.smithy.go.codegen.integration.ProtocolGenerator;
import software.amazon.smithy.go.codegen.integration.ProtocolUtils;
import software.amazon.smithy.model.knowledge.HttpBinding;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ServiceShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.StructureShape;
Expand Down Expand Up @@ -52,16 +54,18 @@ protected void generateDocumentBodyShapeSerializers(GenerationContext context, S
@Override
protected void serializeInputDocument(GenerationContext context, OperationShape operation) {
GoWriter writer = context.getWriter();
ServiceShape service = context.getService();
StructureShape input = ProtocolUtils.expectInput(context.getModel(), operation);
String functionName = ProtocolGenerator.getDocumentSerializerFunctionName(input, getProtocolName());
String functionName = ProtocolGenerator.getDocumentSerializerFunctionName(
input, context.getService(), getProtocolName());
writer.addUseImports(AwsGoDependency.AWS_QUERY_PROTOCOL);

writer.addUseImports(SmithyGoDependency.BYTES);
writer.write("bodyWriter := bytes.NewBuffer(nil)");
writer.write("bodyEncoder := query.NewEncoder(bodyWriter)");
writer.write("body := bodyEncoder.Object()");
writer.write("body.Key(\"Action\").String($S)", operation.getId().getName());
writer.write("body.Key(\"Version\").String($S)", context.getService().getVersion());
writer.write("body.Key(\"Action\").String($S)", operation.getId().getName(service));
writer.write("body.Key(\"Version\").String($S)", service.getVersion());
writer.write("");

if (!input.members().isEmpty()) {
Expand Down Expand Up @@ -91,7 +95,8 @@ protected void generateDocumentBodyShapeDeserializers(GenerationContext context,
protected void deserializeOutputDocument(GenerationContext context, OperationShape operation) {
GoWriter writer = context.getWriter();
StructureShape output = ProtocolUtils.expectOutput(context.getModel(), operation);
String functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(output, getProtocolName());
String functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
output, context.getService(), getProtocolName());
initializeXmlDecoder(writer, "response.Body", "out, metadata, ","nil");
unwrapOutputDocument(context, operation);
writer.write("err = $L(&output, decoder)", functionName);
Expand All @@ -106,12 +111,13 @@ protected void deserializeError(GenerationContext context, StructureShape shape)
writer.write("output := &$T{}", symbol);
writer.insertTrailingNewline();
if (isShapeWithResponseBindings(context.getModel(), shape, HttpBinding.Location.DOCUMENT)) {
String documentDeserFunctionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, getProtocolName());
String functionName = ProtocolGenerator.getDocumentDeserializerFunctionName(
shape, context.getService(), context.getProtocolName());

writer.addUseImports(SmithyGoDependency.IO);
initializeXmlDecoder(writer, "errorBody", "output");
unwrapErrorElement(context);
writer.write("err = $L(&output, decoder)", documentDeserFunctionName);
writer.write("err = $L(&output, decoder)", functionName);
XmlProtocolUtils.handleDecodeError(writer, "");
writer.insertTrailingNewline();
}
Expand All @@ -120,7 +126,8 @@ protected void deserializeError(GenerationContext context, StructureShape shape)

protected void unwrapOutputDocument(GenerationContext context, OperationShape shape) {
GoWriter writer = context.getWriter();
writer.write("t, err = decoder.GetElement(\"$LResult\")", shape.getId().getName());
ServiceShape service = context.getService();
writer.write("t, err = decoder.GetElement(\"$LResult\")", shape.getId().getName(service));
handleDecodeError(writer, "out, metadata, ");
Symbol wrapNodeDecoder = SymbolUtils.createValueSymbolBuilder("WrapNodeDecoder",
SmithyGoDependency.SMITHY_XML).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Void mapShape(MapShape shape) {
}

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

ProtocolUtils.writeSerDelegateFunction(context, writer, member, dataSource, (srcVar) -> {
Expand Down
Loading