Skip to content

Commit

Permalink
[FIXED JENKINS-40793] Add location information to validation errors
Browse files Browse the repository at this point in the history
Specifically to the JSON output. This also moves us to not doing
conversion between JSONObject and JsonNode, which is nice. There's
probably some cleanup/optimization that could still be done in
JSONParser.
  • Loading branch information
abayer committed Jan 10, 2017
1 parent f1a0249 commit 0a9ba67
Show file tree
Hide file tree
Showing 18 changed files with 367 additions and 302 deletions.
Expand Up @@ -122,8 +122,10 @@ public String toGroovy() {
} else {
return "'''" + (str.replace("'''", "\\'\\'\\'")) + "'''";
}
} else {
} else if (getValue() != null) {
return getValue().toString();
} else {
return "";
}
}
};
Expand Down
Expand Up @@ -383,7 +383,4 @@ public class Utils {

return wrapper
}



}
Expand Up @@ -30,6 +30,9 @@ import com.fasterxml.jackson.datatype.jsonorg.JsonOrgModule
import com.github.fge.jsonschema.exceptions.ProcessingException
import com.github.fge.jsonschema.main.JsonSchema
import com.github.fge.jsonschema.report.ProcessingReport
import com.github.fge.jsonschema.tree.JsonTree
import com.github.fge.jsonschema.tree.SimpleJsonTree
import com.github.fge.jsonschema.util.JsonLoader
import net.sf.json.JSONObject
import org.apache.commons.lang.reflect.FieldUtils
import org.codehaus.groovy.control.CompilationFailedException
Expand Down Expand Up @@ -67,8 +70,10 @@ public class Converter {
* @throws ProcessingException If an error of high enough severity is detected in processing.
*/
public static ProcessingReport validateJSONAgainstSchema(JSONObject origJson) throws ProcessingException {
JsonNode jsonNode = jacksonJSONFromJSONObject(origJson);
return validateJSONAgainstSchema(jacksonJSONFromJSONObject(origJson))
}

public static ProcessingReport validateJSONAgainstSchema(JsonNode jsonNode) throws ProcessingException {
JsonSchema schema = ASTSchema.getJSONSchema();

return schema.validate(jsonNode)
Expand All @@ -87,6 +92,10 @@ public class Converter {
return mapper.valueToTree(input);
}

public static JsonTree jsonTreeFromJSONObject(JSONObject input) {
return new SimpleJsonTree(jacksonJSONFromJSONObject(input))
}

/**
* Converts a script at a given URL into {@link ModelASTPipelineDef}
*
Expand Down

0 comments on commit 0a9ba67

Please sign in to comment.