Skip to content

fix #358 - correction of regex problem + tests + auto formatting #359

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 3 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix #358 - formatting code with fmt-maven-plugin
  • Loading branch information
David DE CARVALHO committed Mar 29, 2022
commit bccb97a41e506fbfa22603d5a0fb5ccd5e1ff4b6
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;
import io.swagger.v3.oas.models.Paths;
import io.swagger.v3.oas.models.parameters.Parameter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import io.swagger.v3.oas.models.parameters.Parameter;
import org.openapitools.openapidiff.core.model.Changed;
import org.openapitools.openapidiff.core.model.ChangedPaths;
import org.openapitools.openapidiff.core.model.DiffContext;
Expand Down Expand Up @@ -103,12 +103,10 @@ public static Paths valOrEmpty(Paths path) {
}

/**
*
* @param a a path form the open api spec
* @param b another path from the same open api spec
* @return <code>true</code> in case both paths are of the same method AND their templated parameters are of the same type;
* <code>false</code> otherwise
*
* @return <code>true</code> in case both paths are of the same method AND their templated
* parameters are of the same type; <code>false</code> otherwise
*/
private static boolean methodsAndParametersIntersect(PathItem a, PathItem b) {
Set<PathItem.HttpMethod> methodsA = a.readOperationsMap().keySet();
Expand All @@ -126,15 +124,18 @@ private static boolean methodsAndParametersIntersect(PathItem a, PathItem b) {
}

/**
*
* @param left parameters from the first compared method
* @param right parameters from the second compared method
* @return <code>true</code> in case each parameter pair is of the same type; <code>false</code> otherwise
* @return <code>true</code> in case each parameter pair is of the same type; <code>false</code>
* otherwise
*/
private static boolean parametersIntersect(List<Parameter> left, List<Parameter> right) {;
private static boolean parametersIntersect(List<Parameter> left, List<Parameter> right) {
;
int parametersSize = left.size();
long intersectedParameters = IntStream.range(0, left.size())
.filter(i -> left.get(i).getSchema().getType().equals(right.get(i).getSchema().getType()))
long intersectedParameters =
IntStream.range(0, left.size())
.filter(
i -> left.get(i).getSchema().getType().equals(right.get(i).getSchema().getType()))
.count();
return parametersSize == intersectedParameters;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.openapitools.openapidiff.core;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;
import static org.openapitools.openapidiff.core.TestUtils.assertOpenApiAreEquals;

import org.junit.jupiter.api.Test;

class ParametersOverloadingTest {

private final String OVERLOADED_PARAMETERS = "parameters_overloading.yaml";
private final String DUPLICATED_PARAMETER_TYPES = "parameters_overloading_2.yaml";
private final String OVERLOADED_PARAMETERS = "parameters_overloading.yaml";
private final String DUPLICATED_PARAMETER_TYPES = "parameters_overloading_2.yaml";

@Test
void testDiffWithOverloadedParameterTypes() {
assertDoesNotThrow(() -> OpenApiCompare.fromLocations(OVERLOADED_PARAMETERS, OVERLOADED_PARAMETERS));
assertOpenApiAreEquals(OVERLOADED_PARAMETERS, OVERLOADED_PARAMETERS);
}
@Test
void testDiffWithOverloadedParameterTypes() {
assertDoesNotThrow(
() -> OpenApiCompare.fromLocations(OVERLOADED_PARAMETERS, OVERLOADED_PARAMETERS));
assertOpenApiAreEquals(OVERLOADED_PARAMETERS, OVERLOADED_PARAMETERS);
}

@Test
void testDiffWithDuplicatedParameterTypes() {
assertThrows(
IllegalArgumentException.class,
() -> OpenApiCompare.fromLocations(DUPLICATED_PARAMETER_TYPES, DUPLICATED_PARAMETER_TYPES),
"Two path items have the same signature: /projects/{}");
}
}
@Test
void testDiffWithDuplicatedParameterTypes() {
assertThrows(
IllegalArgumentException.class,
() -> OpenApiCompare.fromLocations(DUPLICATED_PARAMETER_TYPES, DUPLICATED_PARAMETER_TYPES),
"Two path items have the same signature: /projects/{}");
}
}