smithy-lang / smithy-typescript

Smithy code generators for TypeScript. (in development)
Apache License 2.0
220 stars 80 forks source link

@aws-sdk/core is missing when using typescript-codegen #1229

Closed Zouarfi closed 5 months ago

Zouarfi commented 5 months ago

Hello,

It appears that when we use typescript-codegen with 0.20.0 the package @aws-sdk/core is missing in the generated package.json.

This lead to unusable package when it is used with the trait @restJson1.

Here's the diff between the package.json from 0.19.0 to 0.20.0:

--- a/packages/models/build/smithy/api/typescript-codegen/package.json
+++ b/packages/models/build/smithy/api/typescript-codegen/package.json
@@ -5,11 +5,10 @@
     "scripts": {
         "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
         "build:cjs": "tsc -p tsconfig.cjs.json",
-        "build:docs": "typedoc",
         "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",
-        "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
+        "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
         "prepack": "yarn run clean && yarn run build"
     },
     "main": "./dist-cjs/index.js",
@@ -19,47 +18,45 @@
     "dependencies": {
         "@aws-crypto/sha256-browser": "3.0.0",
         "@aws-crypto/sha256-js": "3.0.0",
-        "@aws-sdk/core": "3.441.0",
-        "@aws-sdk/middleware-host-header": "3.433.0",
-        "@aws-sdk/middleware-logger": "3.433.0",
-        "@aws-sdk/middleware-recursion-detection": "3.433.0",
-        "@aws-sdk/middleware-user-agent": "3.438.0",
-        "@aws-sdk/region-config-resolver": "3.433.0",
-        "@aws-sdk/types": "3.433.0",
-        "@aws-sdk/util-user-agent-browser": "3.433.0",
-        "@aws-sdk/util-user-agent-node": "3.437.0",
-        "@smithy/config-resolver": "^2.0.16",
-        "@smithy/fetch-http-handler": "^2.2.4",
-        "@smithy/hash-node": "^2.0.12",
-        "@smithy/invalid-dependency": "^2.0.12",
-        "@smithy/middleware-content-length": "^2.0.14",
-        "@smithy/middleware-retry": "^2.0.18",
-        "@smithy/middleware-serde": "^2.0.12",
-        "@smithy/middleware-stack": "^2.0.6",
-        "@smithy/node-config-provider": "^2.1.3",
-        "@smithy/node-http-handler": "^2.1.8",
-        "@smithy/protocol-http": "^3.0.8",
-        "@smithy/smithy-client": "^2.1.12",
-        "@smithy/types": "^2.4.0",
-        "@smithy/url-parser": "^2.0.12",
-        "@smithy/util-base64": "^2.0.0",
-        "@smithy/util-body-length-browser": "^2.0.0",
-        "@smithy/util-body-length-node": "^2.1.0",
-        "@smithy/util-defaults-mode-browser": "^2.0.16",
-        "@smithy/util-defaults-mode-node": "^2.0.21",
-        "@smithy/util-middleware": "^2.0.5",
-        "@smithy/util-retry": "^2.0.5",
-        "@smithy/util-utf8": "^2.0.0",
-        "tslib": "^2.5.0"
+        "@aws-sdk/middleware-host-header": "3.535.0",
+        "@aws-sdk/middleware-logger": "3.535.0",
+        "@aws-sdk/middleware-recursion-detection": "3.535.0",
+        "@aws-sdk/middleware-user-agent": "3.540.0",
+        "@aws-sdk/types": "3.535.0",
+        "@aws-sdk/util-user-agent-browser": "3.535.0",
+        "@aws-sdk/util-user-agent-node": "3.535.0",
+        "@smithy/config-resolver": "^2.2.0",
+        "@smithy/core": "^1.4.0",
+        "@smithy/fetch-http-handler": "^2.5.0",
+        "@smithy/hash-node": "^2.2.0",
+        "@smithy/invalid-dependency": "^2.2.0",
+        "@smithy/middleware-content-length": "^2.2.0",
+        "@smithy/middleware-retry": "^2.2.0",
+        "@smithy/middleware-serde": "^2.3.0",
+        "@smithy/middleware-stack": "^2.2.0",
+        "@smithy/node-config-provider": "^2.3.0",
+        "@smithy/node-http-handler": "^2.5.0",
+        "@smithy/protocol-http": "^3.3.0",
+        "@smithy/smithy-client": "^2.5.0",
+        "@smithy/types": "^2.12.0",
+        "@smithy/url-parser": "^2.2.0",
+        "@smithy/util-base64": "^2.3.0",
+        "@smithy/util-body-length-browser": "^2.2.0",
+        "@smithy/util-body-length-node": "^2.3.0",
+        "@smithy/util-defaults-mode-browser": "^2.2.0",
+        "@smithy/util-defaults-mode-node": "^2.3.0",
+        "@smithy/util-middleware": "^2.2.0",
+        "@smithy/util-retry": "^2.2.0",
+        "@smithy/util-utf8": "^2.3.0",
+        "tslib": "^2.6.2"
     },
     "devDependencies": {
-        "@smithy/service-client-documentation-generator": "^2.0.0",
+        "@smithy/service-client-documentation-generator": "^2.2.0",
         "@tsconfig/node14": "1.0.3",
         "@types/node": "^14.14.31",
         "concurrently": "7.0.0",
         "downlevel-dts": "0.10.1",
         "rimraf": "^3.0.0",
-        "typedoc": "0.23.23",
         "typescript": "~4.9.5"
     },
kuhe commented 5 months ago

aws.protocols#restJson1 is an AWS protocol, I think you'd have to include smithy-aws-typescript-codegen in addition to this do handle that.

Zouarfi commented 5 months ago

Hello,

Thanks for the reply!

By mentioning AWS Protocol, I have double checked our definition and it appears that in fact, it is required to provide the trait @service when generating TypeScript SDK on version 0.20.0. I have updated our Smithy definition and now it works like a charm!

Thank you very much!

Petroniuss commented 4 months ago

Hi,

I want to ask for clarification whether providing aws.api#service trait is required alongside aws.protocol#restJson1. The official example for generating typescript clients mentions only @restJson1 trait. https://smithy.io/2.0/guides/using-code-generation/update-model.html#id4.

Including @service annotation triggers aws-sdk specific codegen to be triggered (including code regarding regions etc), which isn't desireable in case of generating plain http clients (not part of aws sdk).

syall commented 4 months ago

It appears that when we use typescript-codegen with 0.20.0 the package @aws-sdk/core is missing in the generated package.json.

The overarching issue has been fixed in these PRs, and will go out in the next release: #1239, aws/aws-sdk-js-v3#6000

Hello,

Thanks for the reply!

By mentioning AWS Protocol, I have double checked our definition and it appears that in fact, it is required to provide the trait @service when generating TypeScript SDK on version 0.20.0. I have updated our Smithy definition and now it works like a charm!

Thank you very much!

The aws.api#service trait should not be strictly required when using any of the AWS protocol traits (e.g. aws.protocol#restJson1.

Further investigation will be done in https://github.com/smithy-lang/smithy-typescript/issues/1242#issuecomment-2057727525

Zouarfi commented 4 months ago

Wow thanks for catching up! Good news then