diff --git a/Makefile b/Makefile index e33741ef220..44669fa1bfe 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ sync: git fetch --all generate-protocol-tests: + rm -rf ./smithy-typescript-protocol-test-codegen/build/smithyprojections/smithy-typescript-protocol-test-codegen ./gradlew :smithy-typescript-protocol-test-codegen:build rm -rf ./private/smithy-rpcv2-cbor rm -rf ./private/smithy-rpcv2-cbor-schema diff --git a/private/my-local-model-schema/src/commands/GetNumbersCommand.ts b/private/my-local-model-schema/src/commands/GetNumbersCommand.ts index ea46d633848..664828875cd 100644 --- a/private/my-local-model-schema/src/commands/GetNumbersCommand.ts +++ b/private/my-local-model-schema/src/commands/GetNumbersCommand.ts @@ -68,6 +68,8 @@ export interface GetNumbersCommandOutput extends GetNumbersResponse, __MetadataB * * @throws {@link XYZServiceServiceException} (client fault) * + * @throws {@link MainServiceLinkedError} (client fault) + * * @throws {@link XYZServiceSyntheticServiceException} *

Base exception class for all service exceptions from XYZService service.

* diff --git a/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts b/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts index a86781205af..7fd413320cb 100644 --- a/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts +++ b/private/my-local-model-schema/src/commands/TradeEventStreamCommand.ts @@ -68,6 +68,8 @@ export interface TradeEventStreamCommandOutput extends TradeEventStreamResponse, * @see {@link TradeEventStreamCommandOutput} for command's `response` shape. * @see {@link XYZServiceClientResolvedConfig | config} for XYZServiceClient's `config` shape. * + * @throws {@link MainServiceLinkedError} (client fault) + * * @throws {@link XYZServiceSyntheticServiceException} *

Base exception class for all service exceptions from XYZService service.

