You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: smithy-trait-codegen/README.md
+26-15Lines changed: 26 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,20 @@
1
1
# Smithy Trait CodeGen
2
2
3
-
Smithy build plugin that generates Java trait classes from customized Smithy trait defined with [`@trait`](https://smithy.io/2.0/spec/model.html#trait-trait).
3
+
This package contains a Smithy build plugin that generates Java trait classes from customized Smithy traits defined with [`@trait`](https://smithy.io/2.0/spec/model.html#trait-trait).
4
4
5
5
## Supported Trait Types
6
-
-[**Simple Types**](https://smithy.io/2.0/spec/simple-types.html) (Excluding `Blob` and `Boolean`)
7
-
-**Structure**
6
+
7
+
-[**Simple Types**](https://smithy.io/2.0/spec/simple-types.html), excluding `Blob` and `Boolean`
8
+
-**Structure**, including [annotation traits](https://smithy.io/2.0/spec/model.html#annotation-traits)
8
9
-**List**
9
10
-**Set**
10
11
-**Map**
11
12
12
13
> [!NOTE]
13
-
> [Annotation Trait](https://smithy.io/2.0/spec/model.html#annotation-traits)is recommended rather than Boolean trait
14
+
> [Annotation traits](https://smithy.io/2.0/spec/model.html#annotation-traits)are recommended instead of Boolean traits.
@@ -51,7 +53,9 @@ An example for `smithy-build.json`:
51
53
```
52
54
53
55
## Getting Started
56
+
54
57
### Configure `smithy-build.json`
58
+
55
59
To generate Java code for your customized traits, you will add the `trait-codegen` plugin to the
56
60
[plugin configuration](https://smithy.io/2.0/guides/smithy-build-json.html) in `smithy-build.json`:
57
61
@@ -67,11 +71,13 @@ To generate Java code for your customized traits, you will add the `trait-codege
67
71
}
68
72
}
69
73
```
74
+
70
75
### Add dependency
71
76
72
77
#### **Using Smithy CLI**
73
78
74
-
If you are using Smithy CLI, you will add dependency in `smithy-build.json`:
79
+
If you are using the Smithy CLI, declare a dependency in `smithy-build.json`:
80
+
75
81
```json
76
82
{
77
83
"version": "1.0",
@@ -84,9 +90,13 @@ If you are using Smithy CLI, you will add dependency in `smithy-build.json`:
84
90
"...": "..."
85
91
}
86
92
```
87
-
Then you can run `smithy build` to build the model and generate Java code for your customized traits.
93
+
94
+
Then, running `smithy build` will build the model and generate Java code for your customized traits.
95
+
88
96
#### **Using Gradle**
89
-
If you are using Gradle, you will add dependency `id("software.amazon.smithy.gradle.smithy-trait-package").version("1.3.0")` to the `plugin` section in `build.gradle.kts`:
97
+
98
+
If you are using Gradle, declare a dependency in the `plugin` section in `build.gradle.kts`:
Then you can run `gradle build` to build the model and generate Java code for your customized traits.
115
+
116
+
Then, running `gradle build` will build the model and generate Java code for your customized traits.
106
117
107
118
### Check the Generated Code
108
-
Finally you can find the the generated Java classes under `/build/smithyprojections/trait-codegen/`
109
119
110
-
The generated Java class for `annotationTrait` from `custom-trait` template would be:
120
+
Finally, you can find the generated Java classes under `/build/smithyprojections/trait-codegen/`
121
+
122
+
The generated Java class for `annotationTrait` from `custom-trait`[template](https://github.com/smithy-lang/smithy-examples/tree/main/custom-trait-examples/custom-trait) would be:
@@ -135,7 +148,9 @@ public final class AnnotationTrait extends AbstractTrait implements ToSmithyBuil
135
148
// Service Provider Implementation
136
149
}
137
150
```
138
-
The generated Java class for `JsonNameTrait` from `custom-trait` template would be:
151
+
152
+
The generated Java class for `JsonNameTrait` from `custom-trait`[template](https://github.com/smithy-lang/smithy-examples/tree/main/custom-trait-examples/custom-trait) would be:
153
+
139
154
```java
140
155
@SmithyGenerated
141
156
publicfinalclassJsonNameTraitextendsStringTrait {
@@ -154,7 +169,3 @@ public final class JsonNameTrait extends StringTrait {
0 commit comments