Created
July 1, 2014 00:49
-
-
Save geoffreywiseman/dacb08ad59d82a04ed0b to your computer and use it in GitHub Desktop.
Uber-Simple Use of the RAML Parser as a Validator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.raml; | |
import java.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.InputStream; | |
import java.util.List; | |
import org.raml.parser.rule.ValidationResult; | |
import org.raml.parser.visitor.RamlValidationService; | |
public class Validator { | |
public static void main(String[] arguments) throws FileNotFoundException { | |
File file = new File( | |
"/path/to/myramlfile.raml"); | |
InputStream stream = new FileInputStream(file); | |
List<ValidationResult> results = RamlValidationService.createDefault() | |
.validate(stream); | |
System.out.println("Validation Results:"); | |
for (ValidationResult item : results) { | |
printResult(item); | |
} | |
} | |
private static void printResult(ValidationResult item) { | |
StringBuilder stringBuilder = new StringBuilder(); | |
stringBuilder.append("\t"); | |
stringBuilder.append(item.getLevel()); | |
stringBuilder.append(" "); | |
stringBuilder.append(item.getMessage()); | |
stringBuilder.append(" (line "); | |
stringBuilder.append(item.getLine()); | |
if (item.getStartColumn() != -1) { | |
stringBuilder.append(", col "); | |
stringBuilder.append(item.getStartColumn()); | |
if (item.getEndColumn() != item.getStartColumn()) { | |
stringBuilder.append(" to "); | |
stringBuilder.append(item.getEndColumn()); | |
} | |
stringBuilder.append(")"); | |
System.out.println(stringBuilder.toString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously one of the first things one might like to do with this is feed the path to the RAML file in from the command-line arguments, which is an easy mod, but one I didn't yet make.