@@ -28,7 +28,7 @@ This repository does *not* contain any generated clients, such as for S3 or othe
2828AWS services. Rather, these are the tools that facilitate the generation of those
2929clients and non-AWS Smithy clients.
3030
31- ### How do I use this?
31+ ### How do I use this to create a client ?
3232
3333The first step is to create a Smithy package. If this is your first time working
3434with Smithy, follow [ this quickstart guide] ( https://smithy.io/2.0/quickstart.html )
@@ -82,9 +82,9 @@ this file, see the
8282 "sources" : [" model" ],
8383 "maven" : {
8484 "dependencies" : [
85- " software.amazon.smithy:smithy-model:[1.34 .0,2.0)" ,
86- " software.amazon.smithy:smithy-aws-traits:[1.34 .0,2.0)" ,
87- " software.amazon.smithy.python:smithy-python- codegen:0.1.0 "
85+ " software.amazon.smithy:smithy-model:[1.54 .0,2.0)" ,
86+ " software.amazon.smithy:smithy-aws-traits:[1.54 .0,2.0)" ,
87+ " software.amazon.smithy.python. codegen:core:0.0.1 "
8888 ]
8989 },
9090 "projections" : {
@@ -175,6 +175,146 @@ Only for now. Once the generator has been published, the Smithy CLI will be able
175175to run it without a separate Java installation. Similarly, once the python
176176helper libraries have been published you won't need to install them locally.
177177
178+ ### How do I generate types for shapes without a client?
179+
180+ If all you want are concrete Python classes for the shapes in your Smithy model,
181+ all you need to do is replace ` python-client-codegen ` with
182+ ` python-type-codegen ` when following the steps above. Your ` smithy-build.json `
183+ would now look like:
184+
185+ ``` json
186+ {
187+ "version" : " 1.0" ,
188+ "sources" : [" model" ],
189+ "maven" : {
190+ "dependencies" : [
191+ " software.amazon.smithy:smithy-model:[1.54.0,2.0)" ,
192+ " software.amazon.smithy.python.codegen.plugins:types:0.0.1"
193+ ]
194+ },
195+ "projections" : {
196+ "shapes" : {
197+ "plugins" : {
198+ "python-type-codegen" : {
199+ "service" : " com.example#EchoService" ,
200+ "module" : " echo" ,
201+ "moduleVersion" : " 0.0.1"
202+ }
203+ }
204+ }
205+ }
206+ }
207+ ```
208+
209+ The module with the generated shape classes can be found in
210+ ` build/smithy/client/python-type-codegen ` after you run ` smithy-build ` .
211+
212+ Unlike when generating a client, a service shape is not required for shape
213+ generation. If a service is not provided then every shape found in the model
214+ will be generated. Any naming conflicts may be resolved by using the
215+ [ ` renameShapes ` transform] ( https://smithy.io/2.0/guides/smithy-build-json.html#renameshapes )
216+ (or renaming the shapes in the model of course).
217+
218+ The set of shapes generated can also be constrained by using the
219+ [ ` includeShapesBySelector ` transform] ( https://smithy.io/2.0/guides/smithy-build-json.html#includeshapesbyselector ) .
220+ For example, to generate only shapes within the ` com.example ` namespace:
221+
222+ ``` json
223+ {
224+ "version" : " 1.0" ,
225+ "sources" : [" model" ],
226+ "maven" : {
227+ "dependencies" : [
228+ " software.amazon.smithy:smithy-model:[1.54.0,2.0)" ,
229+ " software.amazon.smithy.python.codegen.plugins:types:0.0.1"
230+ ]
231+ },
232+ "projections" : {
233+ "shapes" : {
234+ "transforms" : [
235+ {
236+ "name" : " includeShapesBySelector" ,
237+ "args" : {
238+ "selector" : " [id|namespace = 'com.example']"
239+ }
240+ }
241+ ],
242+ "plugins" : {
243+ "python-type-codegen" : {
244+ "module" : " echo" ,
245+ "moduleVersion" : " 0.0.1"
246+ }
247+ }
248+ }
249+ }
250+ }
251+ ```
252+
253+ Input and output shapes (shapes with the ` @input ` or ` @output ` traits and
254+ operation inputs / outputs created as part of an operation definition) are not
255+ generated by default. To generate these shapes anyway, set the
256+ ` generateInputsAndOutputs ` property to ` true ` .
257+
258+ ``` json
259+ {
260+ "version" : " 1.0" ,
261+ "sources" : [" model" ],
262+ "maven" : {
263+ "dependencies" : [
264+ " software.amazon.smithy:smithy-model:[1.54.0,2.0)" ,
265+ " software.amazon.smithy.python.codegen.plugins:types:0.0.1"
266+ ]
267+ },
268+ "projections" : {
269+ "shapes" : {
270+ "plugins" : {
271+ "python-type-codegen" : {
272+ "module" : " echo" ,
273+ "moduleVersion" : " 0.0.1" ,
274+ "generateInputsAndOutputs" : true
275+ }
276+ }
277+ }
278+ }
279+ }
280+ ```
281+
282+ You can also generate both a client package and a shape package in one build,
283+ but they won't depend on each other. To do this, just add both plugins in the
284+ projection, or create a projection for each plugin. Below is an example showing
285+ both plugins in one projection:
286+
287+ ``` json
288+ {
289+ "version" : " 1.0" ,
290+ "sources" : [" model" ],
291+ "maven" : {
292+ "dependencies" : [
293+ " software.amazon.smithy:smithy-model:[1.54.0,2.0)" ,
294+ " software.amazon.smithy:smithy-aws-traits:[1.54.0,2.0)" ,
295+ " software.amazon.smithy.python.codegen:core:0.0.1" ,
296+ " software.amazon.smithy.python.codegen.plugins:types:0.0.1"
297+ ]
298+ },
299+ "projections" : {
300+ "client" : {
301+ "plugins" : {
302+ "python-client-codegen" : {
303+ "service" : " com.example#EchoService" ,
304+ "module" : " echo" ,
305+ "moduleVersion" : " 0.0.1"
306+ },
307+ "python-type-codegen" : {
308+ "service" : " com.example#EchoService" ,
309+ "module" : " echo" ,
310+ "moduleVersion" : " 0.0.1"
311+ }
312+ }
313+ }
314+ }
315+ }
316+ ```
317+
178318### Core Modules and Interfaces
179319
180320* ` smithy-core ` provides transport-agnostic core modules and interfaces
0 commit comments