Skip to content

Add SharedModelsValidator #6146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/feature-AWSSDKforJavav2-f004fae.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "feature",
"category": "AWS SDK for Java v2",
"contributor": "",
"description": "Add support for validating that shared models between two services are identical."
}
5 changes: 5 additions & 0 deletions codegen/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,10 @@
<artifactId>mockito-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@
import software.amazon.awssdk.codegen.validation.ModelValidationContext;
import software.amazon.awssdk.codegen.validation.ModelValidationReport;
import software.amazon.awssdk.codegen.validation.ModelValidator;
import software.amazon.awssdk.codegen.validation.SharedModelsValidator;
import software.amazon.awssdk.codegen.validation.ValidationEntry;
import software.amazon.awssdk.utils.Logger;

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

// TODO: add validators
private static final List<ModelValidator> DEFAULT_MODEL_VALIDATORS = Collections.emptyList();
private static final List<ModelValidator> DEFAULT_MODEL_VALIDATORS = Collections.singletonList(
new SharedModelsValidator()
);

private final C2jModels c2jModels;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

import java.util.Objects;

public class ArgumentModel extends DocumentationModel {

private String name;
Expand Down Expand Up @@ -61,4 +63,28 @@ public ArgumentModel withIsEnumArg(boolean isEnumArg) {
this.isEnumArg = isEnumArg;
return this;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}

ArgumentModel that = (ArgumentModel) o;
return isEnumArg == that.isEnumArg
&& Objects.equals(name, that.name)
&& Objects.equals(type, that.type);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Objects.hashCode(name);
result = 31 * result + Objects.hashCode(type);
result = 31 * result + Boolean.hashCode(isEnumArg);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.amazon.awssdk.codegen.model.intermediate;

import com.fasterxml.jackson.annotation.JsonIgnore;
import java.util.Objects;
import software.amazon.awssdk.codegen.model.service.Location;

public class AuthorizerModel extends DocumentationModel {
Expand Down Expand Up @@ -63,4 +64,30 @@ public String getAddAuthTokenMethod() {
authTokenLocation));
}
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}

AuthorizerModel that = (AuthorizerModel) o;
return Objects.equals(name, that.name)
&& Objects.equals(interfaceName, that.interfaceName)
&& authTokenLocation == that.authTokenLocation
&& Objects.equals(tokenName, that.tokenName);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Objects.hashCode(name);
result = 31 * result + Objects.hashCode(interfaceName);
result = 31 * result + Objects.hashCode(authTokenLocation);
result = 31 * result + Objects.hashCode(tokenName);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

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

import java.util.Objects;

