Skip to content

Commit 20cf7d5

Browse files
committed
Add SharedModelsValidator
This validator ensures that when two services share models, any shared model definitions are identical.
1 parent f981caa commit 20cf7d5

30 files changed

+1222
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "",
5+
"description": "Add support for validating that shared models between two services are identical."
6+
}

codegen/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,10 @@
239239
<artifactId>mockito-core</artifactId>
240240
<scope>compile</scope>
241241
</dependency>
242+
<dependency>
243+
<groupId>nl.jqno.equalsverifier</groupId>
244+
<artifactId>equalsverifier</artifactId>
245+
<scope>test</scope>
246+
</dependency>
242247
</dependencies>
243248
</project>

codegen/src/main/java/software/amazon/awssdk/codegen/CodeGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@
3232
import software.amazon.awssdk.codegen.validation.ModelValidationContext;
3333
import software.amazon.awssdk.codegen.validation.ModelValidationReport;
3434
import software.amazon.awssdk.codegen.validation.ModelValidator;
35+
import software.amazon.awssdk.codegen.validation.SharedModelsValidator;
3536
import software.amazon.awssdk.codegen.validation.ValidationEntry;
3637
import software.amazon.awssdk.utils.Logger;
3738

3839
public class CodeGenerator {
3940
private static final Logger log = Logger.loggerFor(CodeGenerator.class);
4041
private static final String MODEL_DIR_NAME = "models";
4142

42-
// TODO: add validators
43-
private static final List<ModelValidator> DEFAULT_MODEL_VALIDATORS = Collections.emptyList();
43+
private static final List<ModelValidator> DEFAULT_MODEL_VALIDATORS = Collections.singletonList(
44+
new SharedModelsValidator()
45+
);
4446

4547
private final C2jModels c2jModels;
4648

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/ArgumentModel.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package software.amazon.awssdk.codegen.model.intermediate;
1717

18+
import java.util.Objects;
19+
1820
public class ArgumentModel extends DocumentationModel {
1921

2022
private String name;
@@ -61,4 +63,28 @@ public ArgumentModel withIsEnumArg(boolean isEnumArg) {
6163
this.isEnumArg = isEnumArg;
6264
return this;
6365
}
66+
67+
@Override
68+
public boolean equals(Object o) {
69+
if (o == null || getClass() != o.getClass()) {
70+
return false;
71+
}
72+
if (!super.equals(o)) {
73+
return false;
74+
}
75+
76+
ArgumentModel that = (ArgumentModel) o;
77+
return isEnumArg == that.isEnumArg
78+
&& Objects.equals(name, that.name)
79+
&& Objects.equals(type, that.type);
80+
}
81+
82+
@Override
83+
public int hashCode() {
84+
int result = super.hashCode();
85+
result = 31 * result + Objects.hashCode(name);
86+
result = 31 * result + Objects.hashCode(type);
87+
result = 31 * result + Boolean.hashCode(isEnumArg);
88+
return result;
89+
}
6490
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/AuthorizerModel.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.codegen.model.intermediate;
1717

1818
import com.fasterxml.jackson.annotation.JsonIgnore;
19+
import java.util.Objects;
1920
import software.amazon.awssdk.codegen.model.service.Location;
2021

2122
public class AuthorizerModel extends DocumentationModel {
@@ -63,4 +64,30 @@ public String getAddAuthTokenMethod() {
6364
authTokenLocation));
6465
}
6566
}
67+
68+
@Override
69+
public boolean equals(Object o) {
70+
if (o == null || getClass() != o.getClass()) {
71+
return false;
72+
}
73+
if (!super.equals(o)) {
74+
return false;
75+
}
76+
77+
AuthorizerModel that = (AuthorizerModel) o;
78+
return Objects.equals(name, that.name)
79+
&& Objects.equals(interfaceName, that.interfaceName)
80+
&& authTokenLocation == that.authTokenLocation
81+
&& Objects.equals(tokenName, that.tokenName);
82+
}
83+
84+
@Override
85+
public int hashCode() {
86+
int result = super.hashCode();
87+
result = 31 * result + Objects.hashCode(name);
88+
result = 31 * result + Objects.hashCode(interfaceName);
89+
result = 31 * result + Objects.hashCode(authTokenLocation);
90+
result = 31 * result + Objects.hashCode(tokenName);
91+
return result;
92+
}
6693
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/DocumentationModel.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import static software.amazon.awssdk.codegen.internal.DocumentationUtils.escapeIllegalCharacters;
1919

