Skip to content

Commit

Permalink
Merge pull request #96 from viclovsky/revert-94-tagBasedFilter
Browse files Browse the repository at this point in the history
Revert "Ability to filter APIs from coverage calculation based on tags"
  • Loading branch information
viclovsky authored Dec 7, 2021
2 parents 0bf5949 + 510cbe8 commit dc08b30
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 205 deletions.
30 changes: 0 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,36 +182,6 @@ By default, this rule is not enabled. Add it to the config file with *true* valu
}
````

#### Including/Excluding tag coverage report statistic

This rule is created for cases when you want to measure coverage of operations having only particular tag(s) or you want to exclude operations having particular tag(s).
The whole httpMethod(and all related operations) is excluded in the coverage measurement if a related tag is present in ignore.

You can setup next options:

**enable** - *true/false*. You can disable this rule. Default value is *true*.

**filter** - *[val1,val2]*. Rule will ignore all methods, which do not have tag in filter list.

**ignore** - *[val1,val2]*. Rule will ignore all methods, which have tag in ignore list.

````
{
"rules" : {
....
"filterAllByTag": {
"enable": true,
"ignore": ["Exclude"]
},
....
},
....
}
````

If you need you can add your rules for generation of conditions. So, please, send your PRs.

## Result writer configuration
Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ configure(subprojects) {

tasks.withType(Javadoc::class) {
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
options.encoding = "UTF-8"
}

tasks.withType<GenerateModuleMetadata> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.github.viclovsky.swagger.coverage.core.rule.parameter.NotOnlyEnumValuesRule;
import com.github.viclovsky.swagger.coverage.core.rule.status.HTTPStatusRule;
import com.github.viclovsky.swagger.coverage.core.rule.status.OnlyDeclaredHTTPStatusesRule;
import com.github.viclovsky.swagger.coverage.core.rule.tag.FilterAllByTagRule;
import com.github.viclovsky.swagger.coverage.core.writer.CoverageResultsWriter;
import com.github.viclovsky.swagger.coverage.core.writer.FileSystemResultsWriter;
import com.github.viclovsky.swagger.coverage.core.writer.HtmlReportResultsWriter;
Expand Down Expand Up @@ -94,7 +93,6 @@ private static List<CoverageResultsWriter> getResultsWriters(ConfigurationOption
private static List<ConditionRule> getDefaultList() {
List<ConditionRule> registeredRules = new ArrayList<>();

registeredRules.add(new FilterAllByTagRule());
registeredRules.add(new HTTPStatusRule());
registeredRules.add(new NotEmptyParameterRule());
registeredRules.add(new EnumAllValuesRule());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.github.viclovsky.swagger.coverage.core.model.OperationKey;
import com.github.viclovsky.swagger.coverage.core.model.OperationsHolder;
import com.github.viclovsky.swagger.coverage.core.rule.core.ConditionRule;
import com.github.viclovsky.swagger.coverage.core.rule.tag.FilterAllByTagRule;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
import org.slf4j.Logger;
Expand All @@ -22,8 +21,7 @@ public class OperationConditionGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(OperationConditionGenerator.class);

public static Map<OperationKey, ConditionOperationCoverage> getOperationMap(OpenAPI swagger, List<ConditionRule> rules) {
OperationsHolder operations = filterByTags(SwaggerSpecificationProcessor.extractOperation(swagger), rules);

OperationsHolder operations = SwaggerSpecificationProcessor.extractOperation(swagger);
Map<OperationKey, ConditionOperationCoverage> coverage = new TreeMap<>();

operations.getOperations().forEach((key, value) -> {
Expand Down Expand Up @@ -54,30 +52,4 @@ private static List<Condition> generateConditionList(Operation operation, List<C
LOGGER.debug(String.format("created list is %s", conditions));
return conditions;
}

private static OperationsHolder filterByTags(OperationsHolder operations, List<ConditionRule> rules) {
List<ConditionRule> tagRules = rules.stream()
.filter(rule -> rule.getClass().equals(FilterAllByTagRule.class))
.collect(Collectors.toList());
if (tagRules.size() == 0) {
return operations;
}

FilterAllByTagRule rule = (FilterAllByTagRule) tagRules.get(0);
if (!rule.isRuleEnabled()) {
return operations;
}

OperationsHolder result = new OperationsHolder();
for (Map.Entry<OperationKey, Operation> entry : operations.getOperations().entrySet()) {
Operation operation = entry.getValue();
List<Condition> conditions = rule.createCondition(operation);
if (conditions != null && !conditions.isEmpty()) {
result.addOperation(entry.getKey(), operation);
}
}

return result;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,4 @@ public ConditionRule configure(RuleConfigurationOptions options) {
this.options = options;
return this;
}

protected final boolean includesEnabled() {
return options != null && options.getFilter() != null && !options.getFilter().isEmpty();
}

protected final boolean excludesEnabled() {
return options != null && options.getIgnore() != null && !options.getIgnore().isEmpty();
}

protected final boolean isIncluded(String val) {
return includesEnabled() && options.getFilter().contains(val);
}

protected final boolean isExcluded(String val) {
return excludesEnabled() && options.getIgnore().contains(val);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@
},
"exclude-deprecated" : {
"enable" : true
},
"filterAllByTag": {
"enable": true,
"filter": [],
"ignore": ["Exclude"]
}
},
"writers": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
<table class="table table-sm">
<thead>
<tr>
<th scope="col">${i18["details.condition.conditionname"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}e</th>
<th scope="col">${i18["details.condition.details"]}</th>
</tr>
</thead>
Expand All @@ -107,7 +107,7 @@
<thead>
<tr>
<th scope="col">${i18["details.condition.operation"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}e</th>
<th scope="col">${i18["details.condition.details"]}</th>
</tr>
</thead>
Expand Down
2 changes: 0 additions & 2 deletions swagger-coverage-commons/src/main/resources/message.en
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,3 @@ predicate.PropertyValueConditionPredicate.name = All property values
predicate.PropertyValueConditionPredicate.description = Verification that the method is called with all properties described in the enum
predicate.PropertyValueNotOnlyConditionPredicate.name = Values not only from the list
predicate.PropertyValueNotOnlyConditionPredicate.description = Verify that the method was called with a value that is not described in the property enum
predicate.DefaultTagConditionPredicate.name= Filter on tags
predicate.DefaultTagConditionPredicate.description= Verify that the method has tag available or unavailable depending on configuration
4 changes: 1 addition & 3 deletions swagger-coverage-commons/src/main/resources/message.ru
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,4 @@ predicate.DefaultPropertyConditionPredicate.description=Проверка, что
predicate.PropertyValueConditionPredicate.name=Все значения проперти
predicate.PropertyValueConditionPredicate.description=Проверка, что метод вызван со всеми описанным в enum проперти
predicate.PropertyValueNotOnlyConditionPredicate.name=Значения не только из списка
predicate.PropertyValueNotOnlyConditionPredicate.description=Проверка, что метод вызывался со значением, которое не описано в enum проперти
predicate.DefaultTagConditionPredicate.name= Фильтр по тегам
predicate.DefaultTagConditionPredicate.description= Убедитесь, что у метода есть тег, доступный или недоступный в зависимости от конфигурации.
predicate.PropertyValueNotOnlyConditionPredicate.description=Проверка, что метод вызывался со значением, которое не описано в enum проперти
4 changes: 2 additions & 2 deletions swagger-coverage-commons/src/main/resources/report.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
<thead>
<tr>
<th scope="col">${i18["details.condition.operation"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}e</th>
<th scope="col">${i18["details.condition.details"]}</th>
</tr>
</thead>
Expand All @@ -264,7 +264,7 @@
<thead>
<tr>
<th scope="col">${i18["details.condition.operation"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}</th>
<th scope="col">${i18["details.condition.conditionname"]}e</th>
<th scope="col">${i18["details.condition.details"]}</th>
</tr>
</thead>
Expand Down

0 comments on commit dc08b30

Please sign in to comment.