public class DocumentationModel {

protected String documentation;
Expand All @@ -28,4 +30,22 @@ public String getDocumentation() {
public void setDocumentation(String documentation) {
this.documentation = escapeIllegalCharacters(documentation);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

DocumentationModel that = (DocumentationModel) o;
return Objects.equals(documentation, that.documentation);
}

@Override
public int hashCode() {
return Objects.hashCode(documentation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,22 @@ public boolean isRequired() {
public void setRequired(boolean required) {
this.required = required;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

EndpointDiscovery that = (EndpointDiscovery) o;
return required == that.required;
}

@Override
public int hashCode() {
return Boolean.hashCode(required);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

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

import java.util.Objects;

/**
* Represents a single enum field in a enum.
*/
Expand Down Expand Up @@ -49,4 +51,23 @@ public String getValue() {
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

EnumModel enumModel = (EnumModel) o;
return Objects.equals(value, enumModel.value) && Objects.equals(name, enumModel.name);
}

@Override
public int hashCode() {
int result = Objects.hashCode(value);
result = 31 * result + Objects.hashCode(name);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.squareup.javapoet.ClassName;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import software.amazon.awssdk.codegen.internal.TypeUtils;
import software.amazon.awssdk.codegen.model.service.ContextParam;
Expand Down Expand Up @@ -785,4 +786,98 @@ public void ignoreDataTypeConversionFailures(boolean ignoreDataTypeConversionFai
public boolean ignoreDataTypeConversionFailures() {
return ignoreDataTypeConversionFailures;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}

MemberModel that = (MemberModel) o;
return deprecated == that.deprecated
&& required == that.required
&& synthetic == that.synthetic
&& idempotencyToken == that.idempotencyToken
&& isJsonValue == that.isJsonValue
&& eventPayload == that.eventPayload
&& eventHeader == that.eventHeader
&& endpointDiscoveryId == that.endpointDiscoveryId
&& sensitive == that.sensitive
&& xmlAttribute == that.xmlAttribute
&& ignoreDataTypeConversionFailures == that.ignoreDataTypeConversionFailures
&& Objects.equals(name, that.name)
&& Objects.equals(c2jName, that.c2jName)
&& Objects.equals(c2jShape, that.c2jShape)
&& Objects.equals(variable, that.variable)
&& Objects.equals(setterModel, that.setterModel)
&& Objects.equals(getterModel, that.getterModel)
&& Objects.equals(http, that.http)
&& Objects.equals(deprecatedMessage, that.deprecatedMessage)
&& Objects.equals(listModel, that.listModel)
&& Objects.equals(mapModel, that.mapModel)
&& Objects.equals(enumType, that.enumType)
&& Objects.equals(xmlNameSpaceUri, that.xmlNameSpaceUri)
&& Objects.equals(shape, that.shape)
&& Objects.equals(fluentGetterMethodName, that.fluentGetterMethodName)
&& Objects.equals(fluentEnumGetterMethodName, that.fluentEnumGetterMethodName)
&& Objects.equals(fluentSetterMethodName, that.fluentSetterMethodName)
&& Objects.equals(fluentEnumSetterMethodName, that.fluentEnumSetterMethodName)
&& Objects.equals(existenceCheckMethodName, that.existenceCheckMethodName)
&& Objects.equals(beanStyleGetterName, that.beanStyleGetterName)
&& Objects.equals(beanStyleSetterName, that.beanStyleSetterName)
&& Objects.equals(unionEnumTypeName, that.unionEnumTypeName)
&& Objects.equals(timestampFormat, that.timestampFormat)
&& Objects.equals(deprecatedName, that.deprecatedName)
&& Objects.equals(fluentDeprecatedGetterMethodName, that.fluentDeprecatedGetterMethodName)
&& Objects.equals(fluentDeprecatedSetterMethodName, that.fluentDeprecatedSetterMethodName)
&& Objects.equals(deprecatedBeanStyleSetterMethodName, that.deprecatedBeanStyleSetterMethodName)
&& Objects.equals(contextParam, that.contextParam);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Objects.hashCode(name);
result = 31 * result + Objects.hashCode(c2jName);
result = 31 * result + Objects.hashCode(c2jShape);
result = 31 * result + Objects.hashCode(variable);
result = 31 * result + Objects.hashCode(setterModel);
result = 31 * result + Objects.hashCode(getterModel);
result = 31 * result + Objects.hashCode(http);
result = 31 * result + Boolean.hashCode(deprecated);
result = 31 * result + Objects.hashCode(deprecatedMessage);
result = 31 * result + Boolean.hashCode(required);
result = 31 * result + Boolean.hashCode(synthetic);
result = 31 * result + Objects.hashCode(listModel);
result = 31 * result + Objects.hashCode(mapModel);
result = 31 * result + Objects.hashCode(enumType);
result = 31 * result + Objects.hashCode(xmlNameSpaceUri);
result = 31 * result + Boolean.hashCode(idempotencyToken);
result = 31 * result + Objects.hashCode(shape);
result = 31 * result + Objects.hashCode(fluentGetterMethodName);
result = 31 * result + Objects.hashCode(fluentEnumGetterMethodName);
result = 31 * result + Objects.hashCode(fluentSetterMethodName);
result = 31 * result + Objects.hashCode(fluentEnumSetterMethodName);
result = 31 * result + Objects.hashCode(existenceCheckMethodName);
result = 31 * result + Objects.hashCode(beanStyleGetterName);
result = 31 * result + Objects.hashCode(beanStyleSetterName);
result = 31 * result + Objects.hashCode(unionEnumTypeName);
result = 31 * result + Boolean.hashCode(isJsonValue);
result = 31 * result + Objects.hashCode(timestampFormat);
result = 31 * result + Boolean.hashCode(eventPayload);
result = 31 * result + Boolean.hashCode(eventHeader);
result = 31 * result + Boolean.hashCode(endpointDiscoveryId);
result = 31 * result + Boolean.hashCode(sensitive);
result = 31 * result + Boolean.hashCode(xmlAttribute);
result = 31 * result + Objects.hashCode(deprecatedName);
result = 31 * result + Objects.hashCode(fluentDeprecatedGetterMethodName);
result = 31 * result + Objects.hashCode(fluentDeprecatedSetterMethodName);
result = 31 * result + Objects.hashCode(deprecatedBeanStyleSetterMethodName);
result = 31 * result + Objects.hashCode(contextParam);
result = 31 * result + Boolean.hashCode(ignoreDataTypeConversionFailures);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import software.amazon.awssdk.codegen.checksum.HttpChecksum;
import software.amazon.awssdk.codegen.compression.RequestCompression;
import software.amazon.awssdk.codegen.docs.ClientType;
Expand Down Expand Up @@ -379,4 +380,63 @@ public boolean isUnsignedPayload() {
public void setUnsignedPayload(boolean unsignedPayload) {
this.unsignedPayload = unsignedPayload;
}

@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
if (!super.equals(o)) {
return false;
}

OperationModel that = (OperationModel) o;
return deprecated == that.deprecated && hasBlobMemberAsPayload == that.hasBlobMemberAsPayload
&& hasStringMemberAsPayload == that.hasStringMemberAsPayload && isAuthenticated == that.isAuthenticated
&& isPaginated == that.isPaginated && endpointOperation == that.endpointOperation
&& endpointCacheRequired == that.endpointCacheRequired && httpChecksumRequired == that.httpChecksumRequired
&& unsignedPayload == that.unsignedPayload && Objects.equals(operationName, that.operationName)
&& Objects.equals(serviceProtocol, that.serviceProtocol)
&& Objects.equals(deprecatedMessage, that.deprecatedMessage) && Objects.equals(input, that.input)
&& Objects.equals(returnType, that.returnType) && Objects.equals(exceptions, that.exceptions)
&& Objects.equals(simpleMethods, that.simpleMethods) && authType == that.authType
&& Objects.equals(auth, that.auth) && Objects.equals(endpointDiscovery, that.endpointDiscovery)
&& Objects.equals(inputShape, that.inputShape) && Objects.equals(outputShape, that.outputShape)
&& Objects.equals(endpointTrait, that.endpointTrait) && Objects.equals(httpChecksum, that.httpChecksum)
&& Objects.equals(requestcompression, that.requestcompression)
&& Objects.equals(staticContextParams, that.staticContextParams)
&& Objects.equals(operationContextParams, that.operationContextParams);
}

@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + Objects.hashCode(operationName);
result = 31 * result + Objects.hashCode(serviceProtocol);
result = 31 * result + Boolean.hashCode(deprecated);
result = 31 * result + Objects.hashCode(deprecatedMessage);
result = 31 * result + Objects.hashCode(input);
result = 31 * result + Objects.hashCode(returnType);
result = 31 * result + Objects.hashCode(exceptions);
result = 31 * result + Objects.hashCode(simpleMethods);
result = 31 * result + Boolean.hashCode(hasBlobMemberAsPayload);
result = 31 * result + Boolean.hashCode(hasStringMemberAsPayload);
result = 31 * result + Boolean.hashCode(isAuthenticated);
result = 31 * result + Objects.hashCode(authType);
result = 31 * result + Objects.hashCode(auth);
result = 31 * result + Boolean.hashCode(isPaginated);
result = 31 * result + Boolean.hashCode(endpointOperation);
result = 31 * result + Boolean.hashCode(endpointCacheRequired);
result = 31 * result + Objects.hashCode(endpointDiscovery);
result = 31 * result + Objects.hashCode(inputShape);
result = 31 * result + Objects.hashCode(outputShape);
result = 31 * result + Objects.hashCode(endpointTrait);
result = 31 * result + Boolean.hashCode(httpChecksumRequired);
result = 31 * result + Objects.hashCode(httpChecksum);
result = 31 * result + Objects.hashCode(requestcompression);
result = 31 * result + Objects.hashCode(staticContextParams);
result = 31 * result + Objects.hashCode(operationContextParams);
result = 31 * result + Boolean.hashCode(unsignedPayload);
return result;
}
}
Loading
Loading