Skip to content

Commit

Permalink
Schema DDL: add linter for missing schema versions (close #307)
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanunlu committed Jan 18, 2018
1 parent 6e220e2 commit bb36586
Showing 1 changed file with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import com.snowplowanalytics.iglu.schemaddl.jsonschema.json4s.Json4sToSchema._

// This library
import FileUtils.{ getJsonFilesStream, JsonFile, filterJsonSchemas }
import Utils.extractSchema
import Utils.{ extractSchema, splitValidations }

case class LintCommand(inputDir: File, skipWarnings: Boolean, severityLevel: SeverityLevel) extends Command.CtlCommand {
import LintCommand._
Expand All @@ -46,11 +46,38 @@ case class LintCommand(inputDir: File, skipWarnings: Boolean, severityLevel: Sev
*/
def process(): Unit = {
val jsons = getJsonFilesStream(inputDir, Some(filterJsonSchemas))
val reports = jsons.map { file =>
val report = file.map(check)
flattenReport(report)

val (failures, validatedJsons) = splitValidations(jsons.toList)
if (failures.nonEmpty) {
println("JSON Parsing errors:")
println(failures.mkString("\n"))
}

// lint schema versions
val stubFile: File = new File(inputDir.getAbsolutePath)
val stubCommand = GenerateCommand(stubFile, stubFile)
val (_, schemas) = splitValidations(validatedJsons.map(_.extractSelfDescribingSchema))
val (schemaVerWarnings, schemaVerErrors) = stubCommand.validateSchemaVersions(schemas)
val lintSchemaVer: Boolean = (schemaVerWarnings, schemaVerErrors) match {
case (Nil, Nil) => true
case (warnings, Nil) =>
println(warnings.mkString("\n"))
true
case (Nil, errors) =>
println(errors.mkString("\n"))
false
case (List(_), List(_)) => true
}

if (!lintSchemaVer) {
sys.exit(1)
} else {
val reports = jsons.map { file =>
val report = file.map(check)
flattenReport(report)
}
reports.foldLeft(Total(0, 0, 0))((acc, cur) => acc.add(cur)).exit()
}
reports.foldLeft(Total(0, 0, 0))((acc, cur) => acc.add(cur)).exit()
}

/**
Expand Down

0 comments on commit bb36586

Please sign in to comment.