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

chore(codegen): update to Smithy 1.12.0 #2878

Merged
merged 2 commits into from
Oct 7, 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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/generic-client-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.11.0, 1.12.0[")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.12.0, 1.13.0[")
implementation(project(":smithy-aws-typescript-codegen"))
}

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.11.0, 1.12.0[")
implementation("software.amazon.smithy:smithy-aws-protocol-tests:[1.12.0, 1.13.0[")
implementation(project(":smithy-aws-typescript-codegen"))
}

Expand Down
5 changes: 4 additions & 1 deletion codegen/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import software.amazon.smithy.aws.traits.ServiceTrait
import kotlin.streams.toList

buildscript {
repositories {
mavenCentral()
}
dependencies {
"classpath"("software.amazon.smithy:smithy-aws-traits:[1.11.0,1.12.0[")
"classpath"("software.amazon.smithy:smithy-aws-traits:[1.12.0,1.13.0[")
}
}

Expand Down
12 changes: 6 additions & 6 deletions codegen/smithy-aws-typescript-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("software.amazon.smithy:smithy-model:[1.11.0, 1.12.0[")
classpath("software.amazon.smithy:smithy-model:[1.12.0, 1.13.0[")
}
}

dependencies {
api("software.amazon.smithy:smithy-aws-cloudformation-traits:[1.11.0, 1.12.0[")
api("software.amazon.smithy:smithy-aws-traits:[1.11.0, 1.12.0[")
api("software.amazon.smithy:smithy-waiters:[1.11.0, 1.12.0[")
api("software.amazon.smithy:smithy-aws-iam-traits:[1.11.0, 1.12.0[")
api("software.amazon.smithy:smithy-protocol-test-traits:[1.11.0, 1.12.0[")
api("software.amazon.smithy:smithy-aws-cloudformation-traits:[1.12.0, 1.13.0[")
api("software.amazon.smithy:smithy-aws-traits:[1.12.0, 1.13.0[")
api("software.amazon.smithy:smithy-waiters:[1.12.0, 1.13.0[")
api("software.amazon.smithy:smithy-aws-iam-traits:[1.12.0, 1.13.0[")
api("software.amazon.smithy:smithy-protocol-test-traits:[1.12.0, 1.13.0[")
api("software.amazon.smithy.typescript:smithy-typescript-codegen:0.6.0")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,6 @@ private static boolean filterMalformedRequestTests(
return true;
}

//TODO: Fixed after Smithy 1.11.0
if (testCase.getId().equals("RestJsonPathTimestampDefaultRejectsDifferent8601Formats_case14")) {
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public void testSomeLibraryMethod() {
Shape service = model.expectShape((ShapeId.from("smithy.example#OriginalName")));
AwsServiceIdIntegration integration = new AwsServiceIdIntegration();
TypeScriptSettings settings = new TypeScriptSettings();
settings.setService(ShapeId.from("smithy.example#OriginalName"));
SymbolProvider provider = TypeScriptCodegenPlugin.createSymbolProvider(model, settings);
SymbolProvider decorated = integration.decorateSymbolProvider(settings, model, provider);
Symbol symbol = decorated.toSymbol(service);
Expand Down
34 changes: 34 additions & 0 deletions protocol_tests/aws-ec2/src/EC2Protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import {
GreetingWithErrorsCommandInput,
GreetingWithErrorsCommandOutput,
} from "./commands/GreetingWithErrorsCommand";
import {
HostWithPathOperationCommand,
HostWithPathOperationCommandInput,
HostWithPathOperationCommandOutput,
} from "./commands/HostWithPathOperationCommand";
import {
IgnoresWrappingXmlNameCommand,
IgnoresWrappingXmlNameCommandInput,
Expand Down Expand Up @@ -219,6 +224,35 @@ export class EC2Protocol extends EC2ProtocolClient {
}
}

public hostWithPathOperation(
args: HostWithPathOperationCommandInput,
options?: __HttpHandlerOptions
): Promise<HostWithPathOperationCommandOutput>;
public hostWithPathOperation(
args: HostWithPathOperationCommandInput,
cb: (err: any, data?: HostWithPathOperationCommandOutput) => void
): void;
public hostWithPathOperation(
args: HostWithPathOperationCommandInput,
options: __HttpHandlerOptions,
cb: (err: any, data?: HostWithPathOperationCommandOutput) => void
): void;
public hostWithPathOperation(
args: HostWithPathOperationCommandInput,
optionsOrCb?: __HttpHandlerOptions | ((err: any, data?: HostWithPathOperationCommandOutput) => void),
cb?: (err: any, data?: HostWithPathOperationCommandOutput) => void
): Promise<HostWithPathOperationCommandOutput> | void {
const command = new HostWithPathOperationCommand(args);
if (typeof optionsOrCb === "function") {
this.send(command, optionsOrCb);
} else if (typeof cb === "function") {
if (typeof optionsOrCb !== "object") throw new Error(`Expect http options but get ${typeof optionsOrCb}`);
this.send(command, optionsOrCb || {}, cb);
} else {
return this.send(command, optionsOrCb);
}
}

/**
* The xmlName trait on the output structure is ignored in AWS Query.
*
Expand Down
6 changes: 6 additions & 0 deletions protocol_tests/aws-ec2/src/EC2ProtocolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ import {
EndpointWithHostLabelOperationCommandOutput,
} from "./commands/EndpointWithHostLabelOperationCommand";
import { GreetingWithErrorsCommandInput, GreetingWithErrorsCommandOutput } from "./commands/GreetingWithErrorsCommand";
import {
HostWithPathOperationCommandInput,
HostWithPathOperationCommandOutput,
} from "./commands/HostWithPathOperationCommand";
import {
IgnoresWrappingXmlNameCommandInput,
IgnoresWrappingXmlNameCommandOutput,
Expand Down Expand Up @@ -84,6 +88,7 @@ export type ServiceInputTypes =
| EndpointOperationCommandInput
| EndpointWithHostLabelOperationCommandInput
| GreetingWithErrorsCommandInput
| HostWithPathOperationCommandInput
| IgnoresWrappingXmlNameCommandInput
| NestedStructuresCommandInput
| NoInputAndOutputCommandInput
Expand All @@ -106,6 +111,7 @@ export type ServiceOutputTypes =
| EndpointOperationCommandOutput
| EndpointWithHostLabelOperationCommandOutput
| GreetingWithErrorsCommandOutput
| HostWithPathOperationCommandOutput
| IgnoresWrappingXmlNameCommandOutput
| NestedStructuresCommandOutput
| NoInputAndOutputCommandOutput
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { getSerdePlugin } from "@aws-sdk/middleware-serde";
import { HttpRequest as __HttpRequest, HttpResponse as __HttpResponse } from "@aws-sdk/protocol-http";
import { Command as $Command } from "@aws-sdk/smithy-client";
import {
FinalizeHandlerArguments,
Handler,
HandlerExecutionContext,
HttpHandlerOptions as __HttpHandlerOptions,
MetadataBearer as __MetadataBearer,
MiddlewareStack,
SerdeContext as __SerdeContext,
} from "@aws-sdk/types";

import { EC2ProtocolClientResolvedConfig, ServiceInputTypes, ServiceOutputTypes } from "../EC2ProtocolClient";
import {
deserializeAws_ec2HostWithPathOperationCommand,
serializeAws_ec2HostWithPathOperationCommand,
} from "../protocols/Aws_ec2";

export interface HostWithPathOperationCommandInput {}
export interface HostWithPathOperationCommandOutput extends __MetadataBearer {}

export class HostWithPathOperationCommand extends $Command<
HostWithPathOperationCommandInput,
HostWithPathOperationCommandOutput,
EC2ProtocolClientResolvedConfig
> {
// Start section: command_properties
// End section: command_properties

constructor(readonly input: HostWithPathOperationCommandInput) {
// Start section: command_constructor
super();
// End section: command_constructor
}

/**
* @internal
*/
resolveMiddleware(
clientStack: MiddlewareStack<ServiceInputTypes, ServiceOutputTypes>,
configuration: EC2ProtocolClientResolvedConfig,
options?: __HttpHandlerOptions
): Handler<HostWithPathOperationCommandInput, HostWithPathOperationCommandOutput> {
this.middlewareStack.use(getSerdePlugin(configuration, this.serialize, this.deserialize));

const stack = clientStack.concat(this.middlewareStack);

const { logger } = configuration;
const clientName = "EC2ProtocolClient";
const commandName = "HostWithPathOperationCommand";
const handlerExecutionContext: HandlerExecutionContext = {
logger,
clientName,
commandName,
inputFilterSensitiveLog: (input: any) => input,
outputFilterSensitiveLog: (output: any) => output,
};
const { requestHandler } = configuration;
return stack.resolve(
(request: FinalizeHandlerArguments<any>) =>
requestHandler.handle(request.request as __HttpRequest, options || {}),
handlerExecutionContext
);
}

private serialize(input: HostWithPathOperationCommandInput, context: __SerdeContext): Promise<__HttpRequest> {
return serializeAws_ec2HostWithPathOperationCommand(input, context);
}

private deserialize(output: __HttpResponse, context: __SerdeContext): Promise<HostWithPathOperationCommandOutput> {
return deserializeAws_ec2HostWithPathOperationCommand(output, context);
}

// Start section: command_body_extra
// End section: command_body_extra
}
1 change: 1 addition & 0 deletions protocol_tests/aws-ec2/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from "./commands/EmptyInputAndEmptyOutputCommand";
export * from "./commands/EndpointOperationCommand";
export * from "./commands/EndpointWithHostLabelOperationCommand";
export * from "./commands/GreetingWithErrorsCommand";
export * from "./commands/HostWithPathOperationCommand";
export * from "./commands/IgnoresWrappingXmlNameCommand";
export * from "./commands/NestedStructuresCommand";
export * from "./commands/NoInputAndOutputCommand";
Expand Down
61 changes: 61 additions & 0 deletions protocol_tests/aws-ec2/src/protocols/Aws_ec2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ import {
EndpointWithHostLabelOperationCommandOutput,
} from "../commands/EndpointWithHostLabelOperationCommand";
import { GreetingWithErrorsCommandInput, GreetingWithErrorsCommandOutput } from "../commands/GreetingWithErrorsCommand";
import {
HostWithPathOperationCommandInput,
HostWithPathOperationCommandOutput,
} from "../commands/HostWithPathOperationCommand";
import {
IgnoresWrappingXmlNameCommandInput,
IgnoresWrappingXmlNameCommandOutput,
Expand Down Expand Up @@ -177,6 +181,20 @@ export const serializeAws_ec2GreetingWithErrorsCommand = async (
return buildHttpRpcRequest(context, headers, "/", undefined, body);
};

export const serializeAws_ec2HostWithPathOperationCommand = async (
input: HostWithPathOperationCommandInput,
context: __SerdeContext
): Promise<__HttpRequest> => {
const headers: __HeaderBag = {
"content-type": "application/x-www-form-urlencoded",
};
const body = buildFormUrlencodedString({
Action: "HostWithPathOperation",
Version: "2020-01-08",
});
return buildHttpRpcRequest(context, headers, "/", undefined, body);
};

export const serializeAws_ec2IgnoresWrappingXmlNameCommand = async (
input: IgnoresWrappingXmlNameCommandInput,
context: __SerdeContext
Expand Down Expand Up @@ -605,6 +623,49 @@ const deserializeAws_ec2GreetingWithErrorsCommandError = async (
return Promise.reject(Object.assign(new Error(message), response));
};

export const deserializeAws_ec2HostWithPathOperationCommand = async (
output: __HttpResponse,
context: __SerdeContext
): Promise<HostWithPathOperationCommandOutput> => {
if (output.statusCode >= 300) {
return deserializeAws_ec2HostWithPathOperationCommandError(output, context);
}
await collectBody(output.body, context);
const response: HostWithPathOperationCommandOutput = {
$metadata: deserializeMetadata(output),
};
return Promise.resolve(response);
};

const deserializeAws_ec2HostWithPathOperationCommandError = async (
output: __HttpResponse,
context: __SerdeContext
): Promise<HostWithPathOperationCommandOutput> => {
const parsedOutput: any = {
...output,
body: await parseBody(output.body, context),
};
let response: __SmithyException & __MetadataBearer & { [key: string]: any };
let errorCode = "UnknownError";
errorCode = loadEc2ErrorCode(output, parsedOutput.body);
switch (errorCode) {
default:
const parsedBody = parsedOutput.body;
errorCode = parsedBody.Errors.Error.code || parsedBody.Errors.Error.Code || errorCode;
response = {
...parsedBody.Errors.Error,
name: `${errorCode}`,
message: parsedBody.Errors.Error.message || parsedBody.Errors.Error.Message || errorCode,
$fault: "client",
$metadata: deserializeMetadata(output),
} as any;
}
const message = response.message || response.Message || errorCode;
response.message = message;
delete response.Message;
return Promise.reject(Object.assign(new Error(message), response));
};

export const deserializeAws_ec2IgnoresWrappingXmlNameCommand = async (
output: __HttpResponse,
context: __SerdeContext
Expand Down
51 changes: 51 additions & 0 deletions protocol_tests/aws-ec2/test/functional/ec2query.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { HttpHandler, HttpRequest, HttpResponse } from "@aws-sdk/protocol-http";
import { Encoder as __Encoder } from "@aws-sdk/types";
import { HeaderBag, HttpHandlerOptions } from "@aws-sdk/types";
import { Readable } from "stream";

import { EmptyInputAndEmptyOutputCommand } from "../../src/commands/EmptyInputAndEmptyOutputCommand";
import { EndpointOperationCommand } from "../../src/commands/EndpointOperationCommand";
import { EndpointWithHostLabelOperationCommand } from "../../src/commands/EndpointWithHostLabelOperationCommand";
import { GreetingWithErrorsCommand } from "../../src/commands/GreetingWithErrorsCommand";
import { HostWithPathOperationCommand } from "../../src/commands/HostWithPathOperationCommand";
import { IgnoresWrappingXmlNameCommand } from "../../src/commands/IgnoresWrappingXmlNameCommand";
import { NestedStructuresCommand } from "../../src/commands/NestedStructuresCommand";
import { NoInputAndOutputCommand } from "../../src/commands/NoInputAndOutputCommand";
Expand Down Expand Up @@ -444,6 +446,38 @@ it("Ec2ComplexError:Error:GreetingWithErrors", async () => {
fail("Expected an exception to be thrown from response");
});

/**
* Custom endpoints supplied by users can have paths
*/
it("Ec2QueryHostWithPath:Request", async () => {
const client = new EC2ProtocolClient({
...clientParams,
endpoint: "https://example.com/custom",
requestHandler: new RequestSerializationTestHandler(),
});

const command = new HostWithPathOperationCommand({});
try {
await client.send(command);
fail("Expected an EXPECTED_REQUEST_SERIALIZATION_ERROR to be thrown");
return;
} catch (err) {
if (!(err instanceof EXPECTED_REQUEST_SERIALIZATION_ERROR)) {
fail(err);
return;
}
const r = err.request;
expect(r.method).toBe("POST");
expect(r.path).toBe("/custom/");

expect(r.body).toBeDefined();
const utf8Encoder = client.config.utf8Encoder;
const bodyString = `Action=HostWithPathOperation&Version=2020-01-08`;
const unequalParts: any = compareEquivalentUnknownTypeBodies(utf8Encoder, bodyString, r.body);
expect(unequalParts).toBeUndefined();
}
});

/**
* The xmlName trait on the output structure is ignored in the ec2 protocol
*/
Expand Down Expand Up @@ -2291,3 +2325,20 @@ const compareEquivalentFormUrlencodedBodies = (expectedBody: string, generatedBo

return compareParts(expectedParts, generatedParts);
};

/**
* Returns a map of key names that were un-equal to value objects showing the
* discrepancies between the components.
*/
const compareEquivalentUnknownTypeBodies = (
utf8Encoder: __Encoder,
expectedBody: string,
generatedBody: string | Uint8Array
): Object => {
const expectedParts = { Value: expectedBody };
const generatedParts = {
Value: generatedBody instanceof Uint8Array ? utf8Encoder(generatedBody) : generatedBody,
};

return compareParts(expectedParts, generatedParts);
};
Loading