@aws/nx-plugin-mcp 1.0.0-rc.52 → 1.0.0-rc.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/aws-nx-mcp.js +2 -2
- package/docs/guides/smithy-project.mdx +175 -0
- package/docs/guides/ts-smithy-api.mdx +25 -0
- package/docs/snippets/pdk-migration/faq/type-safe-api.mdx +3 -109
- package/docs/snippets/prerequisites.mdx +1 -1
- package/generators.json +2 -2
- package/package.json +1 -1
- package/src/smithy/project/schema.json +23 -1
package/bin/aws-nx-mcp.js
CHANGED
|
@@ -54200,9 +54200,9 @@ var generators$1 = {
|
|
|
54200
54200
|
"smithy#project": {
|
|
54201
54201
|
"factory": "./src/smithy/project/generator",
|
|
54202
54202
|
"schema": "./src/smithy/project/schema.json",
|
|
54203
|
-
"description": "Generate a Smithy model project",
|
|
54203
|
+
"description": "Generate a Smithy model project, either defining a service or a library of reusable shapes",
|
|
54204
54204
|
"metric": "g27",
|
|
54205
|
-
"
|
|
54205
|
+
"guidePages": ["smithy-project"]
|
|
54206
54206
|
},
|
|
54207
54207
|
"smithy#react-connection": {
|
|
54208
54208
|
"factory": "./src/smithy/react-connection/generator",
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Smithy Projects
|
|
3
|
+
description: Reference documentation for the Smithy project generator
|
|
4
|
+
generator: smithy#project
|
|
5
|
+
---
|
|
6
|
+
import { FileTree, Steps } from '@astrojs/starlight/components';
|
|
7
|
+
import RunGenerator from '@components/run-generator.astro';
|
|
8
|
+
import Link from '@components/link.astro';
|
|
9
|
+
import GeneratorParameters from '@components/generator-parameters.astro';
|
|
10
|
+
import NxCommands from '@components/nx-commands.astro';
|
|
11
|
+
import OptionFilter from '@components/option-filter.astro';
|
|
12
|
+
|
|
13
|
+
[Smithy](https://smithy.io/) is an interface definition language for describing services and the data they exchange. The Smithy project generator creates a project containing a Smithy model.
|
|
14
|
+
|
|
15
|
+
There are two kinds of Smithy project:
|
|
16
|
+
|
|
17
|
+
- **Service** (`--type=service`) — a model which defines a service and its operations. This is what the <Link path="guides/ts-smithy-api">`ts#api --framework=smithy` generator</Link> creates for you alongside a TypeScript implementation.
|
|
18
|
+
- **Shape library** (`--type=shapes`) — a model which defines reusable shapes but no service. Connect a shape library to your Smithy projects to share shapes between them, rather than duplicating the definitions in each.
|
|
19
|
+
|
|
20
|
+
:::tip
|
|
21
|
+
If you want an API with an implementation, use the <Link path="guides/ts-smithy-api">`ts#api` generator</Link> instead. It creates a Smithy model project _and_ a TypeScript server which implements it.
|
|
22
|
+
:::
|
|
23
|
+
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
### Generate a Smithy Project
|
|
27
|
+
|
|
28
|
+
<RunGenerator generator="smithy#project" requiredParameters={{ name: 'my-shapes' }} />
|
|
29
|
+
|
|
30
|
+
### Options
|
|
31
|
+
|
|
32
|
+
<GeneratorParameters generator="smithy#project" />
|
|
33
|
+
|
|
34
|
+
## Generator Output
|
|
35
|
+
|
|
36
|
+
<OptionFilter when={{ type: 'shapes' }} description="Shape library: a model with no service">
|
|
37
|
+
|
|
38
|
+
### Shape Library
|
|
39
|
+
|
|
40
|
+
<FileTree>
|
|
41
|
+
|
|
42
|
+
- my-shapes
|
|
43
|
+
- src
|
|
44
|
+
- main.smithy Your shared shape definitions
|
|
45
|
+
- smithy-build.json Smithy build configuration
|
|
46
|
+
- build.Dockerfile Builds and validates the model
|
|
47
|
+
- project.json Project configuration and build targets
|
|
48
|
+
|
|
49
|
+
</FileTree>
|
|
50
|
+
|
|
51
|
+
A shape library defines shapes and nothing else:
|
|
52
|
+
|
|
53
|
+
```smithy
|
|
54
|
+
$version: "2.0"
|
|
55
|
+
|
|
56
|
+
namespace com.example
|
|
57
|
+
|
|
58
|
+
structure Customer {
|
|
59
|
+
@required
|
|
60
|
+
id: String
|
|
61
|
+
|
|
62
|
+
name: String
|
|
63
|
+
email: String
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Since a shape library has no service, its `smithy-build.json` configures no code generation — building it validates the model and assembles it into a single JSON model file at `dist/<my-shapes>/build/model/model.json`.
|
|
68
|
+
|
|
69
|
+
</OptionFilter>
|
|
70
|
+
|
|
71
|
+
<OptionFilter when={{ type: 'service' }} description="Service: a model which defines a service and its operations">
|
|
72
|
+
|
|
73
|
+
### Service
|
|
74
|
+
|
|
75
|
+
<FileTree>
|
|
76
|
+
|
|
77
|
+
- my-service
|
|
78
|
+
- src
|
|
79
|
+
- main.smithy Your service definition
|
|
80
|
+
- operations
|
|
81
|
+
- echo.smithy An example operation
|
|
82
|
+
- smithy-build.json Smithy build configuration, including code generation
|
|
83
|
+
- build.Dockerfile Builds the model, OpenAPI spec and TypeScript Server SDK
|
|
84
|
+
- project.json Project configuration and build targets
|
|
85
|
+
|
|
86
|
+
</FileTree>
|
|
87
|
+
|
|
88
|
+
A service model defines a service shape and the operations it exposes:
|
|
89
|
+
|
|
90
|
+
```smithy
|
|
91
|
+
$version: "2.0"
|
|
92
|
+
|
|
93
|
+
namespace com.example
|
|
94
|
+
|
|
95
|
+
use aws.protocols#restJson1
|
|
96
|
+
|
|
97
|
+
@title("MyService")
|
|
98
|
+
@restJson1
|
|
99
|
+
service MyService {
|
|
100
|
+
version: "1.0.0"
|
|
101
|
+
operations: [
|
|
102
|
+
Echo
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Building a service project generates an OpenAPI specification and a TypeScript Server SDK into `dist/<my-service>/build/`.
|
|
108
|
+
|
|
109
|
+
</OptionFilter>
|
|
110
|
+
|
|
111
|
+
## Building
|
|
112
|
+
|
|
113
|
+
Smithy projects build using [Docker](https://www.docker.com/), which runs the [Smithy CLI](https://smithy.io/2.0/guides/smithy-cli/index.html) to validate your model:
|
|
114
|
+
|
|
115
|
+
<NxCommands commands={['build my-shapes']} />
|
|
116
|
+
|
|
117
|
+
## Depending on a Shape Library
|
|
118
|
+
|
|
119
|
+
Building a shape library writes an assembled model to `dist/<my-shapes>/build/model/model.json`. This single file contains every shape the library defines, along with any it depends on, so a consumer only ever declares the libraries it references directly.
|
|
120
|
+
|
|
121
|
+
To depend on a shape library from another Smithy project, make three changes to the consuming project:
|
|
122
|
+
|
|
123
|
+
<Steps>
|
|
124
|
+
|
|
125
|
+
1. Smithy projects build inside a container, and the build is given the workspace root as a named build context. Add a `COPY` to the consuming project's `build.Dockerfile`, alongside where its own sources are copied in:
|
|
126
|
+
|
|
127
|
+
```dockerfile ins={4}
|
|
128
|
+
# Copy project files
|
|
129
|
+
COPY smithy-build.json .
|
|
130
|
+
COPY src src
|
|
131
|
+
COPY --from=workspace dist/packages/my-shapes/build/model/model.json deps/my-shapes.json
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
2. Add the copied file to `imports` in the consuming project's `smithy-build.json`:
|
|
135
|
+
|
|
136
|
+
```json ins={4}
|
|
137
|
+
{
|
|
138
|
+
"version": "1.0",
|
|
139
|
+
"sources": ["src/"],
|
|
140
|
+
"imports": ["deps/my-shapes.json"],
|
|
141
|
+
...
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
3. Add the library's `build` target as a dependency of the consuming project's `compile` target in its `project.json`, so the model exists before the consumer builds:
|
|
146
|
+
|
|
147
|
+
```json ins={4}
|
|
148
|
+
{
|
|
149
|
+
"targets": {
|
|
150
|
+
"compile": {
|
|
151
|
+
"dependsOn": ["@my-scope/my-shapes:build"],
|
|
152
|
+
...
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
</Steps>
|
|
159
|
+
|
|
160
|
+
Your model can now reference the library's shapes with `use`:
|
|
161
|
+
|
|
162
|
+
```smithy
|
|
163
|
+
$version: "2.0"
|
|
164
|
+
|
|
165
|
+
namespace com.example.api
|
|
166
|
+
|
|
167
|
+
use com.example.shared#Customer
|
|
168
|
+
|
|
169
|
+
structure GetCustomerOutput {
|
|
170
|
+
@required
|
|
171
|
+
customer: Customer
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Shape libraries can depend on other shape libraries the same way. Since each library's built model already contains its own dependencies, you only need to repeat these steps for the libraries you reference directly. A library reached by more than one path is resolved once — Smithy ignores duplicate but equivalent shape definitions.
|
|
@@ -224,6 +224,31 @@ You can change the folder structure however you like - all `.smithy` files in th
|
|
|
224
224
|
For more details on Smithy and its syntax, refer to the [Smithy specification](https://smithy.io/2.0/spec/index.html).
|
|
225
225
|
:::
|
|
226
226
|
|
|
227
|
+
### Adding a Shape Library
|
|
228
|
+
|
|
229
|
+
If you have several Smithy APIs which share the same data types, you can define those types once in a shape library rather than duplicating them in each model. A shape library is a Smithy project with no service — just reusable shapes — which any number of Smithy projects can depend on.
|
|
230
|
+
|
|
231
|
+
Generate one with the <Link path="guides/smithy-project">`smithy#project`</Link> generator:
|
|
232
|
+
|
|
233
|
+
<RunGenerator generator="smithy#project" requiredParameters={{ name: 'my-shapes', type: 'shapes' }} />
|
|
234
|
+
|
|
235
|
+
Your API's model can then reference its shapes with `use`:
|
|
236
|
+
|
|
237
|
+
```smithy
|
|
238
|
+
$version: "2.0"
|
|
239
|
+
|
|
240
|
+
namespace com.example.api
|
|
241
|
+
|
|
242
|
+
use com.example.shared#Customer
|
|
243
|
+
|
|
244
|
+
structure GetCustomerOutput {
|
|
245
|
+
@required
|
|
246
|
+
customer: Customer
|
|
247
|
+
}
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
See the <Link path="guides/smithy-project">Smithy project guide</Link> for how to create a shape library and wire it up as a dependency of your API's model.
|
|
251
|
+
|
|
227
252
|
### Implementing Operations in TypeScript
|
|
228
253
|
|
|
229
254
|
Operation implementations are located in the backend project's `src/operations/` directory. Each operation is implemented using the generated types from the TypeScript Server SDK (generated at build time from your Smithy model).
|
|
@@ -77,117 +77,11 @@ For TypeScript, check out [Smithy TypeScript](https://github.com/smithy-lang/smi
|
|
|
77
77
|
|
|
78
78
|
Type Safe API provided a Projen project type named `SmithyShapeLibraryProject` which configured a project which contained Smithy models which could be reused by multiple Smithy-based APIs.
|
|
79
79
|
|
|
80
|
-
The
|
|
80
|
+
The equivalent is the <Link path="/guides/smithy-project">`smithy#project` generator</Link> with `type` set to `shapes`:
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
<RunGenerator generator="smithy#project" requiredParameters={{ name: 'my-shapes', type: 'shapes' }} />
|
|
83
83
|
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
1. Create your shape library using the `smithy#project` generator:
|
|
87
|
-
|
|
88
|
-
<RunGenerator generator="smithy#project" />
|
|
89
|
-
|
|
90
|
-
Specify any name for the `serviceName` option, as we will remove the `service` shape.
|
|
91
|
-
|
|
92
|
-
:::note
|
|
93
|
-
This generator is hidden at the time of writing and so you will need to execute it via the CLI.
|
|
94
|
-
:::
|
|
95
|
-
|
|
96
|
-
1. Replace the default model in `src` with the shapes you wish to define
|
|
97
|
-
|
|
98
|
-
1. Update `smithy-build.json` to remove the `plugins` and any unused maven dependencies
|
|
99
|
-
|
|
100
|
-
1. Replace `build.Dockerfile` with minimal build steps:
|
|
101
|
-
|
|
102
|
-
```docker
|
|
103
|
-
// build.Dockerfile
|
|
104
|
-
FROM public.ecr.aws/docker/library/node:24 AS builder
|
|
105
|
-
|
|
106
|
-
# Output directory
|
|
107
|
-
RUN mkdir /out
|
|
108
|
-
|
|
109
|
-
# Install Smithy CLI
|
|
110
|
-
# https://smithy.io/2.0/guides/smithy-cli/cli_installation.html
|
|
111
|
-
WORKDIR /smithy
|
|
112
|
-
ARG TARGETPLATFORM
|
|
113
|
-
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then ARCH="aarch64"; else ARCH="x86_64"; fi && \
|
|
114
|
-
mkdir -p smithy-install/smithy && \
|
|
115
|
-
curl -L https://github.com/smithy-lang/smithy/releases/download/1.61.0/smithy-cli-linux-$ARCH.zip -o smithy-install/smithy-cli-linux-$ARCH.zip && \
|
|
116
|
-
unzip -qo smithy-install/smithy-cli-linux-$ARCH.zip -d smithy-install && \
|
|
117
|
-
mv smithy-install/smithy-cli-linux-$ARCH/* smithy-install/smithy
|
|
118
|
-
RUN smithy-install/smithy/install
|
|
119
|
-
|
|
120
|
-
# Copy project files
|
|
121
|
-
COPY smithy-build.json .
|
|
122
|
-
COPY src src
|
|
123
|
-
|
|
124
|
-
# Smithy build with Maven cache mount
|
|
125
|
-
RUN --mount=type=cache,target=/root/.m2/repository,id=maven-cache \
|
|
126
|
-
smithy build
|
|
127
|
-
|
|
128
|
-
RUN cp -r build/* /out/
|
|
129
|
-
|
|
130
|
-
# Export the /out directory
|
|
131
|
-
FROM scratch AS export
|
|
132
|
-
COPY --from=builder /out /
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
</Steps>
|
|
136
|
-
|
|
137
|
-
###### Consume the Shape Library
|
|
138
|
-
|
|
139
|
-
In your service model project(s), make the following changes to consume the shape library:
|
|
140
|
-
|
|
141
|
-
<Steps>
|
|
142
|
-
|
|
143
|
-
1. Update the `compile` target in `project.json` to add the workspace as build context, and a dependency on the shape library's `build` target
|
|
144
|
-
|
|
145
|
-
```json {10,15} "--build-context workspace=." "@my-project/shapes:build"
|
|
146
|
-
// project.json
|
|
147
|
-
{
|
|
148
|
-
"cache": true,
|
|
149
|
-
"outputs": ["{workspaceRoot}/dist/{projectRoot}/build"],
|
|
150
|
-
"executor": "nx:run-commands",
|
|
151
|
-
"options": {
|
|
152
|
-
"commands": [
|
|
153
|
-
"rimraf dist/packages/api/model/build",
|
|
154
|
-
"make-dir dist/packages/api/model/build",
|
|
155
|
-
"docker build --build-context workspace=. -f packages/api/model/build.Dockerfile --target export --output type=local,dest=dist/packages/api/model/build packages/api/model"
|
|
156
|
-
],
|
|
157
|
-
"parallel": false,
|
|
158
|
-
"cwd": "{workspaceRoot}"
|
|
159
|
-
},
|
|
160
|
-
"dependsOn": ["@my-project/shapes:build"]
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
1. Update the `build.Dockerfile` to copy the `src` directory from your shape library. For example, assuming the shape library is located in `packages/shapes`:
|
|
165
|
-
|
|
166
|
-
```docker {5}
|
|
167
|
-
// build.Dockerfile
|
|
168
|
-
# Copy project files
|
|
169
|
-
COPY smithy-build.json .
|
|
170
|
-
COPY src src
|
|
171
|
-
COPY --from=workspace packages/shapes/src shapes
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
1. Update `smithy-build.json` to add the shapes directory to its `sources`:
|
|
175
|
-
|
|
176
|
-
```json {4} "shapes/"
|
|
177
|
-
// smithy-build.json
|
|
178
|
-
{
|
|
179
|
-
"version": "1.0",
|
|
180
|
-
"sources": ["src/", "shapes/"],
|
|
181
|
-
"plugins": {
|
|
182
|
-
...
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
</Steps>
|
|
187
|
-
|
|
188
|
-
:::note
|
|
189
|
-
Please express your interest on the [GitHub issue here](https://github.com/awslabs/nx-plugin-for-aws/issues/304) if you have a use case for a dedicated Smithy shape library generator.
|
|
190
|
-
:::
|
|
84
|
+
Move the shapes from your `SmithyShapeLibraryProject` into the generated project's `src` folder, then refer to the <Link path="/guides/smithy-project#depending-on-a-shape-library">Smithy project guide</Link> for how to wire the library up as a dependency of your API's model.
|
|
191
85
|
|
|
192
86
|
#### Interceptors
|
|
193
87
|
|
|
@@ -11,7 +11,7 @@ import Snippet from '@components/snippet.astro';
|
|
|
11
11
|
### Recommended
|
|
12
12
|
|
|
13
13
|
- [AWS Credentials](https://docs.aws.amazon.com/sdkref/latest/guide/access.html) configured to your target AWS account are required to deploy your application (as well as for some local development workflows).
|
|
14
|
-
- [Docker](https://www.docker.com/) or [Finch](https://runfinch.com/) is required for some generators. For Docker, [multi-platform builds](https://docs.docker.com/build/building/multi-platform/) must be set up; Finch supports [multi-platform builds](https://runfinch.com/docs/getting-started/building-images/#building-a-multi-architecture-container-image) out of the box.
|
|
14
|
+
- [Docker](https://www.docker.com/) or [Finch >= 1.6.0](https://runfinch.com/) is required for some generators. For Docker, [multi-platform builds](https://docs.docker.com/build/building/multi-platform/) must be set up; Finch supports [multi-platform builds](https://runfinch.com/docs/getting-started/building-images/#building-a-multi-architecture-container-image) out of the box.
|
|
15
15
|
- [Terraform >= 1.12](https://developer.hashicorp.com/terraform/install) is required if you choose to use this for infrastructure as code instead of CDK
|
|
16
16
|
- verify by running `terraform --version`
|
|
17
17
|
- If you are using [VSCode](https://code.visualstudio.com/), we recommend installing the [Nx Console VSCode Plugin](https://marketplace.visualstudio.com/items?itemName=nrwl.angular-console).
|
package/generators.json
CHANGED
|
@@ -165,9 +165,9 @@
|
|
|
165
165
|
"smithy#project": {
|
|
166
166
|
"factory": "./src/smithy/project/generator",
|
|
167
167
|
"schema": "./src/smithy/project/schema.json",
|
|
168
|
-
"description": "Generate a Smithy model project",
|
|
168
|
+
"description": "Generate a Smithy model project, either defining a service or a library of reusable shapes",
|
|
169
169
|
"metric": "g27",
|
|
170
|
-
"
|
|
170
|
+
"guidePages": ["smithy-project"]
|
|
171
171
|
},
|
|
172
172
|
"smithy#react-connection": {
|
|
173
173
|
"factory": "./src/smithy/react-connection/generator",
|
package/package.json
CHANGED
|
@@ -15,9 +15,31 @@
|
|
|
15
15
|
"x-priority": "important",
|
|
16
16
|
"x-prompt": "What would you like to call your Smithy project?"
|
|
17
17
|
},
|
|
18
|
+
"type": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
"description": "The type of Smithy project to create. Choose between service (a model with a service shape, ready for an implementation) and shapes (a shape library of reusable shapes, shared between multiple Smithy projects).",
|
|
21
|
+
"default": "service",
|
|
22
|
+
"enum": ["service", "shapes"],
|
|
23
|
+
"x-priority": "important",
|
|
24
|
+
"x-prompt": {
|
|
25
|
+
"message": "What type of Smithy project would you like to create?",
|
|
26
|
+
"type": "list",
|
|
27
|
+
"items": [
|
|
28
|
+
{
|
|
29
|
+
"value": "service",
|
|
30
|
+
"label": "service (a model which defines a service and its operations)"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"value": "shapes",
|
|
34
|
+
"label": "shapes (a library of reusable shapes, shared between Smithy projects)"
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
"default": "service"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
18
40
|
"serviceName": {
|
|
19
41
|
"type": "string",
|
|
20
|
-
"description": "The name of your Smithy service. Uses the supplied name by default.",
|
|
42
|
+
"description": "The name of your Smithy service. Uses the supplied name by default. Not applicable to shape libraries.",
|
|
21
43
|
"x-prompt": "What name would you like your Smithy Service to have? i.e: MyService"
|
|
22
44
|
},
|
|
23
45
|
"namespace": {
|