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 28, 2018
1 parent 4333043 commit b3ab3b2
Showing 1 changed file with 21 additions and 2 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,30 @@ case class LintCommand(inputDir: File, skipWarnings: Boolean, severityLevel: Sev
*/
def process(): Unit = {
val jsons = getJsonFilesStream(inputDir, Some(filterJsonSchemas))

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)
// strip GenerateCommand related parts off & prepare LintCommand failure messages
val lintSchemaVerMessages =
schemaVerWarnings.messages.map(m => "FAILURE" + m.stripPrefix("Warning")) :::
schemaVerErrors.messages.map(m => "FAILURE" + m.stripPrefix("Error").stripSuffix(" Use --force to switch off schema version check."))

lintSchemaVerMessages.foreach(println)

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, lintSchemaVerMessages.size))((acc, cur) => acc.add(cur)).exit()
}

/**
Expand Down

0 comments on commit b3ab3b2

Please sign in to comment.