Skip to content

Commit

Permalink
Remove ability to ingore files from spec validation (elastic#56647)
Browse files Browse the repository at this point in the history
An ignore parameter was originally added to the ValidateJsonAgainstSchemaTask
to allow the build to pass for REST specs that did not properly validate
against the schema.

Since the introduction of this task, all schemas that did not validate have
been fixed to now validate properly.

This commit removes the ability to ignore specific files for validation. This
allows any consumers the assurance that all REST specs validate against the schema.
  • Loading branch information
jakelandis committed May 13, 2020
1 parent c76bb5d commit 969820c
Showing 1 changed file with 4 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import org.gradle.api.DefaultTask;
import org.gradle.api.UncheckedIOException;
import org.gradle.api.file.FileCollection;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.TaskAction;
import org.gradle.work.ChangeType;
Expand All @@ -42,9 +40,9 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
Expand All @@ -57,7 +55,6 @@
public class ValidateJsonAgainstSchemaTask extends DefaultTask {

private final ObjectMapper mapper = new ObjectMapper();
private Set<String> ignore = new HashSet<>();
private File jsonSchema;
private FileCollection inputFiles;

Expand All @@ -80,16 +77,6 @@ public void setJsonSchema(File jsonSchema) {
this.jsonSchema = jsonSchema;
}

@Input
@Optional
public Set<String> getIgnore() {
return ignore;
}

public void ignore(String... ignore) {
this.ignore.addAll(Arrays.asList(ignore));
}

@OutputFile
public File getReport() {
return new File(getProject().getBuildDir(), "reports/validateJson.txt");
Expand All @@ -108,9 +95,7 @@ public void validate(InputChanges inputChanges) throws IOException {
.filter(f -> f.getChangeType() != ChangeType.REMOVED)
.forEach(fileChange -> {
File file = fileChange.getFile();
if (ignore.contains(file.getName())) {
getLogger().debug("Ignoring file [{}] due to configuration", file.getName());
} else if (file.isDirectory() == false) {
if (file.isDirectory() == false) {
// validate all files and hold on to errors for a complete report if there are failures
getLogger().debug("Validating JSON [{}]", file.getName());
try {
Expand All @@ -122,9 +107,7 @@ public void validate(InputChanges inputChanges) throws IOException {
}
});
if (errors.isEmpty()) {
try (PrintWriter printWriter = new PrintWriter(getReport())) {
printWriter.println("Success! No validation errors found.");
}
Files.writeString(getReport().toPath(), "Success! No validation errors found.", StandardOpenOption.CREATE);
} else {
try (PrintWriter printWriter = new PrintWriter(getReport())) {
printWriter.printf("Schema: %s%n", jsonSchemaOnDisk);
Expand Down

0 comments on commit 969820c

Please sign in to comment.