Skip to content
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

[NF] add path params extraction from AntPathMatcher and mimick them… #148

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.github.viclovsky.swagger.coverage.core.rule.core.ConditionRule;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.parameters.PathParameter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.AntPathMatcher;
Expand All @@ -24,6 +25,7 @@
import java.util.Optional;
import java.util.TreeMap;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class CoverageStatisticsBuilder extends StatisticsPreBuilder {
private static final Logger LOGGER = LoggerFactory.getLogger(CoverageStatisticsBuilder.class);
Expand All @@ -49,6 +51,22 @@ public CoverageStatisticsBuilder add(OpenAPI swagger) {
.filter(equalsOperationKeys(key)).findFirst();

if (keyOptional.isPresent()) {
// Recreate path parameters if framework can't parse path parameters to value
Map<String, String> extractedPathParams = new AntPathMatcher()
.extractUriTemplateVariables(keyOptional.get().getPath(), key.getPath());
if (!extractedPathParams.isEmpty()) {
List<String> existedPathParametersNames = value.getParameters().stream()
.filter(parameter -> parameter.getIn().equals("path"))
.map(parameter -> parameter.getName())
.collect(Collectors.toList());
extractedPathParams.forEach((n, v) -> {
if (!existedPathParametersNames.contains(n)) {
value.addParametersItem(new PathParameter().name(n).example(v));
LOGGER.info(String.format("== result [%s] was also mimicked by absent path param with [name=%s, example=%s]", key, n, v));
}
});
}

mainCoverageData.get(keyOptional.get())
.increaseProcessCount()
.getConditions()
Expand Down