48
48
import software .amazon .smithy .model .traits .DocumentationTrait ;
49
49
import software .amazon .smithy .model .traits .ErrorTrait ;
50
50
import software .amazon .smithy .model .traits .InternalTrait ;
51
+ import software .amazon .smithy .model .traits .ExamplesTrait ;
51
52
import software .amazon .smithy .rulesengine .traits .EndpointRuleSetTrait ;
52
53
import software .amazon .smithy .typescript .codegen .documentation .StructureExampleGenerator ;
53
54
import software .amazon .smithy .typescript .codegen .endpointsV2 .RuleSetParameterFinder ;
@@ -199,10 +200,12 @@ private void generateClientCommand() {
199
200
writer .write ("}" ); // class close bracket.
200
201
}
201
202
202
- private String getCommandExample (String serviceName , String configName , String commandName , String commandInput ,
203
- String commandOutput ) {
203
+ private String getCommandExample (
204
+ String serviceName , String configName , String commandName ,
205
+ String commandInput , String commandOutput
206
+ ) {
204
207
String packageName = settings .getPackageName ();
205
- return "@example\n "
208
+ String exampleDoc = "@example\n "
206
209
+ "Use a bare-bones client and the command you need to make an API call.\n "
207
210
+ "```javascript\n "
208
211
+ String .format ("import { %s, %s } from \" %s\" ; // ES Modules import%n" , serviceName , commandName ,
@@ -225,6 +228,13 @@ private String getCommandExample(String serviceName, String configName, String c
225
228
+ String .format ("@see {@link %s} for command's `input` shape.%n" , commandInput )
226
229
+ String .format ("@see {@link %s} for command's `response` shape.%n" , commandOutput )
227
230
+ String .format ("@see {@link %s | config} for %s's `config` shape.%n" , configName , serviceName );
231
+
232
+ if (operation .getTrait (ExamplesTrait .class ).isPresent ()) {
233
+ List <ExamplesTrait .Example > examples = operation .getTrait (ExamplesTrait .class ).get ().getExamples ();
234
+ exampleDoc += getOperationExample (examples );
235
+ }
236
+
237
+ return exampleDoc ;
228
238
}
229
239
230
240
private String getThrownExceptions () {
@@ -252,6 +262,21 @@ private String getThrownExceptions() {
252
262
return buffer .toString ();
253
263
}
254
264
265
+ private String getOperationExample (List <ExamplesTrait .Example > examples ) {
266
+ StringBuilder buffer = new StringBuilder ();
267
+ for (ExamplesTrait .Example example : examples ) {
268
+ buffer
269
+ .append ("\n " )
270
+ .append (String .format ("@example %s" , example .getTitle ()))
271
+ .append ("```javascript" )
272
+ .append (String .format ("/* %s */" , example .getDocumentation ()))
273
+ .append ("some code here" )
274
+ .append ("```" )
275
+ .append ("\n " );
276
+ }
277
+ return buffer .toString ();
278
+ }
279
+
255
280
private void generateEndpointParameterInstructionProvider () {
256
281
if (!service .hasTrait (EndpointRuleSetTrait .class )) {
257
282
return ;
0 commit comments