* diff --git a/private/my-local-model-schema/src/models/errors.ts b/private/my-local-model-schema/src/models/errors.ts index 6ae3754be39..146c7f7243d 100644 --- a/private/my-local-model-schema/src/models/errors.ts +++ b/private/my-local-model-schema/src/models/errors.ts @@ -44,6 +44,25 @@ export class HaltError extends __BaseException { } } +/** + * @public + */ +export class MainServiceLinkedError extends __BaseException { + readonly name = "MainServiceLinkedError" as const; + readonly $fault = "client" as const; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "MainServiceLinkedError", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, MainServiceLinkedError.prototype); + } +} + /** * @public */ diff --git a/private/my-local-model-schema/src/schemas/schemas_0.ts b/private/my-local-model-schema/src/schemas/schemas_0.ts index dd693af8d15..8991f413638 100644 --- a/private/my-local-model-schema/src/schemas/schemas_0.ts +++ b/private/my-local-model-schema/src/schemas/schemas_0.ts @@ -4,6 +4,7 @@ const _GN = "GetNumbers"; const _GNR = "GetNumbersRequest"; const _GNRe = "GetNumbersResponse"; const _HE = "HaltError"; +const _MSLE = "MainServiceLinkedError"; const _MTE = "MysteryThrottlingError"; const _RE = "RetryableError"; const _TE = "TradeEvents"; @@ -35,6 +36,7 @@ import type { StaticErrorSchema, StaticOperationSchema, StaticStructureSchema } import { CodedThrottlingError as __CodedThrottlingError, HaltError as __HaltError, + MainServiceLinkedError as __MainServiceLinkedError, MysteryThrottlingError as __MysteryThrottlingError, RetryableError as __RetryableError, XYZServiceServiceException as __XYZServiceServiceException, @@ -71,6 +73,12 @@ export var HaltError: StaticErrorSchema = [-3, n0, _HE, [] ]; TypeRegistry.for(n0).registerError(HaltError, __HaltError); +export var MainServiceLinkedError: StaticErrorSchema = [-3, n0, _MSLE, + { [_e]: _c, [_hE]: 400 }, + [], + [] +]; +TypeRegistry.for(n0).registerError(MainServiceLinkedError, __MainServiceLinkedError); export var MysteryThrottlingError: StaticErrorSchema = [-3, n0, _MTE, { [_e]: _c }, [], diff --git a/private/my-local-model-schema/test/index-objects.spec.mjs b/private/my-local-model-schema/test/index-objects.spec.mjs index e0dc28e52e4..07ab38eb471 100644 --- a/private/my-local-model-schema/test/index-objects.spec.mjs +++ b/private/my-local-model-schema/test/index-objects.spec.mjs @@ -2,6 +2,7 @@ import { CodedThrottlingError, GetNumbersCommand, HaltError, + MainServiceLinkedError, MysteryThrottlingError, RetryableError, TradeEventStreamCommand, @@ -20,6 +21,7 @@ assert(typeof TradeEventStreamCommand === "function"); // errors assert(CodedThrottlingError.prototype instanceof XYZServiceSyntheticServiceException); assert(HaltError.prototype instanceof XYZServiceSyntheticServiceException); +assert(MainServiceLinkedError.prototype instanceof XYZServiceSyntheticServiceException); assert(MysteryThrottlingError.prototype instanceof XYZServiceSyntheticServiceException); assert(RetryableError.prototype instanceof XYZServiceSyntheticServiceException); assert(XYZServiceServiceException.prototype instanceof XYZServiceSyntheticServiceException); diff --git a/private/my-local-model-schema/test/index-types.ts b/private/my-local-model-schema/test/index-types.ts index 1c4ee56ab81..fb0196a7dcd 100644 --- a/private/my-local-model-schema/test/index-types.ts +++ b/private/my-local-model-schema/test/index-types.ts @@ -16,6 +16,7 @@ export type { TradeEventStreamResponse, CodedThrottlingError, HaltError, + MainServiceLinkedError, MysteryThrottlingError, RetryableError, XYZServiceServiceException, diff --git a/private/my-local-model/src/commands/GetNumbersCommand.ts b/private/my-local-model/src/commands/GetNumbersCommand.ts index 7a71ff923ee..890256a61f2 100644 --- a/private/my-local-model/src/commands/GetNumbersCommand.ts +++ b/private/my-local-model/src/commands/GetNumbersCommand.ts @@ -69,6 +69,8 @@ export interface GetNumbersCommandOutput extends GetNumbersResponse, __MetadataB * * @throws {@link XYZServiceServiceException} (client fault) * + * @throws {@link MainServiceLinkedError} (client fault) + * * @throws {@link XYZServiceSyntheticServiceException} *

Base exception class for all service exceptions from XYZService service.

* diff --git a/private/my-local-model/src/commands/TradeEventStreamCommand.ts b/private/my-local-model/src/commands/TradeEventStreamCommand.ts index 7604b4959ae..c1d258edc37 100644 --- a/private/my-local-model/src/commands/TradeEventStreamCommand.ts +++ b/private/my-local-model/src/commands/TradeEventStreamCommand.ts @@ -74,6 +74,8 @@ export interface TradeEventStreamCommandOutput extends TradeEventStreamResponse, * @see {@link TradeEventStreamCommandOutput} for command's `response` shape. * @see {@link XYZServiceClientResolvedConfig | config} for XYZServiceClient's `config` shape. * + * @throws {@link MainServiceLinkedError} (client fault) + * * @throws {@link XYZServiceSyntheticServiceException} *

Base exception class for all service exceptions from XYZService service.

* diff --git a/private/my-local-model/src/models/errors.ts b/private/my-local-model/src/models/errors.ts index 6ae3754be39..146c7f7243d 100644 --- a/private/my-local-model/src/models/errors.ts +++ b/private/my-local-model/src/models/errors.ts @@ -44,6 +44,25 @@ export class HaltError extends __BaseException { } } +/** + * @public + */ +export class MainServiceLinkedError extends __BaseException { + readonly name = "MainServiceLinkedError" as const; + readonly $fault = "client" as const; + /** + * @internal + */ + constructor(opts: __ExceptionOptionType) { + super({ + name: "MainServiceLinkedError", + $fault: "client", + ...opts, + }); + Object.setPrototypeOf(this, MainServiceLinkedError.prototype); + } +} + /** * @public */ diff --git a/private/my-local-model/src/protocols/Rpcv2cbor.ts b/private/my-local-model/src/protocols/Rpcv2cbor.ts index d053e51c15e..7d04ffe29a6 100644 --- a/private/my-local-model/src/protocols/Rpcv2cbor.ts +++ b/private/my-local-model/src/protocols/Rpcv2cbor.ts @@ -35,6 +35,7 @@ import { TradeEventStreamCommandInput, TradeEventStreamCommandOutput } from "../ import { CodedThrottlingError, HaltError, + MainServiceLinkedError, MysteryThrottlingError, RetryableError, XYZServiceServiceException, @@ -133,6 +134,9 @@ const de_CommandError = async ( case "HaltError": case "org.xyz.v1#HaltError": throw await de_HaltErrorRes(parsedOutput, context); + case "MainServiceLinkedError": + case "org.xyz.v1#MainServiceLinkedError": + throw await de_MainServiceLinkedErrorRes(parsedOutput, context); case "MysteryThrottlingError": case "org.xyz.v1#MysteryThrottlingError": throw await de_MysteryThrottlingErrorRes(parsedOutput, context); @@ -184,6 +188,22 @@ const de_HaltErrorRes = async ( return __decorateServiceException(exception, body); }; +/** + * deserializeRpcv2cborMainServiceLinkedErrorRes + */ +const de_MainServiceLinkedErrorRes = async ( + parsedOutput: any, + context: __SerdeContext +): Promise => { + const body = parsedOutput.body + const deserialized: any = _json(body); + const exception = new MainServiceLinkedError({ + $metadata: deserializeMetadata(parsedOutput), + ...deserialized + }); + return __decorateServiceException(exception, body); +}; + /** * deserializeRpcv2cborMysteryThrottlingErrorRes */ @@ -382,6 +402,8 @@ const se_Alpha_event = ( // de_HaltError omitted. + // de_MainServiceLinkedError omitted. + // de_MysteryThrottlingError omitted. // de_RetryableError omitted. diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/knowledge/ServiceClosure.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/knowledge/ServiceClosure.java index 26339de4fa8..9e0017cc0de 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/knowledge/ServiceClosure.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/knowledge/ServiceClosure.java @@ -106,6 +106,7 @@ private ServiceClosure( Set containedOperations = topDown.getContainedOperations(service); operations.addAll(containedOperations); scan(containedOperations); + scan(service); scanned.clear(); deconflictSchemaVarNames(); } @@ -271,6 +272,13 @@ private void scan(Collection shapes) { operations.add(operation); existsAsSchema.add(operation); } + case SERVICE -> { + ServiceShape serviceShape = (ServiceShape) shape; + serviceShape.getErrorsSet().forEach(errorShapeId -> { + Shape errorShape = model.expectShape(errorShapeId); + scan(errorShape); + }); + } case BYTE, INT_ENUM, SHORT, INTEGER, LONG, FLOAT, DOUBLE, BIG_INTEGER, BIG_DECIMAL, BOOLEAN, STRING, TIMESTAMP, DOCUMENT, ENUM, BLOB -> { if (shape.isEnumShape() || shape.isIntEnumShape() || shape.hasTrait(EnumTrait.class)) { diff --git a/smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy b/smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy index c03a53a517e..9eb591a0f1c 100644 --- a/smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy +++ b/smithy-typescript-protocol-test-codegen/model/my-local-model/main.smithy @@ -12,8 +12,15 @@ service XYZService { GetNumbers TradeEventStream ] + errors: [ + MainServiceLinkedError + ] } +@error("client") +@httpError(400) +structure MainServiceLinkedError {} + @readonly operation GetNumbers { input: GetNumbersRequest @@ -91,3 +98,35 @@ structure Alpha { id: String timestamp: Timestamp } + +@rpcv2Cbor +@documentation("a second service in the same model, unused.") +service UnusedService { + version: "1.0" + operations: [ + UnusedOperation + ] + errors: [ + UnusedServiceLinkedError + ] +} + +operation UnusedOperation { + input: Unit + output: Unit + errors: [ + UnusedServiceOperationLinkedError + ] +} + +@error("client") +@httpError(400) +structure UnusedServiceOperationLinkedError {} + +@error("client") +@httpError(400) +structure UnusedServiceLinkedError {} + +@error("client") +@httpError(400) +structure CompletelyUnlinkedError {} diff --git a/smithy-typescript-protocol-test-codegen/model/my-local-model/secondary.smithy b/smithy-typescript-protocol-test-codegen/model/my-local-model/secondary.smithy new file mode 100644 index 00000000000..a57446a8e3f --- /dev/null +++ b/smithy-typescript-protocol-test-codegen/model/my-local-model/secondary.smithy @@ -0,0 +1,37 @@ +$version: "2.0" + +namespace org.xyz.secondary + +use smithy.protocols#rpcv2Cbor + +@rpcv2Cbor +@documentation("a second service in the same model, unused.") +service TertiaryService { + version: "1.0" + operations: [ + TertiaryUnusedOperation + ] + errors: [ + TertiaryUnusedServiceLinkedError + ] +} + +operation TertiaryUnusedOperation { + input: Unit + output: Unit + errors: [ + TertiaryUnusedServiceOperationLinkedError + ] +} + +@error("client") +@httpError(400) +structure TertiaryUnusedServiceOperationLinkedError {} + +@error("client") +@httpError(400) +structure TertiaryUnusedServiceLinkedError {} + +@error("client") +@httpError(400) +structure TertiaryCompletelyUnlinkedError {} diff --git a/smithy-typescript-protocol-test-codegen/smithy-build.json b/smithy-typescript-protocol-test-codegen/smithy-build.json index 7d93617be71..629f69f5ff0 100644 --- a/smithy-typescript-protocol-test-codegen/smithy-build.json +++ b/smithy-typescript-protocol-test-codegen/smithy-build.json @@ -62,7 +62,7 @@ { "name": "includeServices", "args": { - "services": ["org.xyz.v1#XYZService"] + "services": ["org.xyz.v1#XYZService", "org.xyz.v1#UnusedService", "org.xyz.secondary#TertiaryService"] } } ], @@ -83,7 +83,7 @@ { "name": "includeServices", "args": { - "services": ["org.xyz.v1#XYZService"] + "services": ["org.xyz.v1#XYZService", "org.xyz.v1#UnusedService", "org.xyz.secondary#TertiaryService"] } } ],