From 22033c1a1049c983b8397722048b56c717f4a233 Mon Sep 17 00:00:00 2001 From: George Fu Date: Fri, 24 Mar 2023 17:17:32 +0000 Subject: [PATCH] formatting fixes --- .../StructureExampleGenerator.java | 78 +++++++++---------- .../StructureExampleGeneratorTest.java | 10 +-- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGenerator.java b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGenerator.java index 6431a96c5e9..5ef4a56a743 100644 --- a/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGenerator.java +++ b/smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGenerator.java @@ -52,11 +52,11 @@ public static String generateStructuralHintDocumentation(Shape shape, Model mode buffer.toString() .split("\n")) .map(line -> line.replaceAll( - "([\\w\\\",:] )\\s+", + "([\\w\\\",:\\[\\{] )\\s+", "$1")) .collect(Collectors.joining("\n")); - return s; + return s.replaceAll(",$", ";"); } private static void structure(StructureShape structureShape, @@ -64,7 +64,7 @@ private static void structure(StructureShape structureShape, int indentation, ShapeTracker shapeTracker) { if (structureShape.getAllMembers().size() == 0) { - append(indentation, buffer, "{}"); + append(indentation, buffer, "{},"); checkRequired(indentation, buffer, structureShape); } else { append(indentation, buffer, "{"); @@ -73,7 +73,7 @@ private static void structure(StructureShape structureShape, append(indentation + 2, buffer, member.getMemberName() + ": "); shape(member, buffer, model, indentation + 2, shapeTracker); }); - append(indentation, buffer, "}\n"); + append(indentation, buffer, "},\n"); } } @@ -88,7 +88,7 @@ private static void union(UnionShape unionShape, append(indentation + 2, buffer, member.getMemberName() + ": "); shape(member, buffer, model, indentation + 2, shapeTracker); }); - append(indentation, buffer, "}\n"); + append(indentation, buffer, "},\n"); } private static void shape(Shape shape, @@ -104,8 +104,8 @@ private static void shape(Shape shape, } shapeTracker.mark(shape, indentation); - if (shapeTracker.getOccurrenceDepths(shape) > 5) { - append(indentation, buffer, "\"<" + shape.getId().getName() + ">\""); + if (shapeTracker.getOccurrenceDepths(shape) > 2) { + append(indentation, buffer, "\"<" + shape.getId().getName() + ">\"\n"); } else { switch (target.getType()) { case BIG_DECIMAL: @@ -186,7 +186,7 @@ private static void shape(Shape shape, .stream() .map(s -> "\"" + s + "\"") .collect(Collectors.joining(" || ")); - append(indentation, buffer, enumeration); + append(indentation, buffer, enumeration + ","); break; case INT_ENUM: IntEnumShape intEnumShape = (IntEnumShape) target; @@ -195,7 +195,7 @@ private static void shape(Shape shape, .stream() .map(i -> Integer.toString(i)) .collect(Collectors.joining(" || ")); - append(indentation, buffer, intEnumeration); + append(indentation, buffer, intEnumeration + ","); break; case OPERATION: case RESOURCE: @@ -205,37 +205,37 @@ private static void shape(Shape shape, append(indentation, buffer, "\"...\","); break; } - } - switch (target.getType()) { - case STRUCTURE: - case UNION: - case LIST: - case SET: - case MAP: - break; - case BIG_DECIMAL: - case BIG_INTEGER: - case BLOB: - case BOOLEAN: - case BYTE: - case DOCUMENT: - case DOUBLE: - case ENUM: - case FLOAT: - case INTEGER: - case INT_ENUM: - case LONG: - case MEMBER: - case OPERATION: - case RESOURCE: - case SERVICE: - case SHORT: - case STRING: - case TIMESTAMP: - default: - checkRequired(indentation, buffer, shape); - break; + switch (target.getType()) { + case STRUCTURE: + case UNION: + case LIST: + case SET: + case MAP: + break; + case BIG_DECIMAL: + case BIG_INTEGER: + case BLOB: + case BOOLEAN: + case BYTE: + case DOCUMENT: + case DOUBLE: + case ENUM: + case FLOAT: + case INTEGER: + case INT_ENUM: + case LONG: + case MEMBER: + case OPERATION: + case RESOURCE: + case SERVICE: + case SHORT: + case STRING: + case TIMESTAMP: + default: + checkRequired(indentation, buffer, shape); + break; + } } } diff --git a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGeneratorTest.java b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGeneratorTest.java index e55e2055df3..41abd0b466b 100644 --- a/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGeneratorTest.java +++ b/smithy-typescript-codegen/src/test/java/software/amazon/smithy/typescript/codegen/documentation/StructureExampleGeneratorTest.java @@ -66,7 +66,7 @@ public class StructureExampleGeneratorTest { public void generatesStructuralHintDocumentation_map() { assertThat( StructureExampleGenerator.generateStructuralHintDocumentation(map, model), - equalTo("{\n \"\": \"STRING_VALUE\", \n},")); + equalTo("{\n \"\": \"STRING_VALUE\", \n};")); } @Test @@ -75,19 +75,19 @@ public void generatesStructuralHintDocumentation_structure() { StructureExampleGenerator.generateStructuralHintDocumentation(structure, model), equalTo("{\n" + " string: \"STRING_VALUE\", \n" - + " list: [ \n" + + " list: [ \n" + " \"STRING_VALUE\", \n" + " ],\n" - + " map: { \n" + + " map: { \n" + " \"\": \"STRING_VALUE\", \n" + " },\n" - + "}")); + + "};")); } @Test public void generatesStructuralHintDocumentation_list() { assertThat( StructureExampleGenerator.generateStructuralHintDocumentation(list, model), - equalTo("[\n \"STRING_VALUE\", \n],")); + equalTo("[\n \"STRING_VALUE\", \n];")); } }