io.redskap.swagger.brake.core.DefaultBreakChecker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of swagger-brake Show documentation
Show all versions of swagger-brake Show documentation
Swagger contract checker for breaking API changes
package io.redskap.swagger.brake.core;
import static java.util.stream.Collectors.toList;
import java.util.Collection;
import io.redskap.swagger.brake.core.model.Specification;
import io.redskap.swagger.brake.core.rule.BreakingChangeRule;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
@Component
@RequiredArgsConstructor
@Slf4j
public class DefaultBreakChecker implements BreakChecker {
private final Collection> rules;
@Override
public Collection check(Specification oldApi, Specification newApi) {
if (log.isDebugEnabled()) {
rules.stream().map(BreakingChangeRule::getClass).map(Class::getName).forEach(name -> log.debug("Rule configured: {}", name));
}
if (oldApi == null) {
throw new IllegalArgumentException("oldApi must be provided");
}
if (newApi == null) {
throw new IllegalArgumentException("newApi must be provided");
}
return rules.stream().map(rule -> rule.checkRule(oldApi, newApi)).flatMap(Collection::stream).collect(toList());
}
}