20+
import java.util.Objects;
21+
2022
public class DocumentationModel {
2123

2224
protected String documentation;
@@ -28,4 +30,22 @@ public String getDocumentation() {
2830
public void setDocumentation(String documentation) {
2931
this.documentation = escapeIllegalCharacters(documentation);
3032
}
33+
34+
@Override
35+
public boolean equals(Object o) {
36+
if (this == o) {
37+
return true;
38+
}
39+
if (o == null || getClass() != o.getClass()) {
40+
return false;
41+
}
42+
43+
DocumentationModel that = (DocumentationModel) o;
44+
return Objects.equals(documentation, that.documentation);
45+
}
46+
47+
@Override
48+
public int hashCode() {
49+
return Objects.hashCode(documentation);
50+
}
3151
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/EndpointDiscovery.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,22 @@ public boolean isRequired() {
2626
public void setRequired(boolean required) {
2727
this.required = required;
2828
}
29+
30+
@Override
31+
public boolean equals(Object o) {
32+
if (this == o) {
33+
return true;
34+
}
35+
if (o == null || getClass() != o.getClass()) {
36+
return false;
37+
}
38+
39+
EndpointDiscovery that = (EndpointDiscovery) o;
40+
return required == that.required;
41+
}
42+
43+
@Override
44+
public int hashCode() {
45+
return Boolean.hashCode(required);
46+
}
2947
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/EnumModel.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
package software.amazon.awssdk.codegen.model.intermediate;
1717

18+
import java.util.Objects;
19+
1820
/**
1921
* Represents a single enum field in a enum.
2022
*/
@@ -49,4 +51,23 @@ public String getValue() {
4951
return value;
5052
}
5153

54+
@Override
55+
public boolean equals(Object o) {
56+
if (this == o) {
57+
return true;
58+
}
59+
if (o == null || getClass() != o.getClass()) {
60+
return false;
61+
}
62+
63+
EnumModel enumModel = (EnumModel) o;
64+
return Objects.equals(value, enumModel.value) && Objects.equals(name, enumModel.name);
65+
}
66+
67+
@Override
68+
public int hashCode() {
69+
int result = Objects.hashCode(value);
70+
result = 31 * result + Objects.hashCode(name);
71+
return result;
72+
}
5273
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/MemberModel.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.squareup.javapoet.ClassName;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.Objects;
3132
import java.util.Optional;
3233
import software.amazon.awssdk.codegen.internal.TypeUtils;
3334
import software.amazon.awssdk.codegen.model.service.ContextParam;
@@ -785,4 +786,98 @@ public void ignoreDataTypeConversionFailures(boolean ignoreDataTypeConversionFai
785786
public boolean ignoreDataTypeConversionFailures() {
786787
return ignoreDataTypeConversionFailures;
787788
}
789+
790+
@Override
791+
public boolean equals(Object o) {
792+
if (o == null || getClass() != o.getClass()) {
793+
return false;
794+
}
795+
if (!super.equals(o)) {
796+
return false;
797+
}
798+
799+
MemberModel that = (MemberModel) o;
800+
return deprecated == that.deprecated
801+
&& required == that.required
802+
&& synthetic == that.synthetic
803+
&& idempotencyToken == that.idempotencyToken
804+
&& isJsonValue == that.isJsonValue
805+
&& eventPayload == that.eventPayload
806+
&& eventHeader == that.eventHeader
807+
&& endpointDiscoveryId == that.endpointDiscoveryId
808+
&& sensitive == that.sensitive
809+
&& xmlAttribute == that.xmlAttribute
810+
&& ignoreDataTypeConversionFailures == that.ignoreDataTypeConversionFailures
811+
&& Objects.equals(name, that.name)
812+
&& Objects.equals(c2jName, that.c2jName)
813+
&& Objects.equals(c2jShape, that.c2jShape)
814+
&& Objects.equals(variable, that.variable)
815+
&& Objects.equals(setterModel, that.setterModel)
816+
&& Objects.equals(getterModel, that.getterModel)
817+
&& Objects.equals(http, that.http)
818+
&& Objects.equals(deprecatedMessage, that.deprecatedMessage)
819+
&& Objects.equals(listModel, that.listModel)
820+
&& Objects.equals(mapModel, that.mapModel)
821+
&& Objects.equals(enumType, that.enumType)
822+
&& Objects.equals(xmlNameSpaceUri, that.xmlNameSpaceUri)
823+
&& Objects.equals(shape, that.shape)
824+
&& Objects.equals(fluentGetterMethodName, that.fluentGetterMethodName)
825+
&& Objects.equals(fluentEnumGetterMethodName, that.fluentEnumGetterMethodName)
826+
&& Objects.equals(fluentSetterMethodName, that.fluentSetterMethodName)
827+
&& Objects.equals(fluentEnumSetterMethodName, that.fluentEnumSetterMethodName)
828+
&& Objects.equals(existenceCheckMethodName, that.existenceCheckMethodName)
829+
&& Objects.equals(beanStyleGetterName, that.beanStyleGetterName)
830+
&& Objects.equals(beanStyleSetterName, that.beanStyleSetterName)
831+
&& Objects.equals(unionEnumTypeName, that.unionEnumTypeName)
832+
&& Objects.equals(timestampFormat, that.timestampFormat)
833+
&& Objects.equals(deprecatedName, that.deprecatedName)
834+
&& Objects.equals(fluentDeprecatedGetterMethodName, that.fluentDeprecatedGetterMethodName)
835+
&& Objects.equals(fluentDeprecatedSetterMethodName, that.fluentDeprecatedSetterMethodName)
836+
&& Objects.equals(deprecatedBeanStyleSetterMethodName, that.deprecatedBeanStyleSetterMethodName)
837+
&& Objects.equals(contextParam, that.contextParam);
838+
}
839+
840+
@Override
841+
public int hashCode() {
842+
int result = super.hashCode();
843+
result = 31 * result + Objects.hashCode(name);
844+
result = 31 * result + Objects.hashCode(c2jName);
845+
result = 31 * result + Objects.hashCode(c2jShape);
846+
result = 31 * result + Objects.hashCode(variable);
847+
result = 31 * result + Objects.hashCode(setterModel);
848+
result = 31 * result + Objects.hashCode(getterModel);
849+
result = 31 * result + Objects.hashCode(http);
850+
result = 31 * result + Boolean.hashCode(deprecated);
851+
result = 31 * result + Objects.hashCode(deprecatedMessage);
852+
result = 31 * result + Boolean.hashCode(required);
853+
result = 31 * result + Boolean.hashCode(synthetic);
854+
result = 31 * result + Objects.hashCode(listModel);
855+
result = 31 * result + Objects.hashCode(mapModel);
856+
result = 31 * result + Objects.hashCode(enumType);
857+
result = 31 * result + Objects.hashCode(xmlNameSpaceUri);
858+
result = 31 * result + Boolean.hashCode(idempotencyToken);
859+
result = 31 * result + Objects.hashCode(shape);
860+
result = 31 * result + Objects.hashCode(fluentGetterMethodName);
861+
result = 31 * result + Objects.hashCode(fluentEnumGetterMethodName);
862+
result = 31 * result + Objects.hashCode(fluentSetterMethodName);
863+
result = 31 * result + Objects.hashCode(fluentEnumSetterMethodName);
864+
result = 31 * result + Objects.hashCode(existenceCheckMethodName);
865+
result = 31 * result + Objects.hashCode(beanStyleGetterName);
866+
result = 31 * result + Objects.hashCode(beanStyleSetterName);
867+
result = 31 * result + Objects.hashCode(unionEnumTypeName);
868+
result = 31 * result + Boolean.hashCode(isJsonValue);
869+
result = 31 * result + Objects.hashCode(timestampFormat);
870+
result = 31 * result + Boolean.hashCode(eventPayload);
871+
result = 31 * result + Boolean.hashCode(eventHeader);
872+
result = 31 * result + Boolean.hashCode(endpointDiscoveryId);
873+
result = 31 * result + Boolean.hashCode(sensitive);
874+
result = 31 * result + Boolean.hashCode(xmlAttribute);
875+
result = 31 * result + Objects.hashCode(deprecatedName);
876+
result = 31 * result + Objects.hashCode(fluentDeprecatedGetterMethodName);
877+
result = 31 * result + Objects.hashCode(fluentDeprecatedSetterMethodName);
878+
result = 31 * result + Objects.hashCode(deprecatedBeanStyleSetterMethodName);
879+
result = 31 * result + Objects.hashCode(contextParam);
880+
result = 31 * result + Boolean.hashCode(ignoreDataTypeConversionFailures);
881+
return result;
882+
}
788883
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/intermediate/OperationModel.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.ArrayList;
2020
import java.util.List;
2121
import java.util.Map;
22+
import java.util.Objects;
2223
import software.amazon.awssdk.codegen.checksum.HttpChecksum;
2324
import software.amazon.awssdk.codegen.compression.RequestCompression;
2425
import software.amazon.awssdk.codegen.docs.ClientType;
@@ -379,4 +380,63 @@ public boolean isUnsignedPayload() {
379380
public void setUnsignedPayload(boolean unsignedPayload) {
380381
this.unsignedPayload = unsignedPayload;
381382
}
383+
384+
@Override
385+
public boolean equals(Object o) {
386+
if (o == null || getClass() != o.getClass()) {
387+
return false;
388+
}
389+
if (!super.equals(o)) {
390+
return false;
391+
}
392+
393+
OperationModel that = (OperationModel) o;
394+
return deprecated == that.deprecated && hasBlobMemberAsPayload == that.hasBlobMemberAsPayload
395+
&& hasStringMemberAsPayload == that.hasStringMemberAsPayload && isAuthenticated == that.isAuthenticated
396+
&& isPaginated == that.isPaginated && endpointOperation == that.endpointOperation
397+
&& endpointCacheRequired == that.endpointCacheRequired && httpChecksumRequired == that.httpChecksumRequired
398+
&& unsignedPayload == that.unsignedPayload && Objects.equals(operationName, that.operationName)
399+
&& Objects.equals(serviceProtocol, that.serviceProtocol)
400+
&& Objects.equals(deprecatedMessage, that.deprecatedMessage) && Objects.equals(input, that.input)
401+
&& Objects.equals(returnType, that.returnType) && Objects.equals(exceptions, that.exceptions)
402+
&& Objects.equals(simpleMethods, that.simpleMethods) && authType == that.authType
403+
&& Objects.equals(auth, that.auth) && Objects.equals(endpointDiscovery, that.endpointDiscovery)
404+
&& Objects.equals(inputShape, that.inputShape) && Objects.equals(outputShape, that.outputShape)
405+
&& Objects.equals(endpointTrait, that.endpointTrait) && Objects.equals(httpChecksum, that.httpChecksum)
406+
&& Objects.equals(requestcompression, that.requestcompression)
407+
&& Objects.equals(staticContextParams, that.staticContextParams)
408+
&& Objects.equals(operationContextParams, that.operationContextParams);
409+
}
410+
411+
@Override
412+
public int hashCode() {
413+
int result = super.hashCode();
414+
result = 31 * result + Objects.hashCode(operationName);
415+
result = 31 * result + Objects.hashCode(serviceProtocol);
416+
result = 31 * result + Boolean.hashCode(deprecated);
417+
result = 31 * result + Objects.hashCode(deprecatedMessage);
418+
result = 31 * result + Objects.hashCode(input);
419+
result = 31 * result + Objects.hashCode(returnType);
420+
result = 31 * result + Objects.hashCode(exceptions);
421+
result = 31 * result + Objects.hashCode(simpleMethods);
422+
result = 31 * result + Boolean.hashCode(hasBlobMemberAsPayload);
423+
result = 31 * result + Boolean.hashCode(hasStringMemberAsPayload);
424+
result = 31 * result + Boolean.hashCode(isAuthenticated);
425+
result = 31 * result + Objects.hashCode(authType);
426+
result = 31 * result + Objects.hashCode(auth);
427+
result = 31 * result + Boolean.hashCode(isPaginated);
428+
result = 31 * result + Boolean.hashCode(endpointOperation);
429+
result = 31 * result + Boolean.hashCode(endpointCacheRequired);
430+
result = 31 * result + Objects.hashCode(endpointDiscovery);
431+
result = 31 * result + Objects.hashCode(inputShape);
432+
result = 31 * result + Objects.hashCode(outputShape);
433+
result = 31 * result + Objects.hashCode(endpointTrait);
434+
result = 31 * result + Boolean.hashCode(httpChecksumRequired);
435+
result = 31 * result + Objects.hashCode(httpChecksum);
436+
result = 31 * result + Objects.hashCode(requestcompression);
437+
result = 31 * result + Objects.hashCode(staticContextParams);
438+
result = 31 * result + Objects.hashCode(operationContextParams);
439+
result = 31 * result + Boolean.hashCode(unsignedPayload);
440+
return result;
441+
}
382442
}

0 commit comments

Comments
 (0)