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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ By default, the Smithy TypeScript code generators provide the code generation fr
| `useLegacyAuth` | No | **NOT RECOMMENDED, AVAILABLE ONLY FOR BACKWARD COMPATIBILITY CONCERNS.** Flag that enables using legacy auth. When in doubt, use the default identity and auth behavior (not configuring `useLegacyAuth`) as the golden path. |
| `serviceProtocolPriority` | No | Map of service `ShapeId` strings to lists of protocol `ShapeId` strings. Used to override protocol selection behavior. |
| `defaultProtocolPriority` | No | List of protocol `ShapeId` strings. Lower precedence than `serviceProtocolPriority` but applies to all services. |
| `generateIndexTests` | No | Default=`false`. Whether to generate a set of tests that does a basic validation of the export surface of the generated client package. The tests can be run with the script `test:index` in the generated package. |

#### `typescript-client-codegen` plugin artifacts

Expand Down
1 change: 1 addition & 0 deletions private/my-local-model-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build:es": "tsc -p tsconfig.es.json",
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"test:index": "tsc --noEmit ./test/index-types.ts && node ./test/index-objects.spec.mjs",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"prepack": "yarn run clean && yarn run build"
},
Expand Down
17 changes: 17 additions & 0 deletions private/my-local-model-schema/test/index-objects.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
GetNumbersCommand,
TradeEventStreamCommand,
XYZService,
XYZServiceClient,
XYZServiceServiceException,
} from "../dist-cjs/index.js";
import assert from "node:assert";
// clients
assert(typeof XYZServiceClient === "function");
assert(typeof XYZService === "function");
// commands
assert(typeof GetNumbersCommand === "function");
assert(typeof TradeEventStreamCommand === "function");
// errors
assert(XYZServiceServiceException.prototype instanceof Error);
console.log(`XYZService index test passed.`);
15 changes: 15 additions & 0 deletions private/my-local-model-schema/test/index-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// smithy-typescript generated code
export type {
XYZServiceClient,
XYZService,
GetNumbersCommand,
TradeEventStreamCommand,
Alpha,
GetNumbersRequest,
GetNumbersResponse,
TradeEvents,
TradeEventStreamRequest,
TradeEventStreamResponse,
Unit,
XYZServiceServiceException,
} from "../dist-types/index.d";
1 change: 1 addition & 0 deletions private/smithy-rpcv2-cbor-schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build:es": "tsc -p tsconfig.es.json",
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"test:index": "tsc --noEmit ./test/index-types.ts && node ./test/index-objects.spec.mjs",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"prepack": "yarn run clean && yarn run build",
"test": "yarn g:vitest run --passWithNoTests"
Expand Down
48 changes: 48 additions & 0 deletions private/smithy-rpcv2-cbor-schema/test/index-objects.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
EmptyInputOutputCommand,
Float16Command,
FooEnum,
FractionalSecondsCommand,
GreetingWithErrorsCommand,
IntegerEnum,
NoInputOutputCommand,
OperationWithDefaultsCommand,
OptionalInputOutputCommand,
RecursiveShapesCommand,
RpcV2CborDenseMapsCommand,
RpcV2CborListsCommand,
RpcV2CborSparseMapsCommand,
RpcV2Protocol,
RpcV2ProtocolClient,
RpcV2ProtocolServiceException,
SimpleScalarPropertiesCommand,
SparseNullsOperationCommand,
TestEnum,
TestIntEnum,
} from "../dist-cjs/index.js";
import assert from "node:assert";
// clients
assert(typeof RpcV2ProtocolClient === "function");
assert(typeof RpcV2Protocol === "function");
// commands
assert(typeof EmptyInputOutputCommand === "function");
assert(typeof Float16Command === "function");
assert(typeof FractionalSecondsCommand === "function");
assert(typeof GreetingWithErrorsCommand === "function");
assert(typeof NoInputOutputCommand === "function");
assert(typeof OperationWithDefaultsCommand === "function");
assert(typeof OptionalInputOutputCommand === "function");
assert(typeof RecursiveShapesCommand === "function");
assert(typeof RpcV2CborDenseMapsCommand === "function");
assert(typeof RpcV2CborListsCommand === "function");
assert(typeof RpcV2CborSparseMapsCommand === "function");
assert(typeof SimpleScalarPropertiesCommand === "function");
assert(typeof SparseNullsOperationCommand === "function");
// enums
assert(typeof TestEnum === "object");
assert(typeof TestIntEnum === "object");
assert(typeof FooEnum === "object");
assert(typeof IntegerEnum === "object");
// errors
assert(RpcV2ProtocolServiceException.prototype instanceof Error);
console.log(`RpcV2Protocol index test passed.`);
42 changes: 42 additions & 0 deletions private/smithy-rpcv2-cbor-schema/test/index-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// smithy-typescript generated code
export type {
RpcV2ProtocolClient,
RpcV2Protocol,
EmptyInputOutputCommand,
Float16Command,
FractionalSecondsCommand,
GreetingWithErrorsCommand,
NoInputOutputCommand,
OperationWithDefaultsCommand,
OptionalInputOutputCommand,
RecursiveShapesCommand,
RpcV2CborDenseMapsCommand,
RpcV2CborListsCommand,
RpcV2CborSparseMapsCommand,
SimpleScalarPropertiesCommand,
SparseNullsOperationCommand,
TestEnum,
TestIntEnum,
FooEnum,
IntegerEnum,
ClientOptionalDefaults,
Defaults,
EmptyStructure,
Float16Output,
FractionalSecondsOutput,
GreetingWithErrorsOutput,
OperationWithDefaultsInput,
OperationWithDefaultsOutput,
RecursiveShapesInputOutput,
RecursiveShapesInputOutputNested1,
RecursiveShapesInputOutputNested2,
RpcV2CborDenseMapsInputOutput,
RpcV2CborListInputOutput,
RpcV2CborSparseMapsInputOutput,
SimpleScalarStructure,
SimpleStructure,
SparseNullsOperationInputOutput,
StructureListMember,
GreetingStruct,
RpcV2ProtocolServiceException,
} from "../dist-types/index.d";
1 change: 1 addition & 0 deletions private/smithy-rpcv2-cbor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build:es": "tsc -p tsconfig.es.json",
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"test:index": "tsc --noEmit ./test/index-types.ts && node ./test/index-objects.spec.mjs",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
"prepack": "yarn run clean && yarn run build",
"merged": "echo \"this is merged from user configuration.\"",
Expand Down
48 changes: 48 additions & 0 deletions private/smithy-rpcv2-cbor/test/index-objects.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import {
EmptyInputOutputCommand,
Float16Command,
FooEnum,
FractionalSecondsCommand,
GreetingWithErrorsCommand,
IntegerEnum,
NoInputOutputCommand,
OperationWithDefaultsCommand,
OptionalInputOutputCommand,
RecursiveShapesCommand,
RpcV2CborDenseMapsCommand,
RpcV2CborListsCommand,
RpcV2CborSparseMapsCommand,
RpcV2Protocol,
RpcV2ProtocolClient,
RpcV2ProtocolServiceException,
SimpleScalarPropertiesCommand,
SparseNullsOperationCommand,
TestEnum,
TestIntEnum,
} from "../dist-cjs/index.js";
import assert from "node:assert";
// clients
assert(typeof RpcV2ProtocolClient === "function");
assert(typeof RpcV2Protocol === "function");
// commands
assert(typeof EmptyInputOutputCommand === "function");
assert(typeof Float16Command === "function");
assert(typeof FractionalSecondsCommand === "function");
assert(typeof GreetingWithErrorsCommand === "function");
assert(typeof NoInputOutputCommand === "function");
assert(typeof OperationWithDefaultsCommand === "function");
assert(typeof OptionalInputOutputCommand === "function");
assert(typeof RecursiveShapesCommand === "function");
assert(typeof RpcV2CborDenseMapsCommand === "function");
assert(typeof RpcV2CborListsCommand === "function");
assert(typeof RpcV2CborSparseMapsCommand === "function");
assert(typeof SimpleScalarPropertiesCommand === "function");
assert(typeof SparseNullsOperationCommand === "function");
// enums
assert(typeof TestEnum === "object");
assert(typeof TestIntEnum === "object");
assert(typeof FooEnum === "object");
assert(typeof IntegerEnum === "object");
// errors
assert(RpcV2ProtocolServiceException.prototype instanceof Error);
console.log(`RpcV2Protocol index test passed.`);
42 changes: 42 additions & 0 deletions private/smithy-rpcv2-cbor/test/index-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// smithy-typescript generated code
export type {
RpcV2ProtocolClient,
RpcV2Protocol,
EmptyInputOutputCommand,
Float16Command,
FractionalSecondsCommand,
GreetingWithErrorsCommand,
NoInputOutputCommand,
OperationWithDefaultsCommand,
OptionalInputOutputCommand,
RecursiveShapesCommand,
RpcV2CborDenseMapsCommand,
RpcV2CborListsCommand,
RpcV2CborSparseMapsCommand,
SimpleScalarPropertiesCommand,
SparseNullsOperationCommand,
TestEnum,
TestIntEnum,
FooEnum,
IntegerEnum,
ClientOptionalDefaults,
Defaults,
EmptyStructure,
Float16Output,
FractionalSecondsOutput,
GreetingWithErrorsOutput,
OperationWithDefaultsInput,
OperationWithDefaultsOutput,
RecursiveShapesInputOutput,
RecursiveShapesInputOutputNested1,
RecursiveShapesInputOutputNested2,
RpcV2CborDenseMapsInputOutput,
RpcV2CborListInputOutput,
RpcV2CborSparseMapsInputOutput,
SimpleScalarStructure,
SimpleStructure,
SparseNullsOperationInputOutput,
StructureListMember,
GreetingStruct,
RpcV2ProtocolServiceException,
} from "../dist-types/index.d";
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
public final class CodegenUtils {

public static final String SOURCE_FOLDER = "src";
public static final String TEST_FOLDER = "test";

private CodegenUtils() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,25 @@ public void customizeBeforeIntegrations(
);
});

if (directive.settings().generateClient() && directive.settings().generateIndexTests()) {
writerFactory.accept(Paths.get(CodegenUtils.TEST_FOLDER, "index-types.ts").toString(), writer -> {
new PackageApiValidationGenerator(
writer,
directive.settings(),
directive.model(),
directive.symbolProvider()
).writeTypeIndexTest();
});
writerFactory.accept(Paths.get(CodegenUtils.TEST_FOLDER, "index-objects.spec.mjs").toString(), writer -> {
new PackageApiValidationGenerator(
writer,
directive.settings(),
directive.model(),
directive.symbolProvider()
).writeRuntimeIndexTest();
});
}

if (directive.settings().generateServerSdk()) {
// Generate index for server
IndexGenerator.writeServerIndex(
Expand Down
Loading