Skip to content

Commit 696d2e1

Browse files
authored
fix(type-safe-api): fix websocket api issues (#738)
* fix(type-safe-api): use service namespace in prelude and fix docs * fix(type-safe-api): ensure smithy async transformer jar is included in cache Addresses a bug where the smithy async transformer was not published as part of the release build, since build artifacts were loaded from the cache which didn't include the jar
1 parent 8662693 commit 696d2e1

File tree

7 files changed

+84
-69
lines changed

7 files changed

+84
-69
lines changed

packages/type-safe-api/docs/developer_guides/type-safe-api/getting_started.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The `TypeSafeApiProject` projen project sets up the project structure for you. C
2626
1.) To start an empty `monorepo` project, use this command:
2727

2828
```bash
29-
pdk new monorepo-ts
29+
pdk new monorepo-ts --package-manager=pnpm
3030
```
3131

3232
2.) Edit your `.projenrc` and configure `TypeSafeApiProject`.
@@ -47,13 +47,15 @@ pdk new monorepo-ts
4747
TypeSafeApiProject,
4848
} from "@aws/pdk/type-safe-api";
4949
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";
50+
import { NodePackageManager } from "projen/lib/javascript";
5051

5152
// Create the monorepo
5253
const monorepo = new MonorepoTsProject({
5354
name: "my-project",
5455
devDeps: [
5556
"@aws/pdk",
5657
],
58+
packageManager: NodePackageManager.PNPM,
5759
});
5860

5961
// Create the API project

packages/type-safe-api/docs/developer_guides/type-safe-api/websocket_getting_started.md

+11-7
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ The `TypeSafeWebSocketApiProject` projen project sets up the project structure f
2525
1.) To start an empty `monorepo` project, use this command:
2626

2727
```bash
28-
pdk new monorepo-ts
28+
pdk new monorepo-ts --package-manager=pnpm
2929
```
3030

3131
2.) Edit your `.projenrc` and configure `TypeSafeWebSocketApiProject`.
@@ -35,13 +35,13 @@ pdk new monorepo-ts
3535
```ts
3636
import { MonorepoTsProject } from "@aws/pdk/monorepo";
3737
import {
38-
DocumentationFormat,
3938
Language,
40-
Library,
4139
ModelLanguage,
4240
TypeSafeWebSocketApiProject,
41+
WebSocketLibrary,
4342
} from "@aws/pdk/type-safe-api";
4443
import { InfrastructureTsProject } from "@aws/pdk/infrastructure";
44+
import { CloudscapeReactTsWebsiteProject } from "@aws/pdk/cloudscape-react-ts-website";
4545

4646
// Create the monorepo
4747
const monorepo = new MonorepoTsProject({
@@ -75,10 +75,10 @@ pdk new monorepo-ts
7575
// Lambda handlers in TypeScript
7676
handlers: {
7777
languages: [Language.TYPESCRIPT],
78-
}
78+
},
7979
// Generate react hooks to interact with the API from a React website
8080
library: {
81-
libraries: [Library.TYPESCRIPT_WEBSOCKET_HOOKS],
81+
libraries: [WebSocketLibrary.TYPESCRIPT_WEBSOCKET_HOOKS],
8282
},
8383
});
8484

@@ -124,9 +124,11 @@ The generated runtime projects include lambda handler wrappers which provide typ
124124

125125
=== "SMITHY"
126126

127+
Use the `@async` trait to select the operation direction. Choose between `client_to_server`, `server_to_client` or `bidirectional`
128+
127129
Use the `@handler` trait, and specify the language you wish to implement this operation in.
128130

129-
```smithy hl_lines="2"
131+
```smithy hl_lines="1-2"
130132
@async(direction: "client_to_server")
131133
@handler(language: "typescript")
132134
operation SubscribeToNotifications {
@@ -143,9 +145,11 @@ The generated runtime projects include lambda handler wrappers which provide typ
143145

144146
=== "OPENAPI"
145147

148+
Use the `x-async` vendor extension to select the operation direction. Choose between `client_to_server`, `server_to_client` or `bidirectional`
149+
146150
Use the `x-handler` vendor extension, specifying the language you wish to implement this operation in.
147151

148-
```yaml hl_lines="4-5"
152+
```yaml hl_lines="4-7"
149153
/SubscribeToNotifications:
150154
post:
151155
operationId: SubscribeToNotifications

packages/type-safe-api/project.json

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/type-safe-api/src/project/model/smithy/components/smithy-aws-pdk-async-prelude.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ metadata validators = [
5454
message: "Operation is missing @async trait"
5555
configuration: {
5656
selector: """
57-
operation :not([trait|com.aws#async])
57+
operation :not([trait|${this.options.serviceNamespace}#async])
5858
"""
5959
}
6060
}
@@ -65,7 +65,9 @@ metadata validators = [
6565
message: "Service is missing @websocketJson trait"
6666
configuration: {
6767
selector: """
68-
service :not([trait|com.aws#websocketJson])
68+
service :not([trait|${
69+
this.options.serviceNamespace
70+
}#websocketJson])
6971
"""
7072
}
7173
}
@@ -99,8 +101,10 @@ metadata validators = [
99101
configuration: {
100102
selector: """
101103
operation
102-
[@trait|com.aws#async: @{direction} = server_to_client]
103-
[trait|com.aws#handler]
104+
[@trait|${
105+
this.options.serviceNamespace
106+
}#async: @{direction} = server_to_client]
107+
[trait|${this.options.serviceNamespace}#handler]
104108
"""
105109
}
106110
}

0 commit comments

Comments
 (0)