Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package io.apicurio.registry.rules.compatibility.protobuf;
import com.squareup.wire.Syntax;
import com.squareup.wire.schema.Field;
import com.squareup.wire.schema.internal.parser.EnumConstantElement;
import com.squareup.wire.schema.internal.parser.FieldElement;
import io.apicurio.registry.protobuf.ProtobufDifference;
import io.apicurio.registry.utils.protobuf.schema.ProtobufFile;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* Provides compatibility validation functions for changes between two versions of a Protobuf schema document.
*
* @see Protolock
*/
public class ProtobufCompatibilityCheckerLibrary {
// TODO https://github.com/square/wire/issues/797 RFE: capture EnumElement reserved info
private final ProtobufFile fileBefore;
private final ProtobufFile fileAfter;
public ProtobufCompatibilityCheckerLibrary(ProtobufFile fileBefore, ProtobufFile fileAfter) {
this.fileBefore = fileBefore;
this.fileAfter = fileAfter;
}
public boolean validate() {
return findDifferences().isEmpty();
}
public List findDifferences() {
List totalIssues = new ArrayList<>();
totalIssues.addAll(checkNoUsingReservedFields());
totalIssues.addAll(checkNoRemovingReservedFields());
totalIssues.addAll(checkNoRemovingFieldsWithoutReserve());
totalIssues.addAll(checkNoChangingFieldIDs());
totalIssues.addAll(checkNoChangingFieldTypes());
totalIssues.addAll(checkNoChangingFieldNames());
totalIssues.addAll(checkNoRemovingServiceRPCs());
totalIssues.addAll(checkNoChangingRPCSignature());
if (Syntax.PROTO_2.equals(fileBefore.getSyntax())) {
totalIssues.addAll(checkRequiredFields());
}
return totalIssues;
}
/**
* Determine if any message's previously reserved fields or IDs are now being used as part of the same
* message.
*
* Note: TODO can't currently validate enum reserved fields, as the parser doesn't capture those.
*
* @return differences list
*/
public List checkNoUsingReservedFields() {
List issues = new ArrayList<>();
Map> reservedFields = fileBefore.getReservedFields();
Map> nonReservedFields = fileAfter.getNonReservedFields();
for (Map.Entry> entry : nonReservedFields.entrySet()) {
Set