Skip to content

Commit

Permalink
Use updated addImport method
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed May 15, 2023
1 parent 29935a0 commit ef77fc5
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static String getOperationDeserializerContextType(
private static List<String> getDefaultOperationSerdeContextTypes(TypeScriptWriter writer) {
List<String> contextInterfaceList = new ArrayList<>();
// Get default SerdeContext.
writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES);
contextInterfaceList.add("__SerdeContext");
return contextInterfaceList;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ private String registerBodyComparatorStub(String mediaType) {
additionalStubs.add("protocol-test-xml-stub.ts");
return "compareEquivalentXmlBodies(bodyString, r.body.toString())";
case "application/octet-stream":
writer.addImport("Encoder", "__Encoder", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Encoder", "__Encoder", TypeScriptDependency.SMITHY_TYPES);
additionalStubs.add("protocol-test-octet-stream-stub.ts");
return "compareEquivalentOctetStreamBodies(utf8Encoder, bodyString, r.body)";
case "text/plain":
Expand All @@ -590,7 +590,7 @@ private String registerBodyComparatorStub(String mediaType) {
default:
LOGGER.warning("Unable to compare bodies with unknown media type `" + mediaType
+ "`, defaulting to direct comparison.");
writer.addImport("Encoder", "__Encoder", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Encoder", "__Encoder", TypeScriptDependency.SMITHY_TYPES);
additionalStubs.add("protocol-test-unknown-type-stub.ts");
return "compareEquivalentUnknownTypeBodies(utf8Encoder, bodyString, r.body)";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ private void generateClientDefaults() {
+ "@internal");
writer.write("bodyLengthChecker?: __BodyLengthCalculator;\n");

writer.addImport("StreamCollector", "__StreamCollector", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("StreamCollector", "__StreamCollector", TypeScriptDependency.SMITHY_TYPES);
writer.writeDocs("A function that converts a stream into an array of bytes.\n"
+ "@internal");
writer.write("streamCollector?: __StreamCollector;\n");

// Note: Encoder and Decoder are both used for base64 and UTF.
writer.addImport("Encoder", "__Encoder", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Decoder", "__Decoder", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Encoder", "__Encoder", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("Decoder", "__Decoder", TypeScriptDependency.SMITHY_TYPES);

writer.writeDocs("The function that will be used to convert a base64-encoded string to a byte array.\n"
+ "@internal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private void generateEndpointParameters() {
Paths.get(CodegenUtils.SOURCE_FOLDER, ENDPOINT_FOLDER, ENDPOINT_PARAMETERS_FILE).toString(),
writer -> {
writer.addImport("EndpointParameters", "__EndpointParameters", "@aws-sdk/types");
writer.addImport("Provider", null, TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Provider", null, TypeScriptDependency.SMITHY_TYPES);

writer.openBlock(
"export interface ClientInputEndpointParameters {",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ public Void objectNode(ObjectNode node) {
ParameterGenerator parameterGenerator = new ParameterGenerator(localKey, param);

if (localKey.equals("endpoint")) {
writer.addImport("Endpoint", null, TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Endpoint", null, TypeScriptDependency.SMITHY_TYPES);
writer.addImport("EndpointV2", null, "@aws-sdk/types");
writer.addImport("Provider", null, TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Provider", null, TypeScriptDependency.SMITHY_TYPES);
}

if (writeDefaults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void addConfigInterfaceFields(
SymbolProvider symbolProvider,
TypeScriptWriter writer
) {
writer.addImport("Provider", "__Provider", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Provider", "__Provider", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("Logger", "__Logger", TypeScriptDependency.AWS_SDK_TYPES.packageName);

writer.writeDocs("Value for how many times a request will be made at most in case of retry.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void addConfigInterfaceFields(
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_DEFAULTS_MODE_BROWSER);
writer.addDependency(TypeScriptDependency.AWS_SDK_UTIL_DEFAULTS_MODE_NODE);
writer.addImport("DefaultsMode", "__DefaultsMode", TypeScriptDependency.AWS_SMITHY_CLIENT.packageName);
writer.addImport("Provider", "__Provider", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Provider", "__Provider", TypeScriptDependency.SMITHY_TYPES);
writer.writeDocs("The {@link @aws-sdk/smithy-client#DefaultsMode} that "
+ "will be used to determine how certain default configuration "
+ "options are resolved in the SDK.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ private void generateOperationRequestSerializer(

// Ensure that the request type is imported.
writer.addUseImports(requestType);
writer.addImport("Endpoint", "__Endpoint", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Endpoint", "__Endpoint", TypeScriptDependency.SMITHY_TYPES);

// e.g., se_ES
String methodName = ProtocolGenerator.getSerFunctionShortName(symbol);
Expand Down Expand Up @@ -1729,7 +1729,7 @@ private void generateOperationRequestDeserializer(

// Ensure that the request type is imported.
writer.addUseImports(requestType);
writer.addImport("Endpoint", "__Endpoint", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Endpoint", "__Endpoint", TypeScriptDependency.SMITHY_TYPES);
String methodName = ProtocolGenerator.getGenericDeserFunctionName(symbol) + "Request";
// Add the normalized input type.
Symbol inputType = symbol.expectProperty("inputType", Symbol.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void generateMetadataDeserializer(GenerationContext context, SymbolRefere
static void generateCollectBody(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();

writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES);
writer.write("// Collect low-level response body stream to Uint8Array.");
writer.openBlock("const collectBody = (streamBody: any = new Uint8Array(), context: __SerdeContext): "
+ "Promise<Uint8Array> => {", "};", () -> {
Expand All @@ -278,7 +278,7 @@ static void generateCollectBody(GenerationContext context) {
static void generateCollectBodyString(GenerationContext context) {
TypeScriptWriter writer = context.getWriter();

writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES);
writer.write("// Encode Uint8Array data into string with utf-8.");
writer.write("const collectBodyString = (streamBody: any, context: __SerdeContext): Promise<string> => "
+ "collectBody(streamBody, context).then(body => context.utf8Encoder(body))");
Expand Down Expand Up @@ -435,8 +435,7 @@ static void writeHostPrefix(GenerationContext context, OperationShape operation)
writer.write("let { hostname: resolvedHostname } = await context.endpoint();");
// Check if disableHostPrefixInjection has been set to true at runtime
writer.openBlock("if (context.disableHostPrefix !== true) {", "}", () -> {
writer.addImport("isValidHostname", "__isValidHostname",
TypeScriptDependency.PROTOCOL_HTTP.packageName);
writer.addImport("isValidHostname", "__isValidHostname", TypeScriptDependency.PROTOCOL_HTTP);
writer.write("resolvedHostname = $S + resolvedHostname;", trait.getHostPrefix().toString());
if (operation.getInput().isPresent()) {
List<SmithyPattern.Segment> prefixLabels = trait.getHostPrefix().getLabels();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void generateSharedComponents(GenerationContext context) {
// Write a function to generate HTTP requests since they're so similar.
SymbolReference requestType = getApplicationProtocol().getRequestType();
writer.addUseImports(requestType);
writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("SerdeContext", "__SerdeContext", TypeScriptDependency.SMITHY_TYPES);
writer.addImport("HeaderBag", "__HeaderBag", "@aws-sdk/types");
writer.openBlock("const buildHttpRpcRequest = async (\n"
+ " context: __SerdeContext,\n"
Expand Down Expand Up @@ -231,7 +231,7 @@ private void generateOperationSerializer(GenerationContext context, OperationSha

// Ensure that the request type is imported.
writer.addUseImports(requestType);
writer.addImport("Endpoint", "__Endpoint", TypeScriptDependency.SMITHY_TYPES.packageName);
writer.addImport("Endpoint", "__Endpoint", TypeScriptDependency.SMITHY_TYPES);
// e.g., se_ES
String methodName = ProtocolGenerator.getSerFunctionShortName(symbol);
// e.g., serializeAws_restJson1_1ExecuteStatement
Expand Down

0 comments on commit ef77fc5

Please sign in to comment.