Skip to content

Commit e7032e8

Browse files
authored
Throw invalid model for lowercase shape names (#6570)
1 parent 263c0f2 commit e7032e8

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/customization/processors/LowercaseShapeValidatorProcessor.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
import software.amazon.awssdk.codegen.customization.CodegenCustomizationProcessor;
1919
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
2020
import software.amazon.awssdk.codegen.model.service.ServiceModel;
21+
import software.amazon.awssdk.codegen.validation.ModelInvalidException;
22+
import software.amazon.awssdk.codegen.validation.ValidationEntry;
23+
import software.amazon.awssdk.codegen.validation.ValidationErrorId;
24+
import software.amazon.awssdk.codegen.validation.ValidationErrorSeverity;
2125

2226
/**
2327
* A processor that validates shape names in service models to ensure they start with uppercase letters.
@@ -31,11 +35,12 @@ public void preprocess(ServiceModel serviceModel) {
3135

3236
serviceModel.getShapes().forEach((shapeName, shape) -> {
3337
if ("structure".equals(shape.getType()) && Character.isLowerCase(shapeName.charAt(0))) {
34-
throw new IllegalStateException(
35-
String.format("Shape name '%s' starts with a lowercase character." +
36-
"Shape names must start with an uppercase character." +
37-
"Please update the shape name in your service model",
38-
shapeName));
38+
String errorMsg = String.format("Shape name '%s' starts with a lowercase character. Shape names must start with"
39+
+ " an uppercase character. Please update the shape name in your service model",
40+
shapeName);
41+
ValidationEntry entry = ValidationEntry.create(ValidationErrorId.INVALID_IDENTIFIER_NAME,
42+
ValidationErrorSeverity.DANGER, errorMsg);
43+
throw ModelInvalidException.fromEntry(entry);
3944
}
4045
});
4146
}

codegen/src/test/java/software/amazon/awssdk/codegen/customization/processors/LowercaseShapeValidatorProcessorTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
import org.junit.jupiter.api.Test;
2424
import software.amazon.awssdk.codegen.model.service.ServiceModel;
2525
import software.amazon.awssdk.codegen.utils.ModelLoaderUtils;
26+
import software.amazon.awssdk.codegen.validation.ModelInvalidException;
27+
import software.amazon.awssdk.codegen.validation.ValidationEntry;
28+
import software.amazon.awssdk.codegen.validation.ValidationErrorId;
29+
import software.amazon.awssdk.codegen.validation.ValidationErrorSeverity;
2630

2731
public class LowercaseShapeValidatorProcessorTest {
2832

@@ -40,7 +44,14 @@ public static void setUp() throws IOException {
4044
@Test
4145
public void preprocess_serviceWithLowercaseShape_throwsException() {
4246
assertThatThrownBy(() -> processor.preprocess(serviceModel))
43-
.isInstanceOf(IllegalStateException.class)
44-
.hasMessageContaining("Shape name 'lowercaseshape' starts with a lowercase character");
47+
.isInstanceOf(ModelInvalidException.class)
48+
.hasMessageContaining("Shape name 'lowercaseshape' starts with a lowercase character")
49+
.matches(e -> {
50+
ModelInvalidException modelInvalid = (ModelInvalidException) e;
51+
ValidationEntry entry = modelInvalid.validationEntries().get(0);
52+
53+
return entry.getErrorId() == ValidationErrorId.INVALID_IDENTIFIER_NAME &&
54+
entry.getSeverity() == ValidationErrorSeverity.DANGER;
55+
}, "Validation entry details are correct");
4556
}
4657
}

0 commit comments

Comments
 (0)