All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deepoove.swagger.diff.compare.VendorExtensionDiff Maven / Gradle / Ivy

package com.deepoove.swagger.diff.compare;

import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.lang3.tuple.Pair;

import com.deepoove.swagger.diff.model.ChangedExtensionGroup;

import io.swagger.models.Info;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Response;
import io.swagger.models.Swagger;
import io.swagger.models.Tag;
import io.swagger.models.auth.SecuritySchemeDefinition;
import io.swagger.models.parameters.Parameter;

public class VendorExtensionDiff {

  private boolean withExts;

  public VendorExtensionDiff(boolean withExts) {
    this.withExts = withExts;
  }

  public ChangedExtensionGroup diff(Parameter left, Parameter right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(Operation left, Operation right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(Swagger left, Swagger right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(Info left, Info right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(Path left, Path right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(Response left, Response right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(Tag left , Tag right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  public ChangedExtensionGroup diff(SecuritySchemeDefinition left, SecuritySchemeDefinition right) {
    return diff(left.getVendorExtensions(), right.getVendorExtensions());
  }

  private ChangedExtensionGroup diff(Map oldExts, Map newExts) {
    ChangedExtensionGroup group = new ChangedExtensionGroup();
    if (withExts) {
      MapDiff mapDiff = MapDiff.diff(oldExts, newExts);
      group.setMissingVendorExtensions(mapDiff.getMissing());
      group.setChangedVendorExtensions(mapDiff.getChanged());
      group.setIncreasedVendorExtensions(mapDiff.getIncreased());
    }
    return group;
  }

  public ChangedExtensionGroup diffTagGroup(Map left, Map right) {
    MapDiff responseDiff = MapDiff.diff(left, right);
    ChangedExtensionGroup responseGroup = new ChangedExtensionGroup();
    for (Entry> entry : responseDiff.getChanged().entrySet()) {
      String code = entry.getKey();
      Tag oldVal = entry.getValue().getLeft();
      Tag newVal = entry.getValue().getRight();
      responseGroup.putSubGroup(code, diff(oldVal, newVal));
    }
    return responseGroup;
  }

  public ChangedExtensionGroup diffSecGroup(Map left, Map right) {
    MapDiff responseDiff = MapDiff.diff(left, right);
    ChangedExtensionGroup responseGroup = new ChangedExtensionGroup();
    for (Entry> entry : responseDiff.getChanged().entrySet()) {
      String code = entry.getKey();
      SecuritySchemeDefinition oldVal = entry.getValue().getLeft();
      SecuritySchemeDefinition newVal = entry.getValue().getRight();
      responseGroup.putSubGroup(code, diff(oldVal, newVal));
    }
    return responseGroup;
  }

  public ChangedExtensionGroup diffResGroup(Map left, Map right) {
    MapDiff responseDiff = MapDiff.diff(left, right);
    ChangedExtensionGroup responseGroup = new ChangedExtensionGroup();
    for (Entry> entry : responseDiff.getChanged().entrySet()) {
      String code = entry.getKey();
      Response oldVal = entry.getValue().getLeft();
      Response newVal = entry.getValue().getRight();
      responseGroup.putSubGroup(code, diff(oldVal, newVal));
    }
    return responseGroup;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy