Skip to content

Commit

Permalink
docs: WIP add doc examples to operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Jun 12, 2024
1 parent 38da900 commit 00fe434
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import software.amazon.smithy.model.traits.DocumentationTrait;
import software.amazon.smithy.model.traits.ErrorTrait;
import software.amazon.smithy.model.traits.InternalTrait;
import software.amazon.smithy.model.traits.ExamplesTrait;
import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait;
import software.amazon.smithy.typescript.codegen.documentation.StructureExampleGenerator;
import software.amazon.smithy.typescript.codegen.endpointsV2.RuleSetParameterFinder;
Expand Down Expand Up @@ -199,10 +200,12 @@ private void generateClientCommand() {
writer.write("}"); // class close bracket.
}

private String getCommandExample(String serviceName, String configName, String commandName, String commandInput,
String commandOutput) {
private String getCommandExample(
String serviceName, String configName, String commandName,
String commandInput, String commandOutput
) {
String packageName = settings.getPackageName();
return "@example\n"
String exampleDoc = "@example\n"
+ "Use a bare-bones client and the command you need to make an API call.\n"
+ "```javascript\n"
+ String.format("import { %s, %s } from \"%s\"; // ES Modules import%n", serviceName, commandName,
Expand All @@ -225,6 +228,13 @@ private String getCommandExample(String serviceName, String configName, String c
+ String.format("@see {@link %s} for command's `input` shape.%n", commandInput)
+ String.format("@see {@link %s} for command's `response` shape.%n", commandOutput)
+ String.format("@see {@link %s | config} for %s's `config` shape.%n", configName, serviceName);

if (operation.getTrait(ExamplesTrait.class).isPresent()) {
List<ExamplesTrait.Example> examples = operation.getTrait(ExamplesTrait.class).get().getExamples();
exampleDoc += getOperationExample(examples);
}

return exampleDoc;
}

private String getThrownExceptions() {
Expand Down Expand Up @@ -252,6 +262,21 @@ private String getThrownExceptions() {
return buffer.toString();
}

private String getOperationExample(List<ExamplesTrait.Example> examples) {
StringBuilder buffer = new StringBuilder();
for (ExamplesTrait.Example example : examples) {
buffer
.append("\n")
.append(String.format("@example %s", example.getTitle()))
.append("```javascript")
.append(String.format("/* %s */", example.getDocumentation()))
.append("some code here")
.append("```")
.append("\n");
}
return buffer.toString();
}

private void generateEndpointParameterInstructionProvider() {
if (!service.hasTrait(EndpointRuleSetTrait.class)) {
return;
Expand Down

0 comments on commit 00fe434

Please sign in to comment.