Skip to content

Commit 251b7b5

Browse files
committed
update tests, formatting
1 parent e00595e commit 251b7b5

File tree

3 files changed

+240
-181
lines changed

3 files changed

+240
-181
lines changed

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/CommandGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ private String getCommandExample(String serviceName, String configName, String c
212212
+ String.format("const client = new %s(config);%n", serviceName)
213213
+ String.format("const input = %s%n",
214214
StructureExampleGenerator.generateStructuralHintDocumentation(
215-
model.getShape(operation.getInputShape()).get(), model, false))
215+
model.getShape(operation.getInputShape()).get(), model, false, true))
216216
+ String.format("const command = new %s(input);%n", commandName)
217217
+ "const response = await client.send(command);\n"
218218
+ String.format("%s%n",
219219
StructureExampleGenerator.generateStructuralHintDocumentation(
220-
model.getShape(operation.getOutputShape()).get(), model, true))
220+
model.getShape(operation.getOutputShape()).get(), model, true, false))
221221
+ "\n```\n"
222222
+ "\n"
223223
+ String.format("@param %s - {@link %s}%n", commandInput, commandInput)

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGenerator.java

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import software.amazon.smithy.model.shapes.Shape;
2323
import software.amazon.smithy.model.shapes.StructureShape;
2424
import software.amazon.smithy.model.shapes.UnionShape;
25-
import software.amazon.smithy.model.traits.InputTrait;
2625
import software.amazon.smithy.model.traits.RequiredTrait;
2726
import software.amazon.smithy.model.traits.StreamingTrait;
2827

@@ -45,20 +44,24 @@ public abstract class StructureExampleGenerator {
4544
* };
4645
* ```
4746
*/
48-
public static String generateStructuralHintDocumentation(Shape shape, Model model, boolean isComment) {
47+
public static String generateStructuralHintDocumentation(
48+
Shape shape,
49+
Model model,
50+
boolean isComment,
51+
boolean isInput
52+
) {
4953
StringBuilder buffer = new StringBuilder();
50-
boolean isInput = shape.hasTrait(InputTrait.class);
5154
shape(shape, buffer, model, 0, new ShapeTracker(), isInput);
5255

5356
// replace non-leading whitespace with single space.
5457
String s = Arrays.stream(
5558
buffer.toString()
56-
.split("\n"))
57-
.map(line -> line.replaceAll(
58-
"([\\w\\\",:\\[\\{] )\\s+",
59-
"$1")
60-
.replaceAll("\\s+$", ""))
61-
.collect(Collectors.joining((isComment) ? "\n// " : "\n"));
59+
.split("\n"))
60+
.map(line -> line.replaceAll(
61+
"([\\w\\\",:\\[\\{] )\\s+",
62+
"$1")
63+
.replaceAll("\\s+$", ""))
64+
.collect(Collectors.joining((isComment) ? "\n// " : "\n"));
6265

6366
return ((isComment) ? "// " : "") + s.replaceAll(",$", ";");
6467
}
@@ -74,9 +77,9 @@ private static void structure(StructureShape structureShape,
7477
checkRequired(indentation, buffer, structureShape);
7578
} else {
7679
append(indentation, buffer,
77-
"{" + (shapeTracker.getOccurrenceCount(structureShape) == 1
78-
? " // " + structureShape.getId().getName()
79-
: ""));
80+
"{" + (shapeTracker.getOccurrenceCount(structureShape) == 1
81+
? " // " + structureShape.getId().getName()
82+
: ""));
8083
checkRequired(indentation, buffer, structureShape);
8184
structureShape.getAllMembers().values().forEach(member -> {
8285
append(indentation + 2, buffer, member.getMemberName() + ": ");
@@ -93,8 +96,8 @@ private static void union(UnionShape unionShape,
9396
ShapeTracker shapeTracker,
9497
boolean isInput) {
9598
append(indentation, buffer, "{" + (shapeTracker.getOccurrenceCount(unionShape) == 1
96-
? " // " + unionShape.getId().getName()
97-
: "// ") + " Union: only one key present");
99+
? " // " + unionShape.getId().getName()
100+
: "// ") + " Union: only one key present");
98101
checkRequired(indentation, buffer, unionShape);
99102
unionShape.getAllMembers().values().forEach(member -> {
100103
append(indentation + 2, buffer, member.getMemberName() + ": ");
@@ -183,22 +186,22 @@ private static void shape(Shape shape,
183186
case SET:
184187
case LIST:
185188
append(indentation, buffer, "[" + (shapeTracker.getOccurrenceCount(target) == 1
186-
? " // " + target.getId().getName()
187-
: ""));
189+
? " // " + target.getId().getName()
190+
: ""));
188191
checkRequired(indentation, buffer, shape);
189192
ListShape list = (ListShape) target;
190193
shape(list.getMember(), buffer, model, indentation + 2, shapeTracker, isInput);
191194
append(indentation, buffer, "],\n");
192195
break;
193196
case MAP:
194197
append(indentation, buffer, "{" + (shapeTracker.getOccurrenceCount(target) == 1
195-
? " // " + target.getId().getName()
196-
: ""));
198+
? " // " + target.getId().getName()
199+
: ""));
197200
checkRequired(indentation, buffer, shape);
198201
append(indentation + 2, buffer, "\"<keys>\": ");
199202
MapShape map = (MapShape) target;
200203
shape(model.getShape(map.getValue().getTarget()).get(), buffer, model, indentation + 2,
201-
shapeTracker, isInput);
204+
shapeTracker, isInput);
202205
append(indentation, buffer, "},\n");
203206
break;
204207

@@ -214,19 +217,19 @@ private static void shape(Shape shape,
214217
case ENUM:
215218
EnumShape enumShape = (EnumShape) target;
216219
String enumeration = enumShape.getEnumValues()
217-
.values()
218-
.stream()
219-
.map(s -> "\"" + s + "\"")
220-
.collect(Collectors.joining(" || "));
220+
.values()
221+
.stream()
222+
.map(s -> "\"" + s + "\"")
223+
.collect(Collectors.joining(" || "));
221224
append(indentation, buffer, enumeration + ",");
222225
break;
223226
case INT_ENUM:
224227
IntEnumShape intEnumShape = (IntEnumShape) target;
225228
String intEnumeration = intEnumShape.getEnumValues()
226-
.values()
227-
.stream()
228-
.map(i -> Integer.toString(i))
229-
.collect(Collectors.joining(" || "));
229+
.values()
230+
.stream()
231+
.map(i -> Integer.toString(i))
232+
.collect(Collectors.joining(" || "));
230233
append(indentation, buffer, intEnumeration + ",");
231234
break;
232235
case OPERATION:
@@ -311,8 +314,8 @@ public void mark(Shape shape, int depth) {
311314
*/
312315
public boolean shouldTruncate(Shape shape) {
313316
return (shape instanceof MapShape || shape instanceof UnionShape || shape instanceof StructureShape
314-
|| shape instanceof ListShape || shape instanceof SetShape)
315-
&& (getOccurrenceCount(shape) > 5 || getOccurrenceDepths(shape) > 2);
317+
|| shape instanceof ListShape || shape instanceof SetShape)
318+
&& (getOccurrenceCount(shape) > 5 || getOccurrenceDepths(shape) > 2);
316319
}
317320

318321
/**

0 commit comments

Comments
 (0)