forked from usnistgov/OSCAL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from david-waltermire-nist/wendell-json-validation
Fixed JSON Validation
- Loading branch information
Showing
18 changed files
with
272 additions
and
38 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
if [[ -z "$OSCALDIR" ]]; then | ||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" | ||
source "$DIR/common-environment.sh" | ||
fi | ||
|
||
if [[ -z "$JSON_CLI_HOME" ]]; then | ||
if [[ -z "$JSON_CLI_VERSION" ]]; then | ||
echo "${P_ERROR}JSON_CLI_VERSION is not set or is empty.${P_END} ${P_INFO}Please set JSON_CLI_VERSION to indicate the library version${P_END}" | ||
fi | ||
JSON_CLI_HOME=~/.m2/repository/gov/nist/oscal/json-cli/${JSON_CLI_VERSION} | ||
fi | ||
|
||
# ( set -o posix ; set ) | ||
|
||
validate_json() { | ||
local json_schema="$1"; shift | ||
local json_file="$1"; shift | ||
local extra_params=($@) | ||
|
||
local classpath=$(JARS=("$JSON_CLI_HOME"/*.jar); IFS=:; echo "${JARS[*]}") | ||
|
||
set -- | ||
|
||
if [ -z "$json_schema" ]; then | ||
echo "${P_ERROR}The JSON schema must be provided as the first argument.${P_END}" | ||
else | ||
set -- "$@" "-s" "${json_schema}" | ||
fi | ||
|
||
if [ -z "$json_file" ]; then | ||
echo "${P_ERROR}The JSON file must be provided as the second argument.${P_END}" | ||
else | ||
set -- "$@" "-v" "${json_file}" | ||
fi | ||
|
||
java -cp "$classpath" gov.nist.oscal.json.JsonCLI "$@" "${extra_params[@]}" | ||
|
||
if [ "$?" -ne 0 ]; then | ||
echo "${P_ERROR}Error running JsonCLI.${P_END}" | ||
return 3 | ||
fi | ||
return 0 | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$id": "http://json-schema.org/draft-07/schema#", | ||
"title": "Core schema meta-schema", | ||
"definitions": { | ||
"schemaArray": { | ||
"type": "array", | ||
"minItems": 1, | ||
"items": { "$ref": "#" } | ||
}, | ||
"nonNegativeInteger": { | ||
"type": "integer", | ||
"minimum": 0 | ||
}, | ||
"nonNegativeIntegerDefault0": { | ||
"allOf": [ | ||
{ "$ref": "#/definitions/nonNegativeInteger" }, | ||
{ "default": 0 } | ||
] | ||
}, | ||
"simpleTypes": { | ||
"enum": [ | ||
"array", | ||
"boolean", | ||
"integer", | ||
"null", | ||
"number", | ||
"object", | ||
"string" | ||
] | ||
}, | ||
"stringArray": { | ||
"type": "array", | ||
"items": { "type": "string" }, | ||
"uniqueItems": true, | ||
"default": [] | ||
} | ||
}, | ||
"type": ["object", "boolean"], | ||
"properties": { | ||
"$id": { | ||
"type": "string", | ||
"format": "uri-reference" | ||
}, | ||
"$schema": { | ||
"type": "string", | ||
"format": "uri" | ||
}, | ||
"$ref": { | ||
"type": "string", | ||
"format": "uri-reference" | ||
}, | ||
"$comment": { | ||
"type": "string" | ||
}, | ||
"title": { | ||
"type": "string" | ||
}, | ||
"description": { | ||
"type": "string" | ||
}, | ||
"default": true, | ||
"readOnly": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"examples": { | ||
"type": "array", | ||
"items": true | ||
}, | ||
"multipleOf": { | ||
"type": "number", | ||
"exclusiveMinimum": 0 | ||
}, | ||
"maximum": { | ||
"type": "number" | ||
}, | ||
"exclusiveMaximum": { | ||
"type": "number" | ||
}, | ||
"minimum": { | ||
"type": "number" | ||
}, | ||
"exclusiveMinimum": { | ||
"type": "number" | ||
}, | ||
"maxLength": { "$ref": "#/definitions/nonNegativeInteger" }, | ||
"minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, | ||
"pattern": { | ||
"type": "string", | ||
"format": "regex" | ||
}, | ||
"additionalItems": { "$ref": "#" }, | ||
"items": { | ||
"anyOf": [ | ||
{ "$ref": "#" }, | ||
{ "$ref": "#/definitions/schemaArray" } | ||
], | ||
"default": true | ||
}, | ||
"maxItems": { "$ref": "#/definitions/nonNegativeInteger" }, | ||
"minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, | ||
"uniqueItems": { | ||
"type": "boolean", | ||
"default": false | ||
}, | ||
"contains": { "$ref": "#" }, | ||
"maxProperties": { "$ref": "#/definitions/nonNegativeInteger" }, | ||
"minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" }, | ||
"required": { "$ref": "#/definitions/stringArray" }, | ||
"additionalProperties": { "$ref": "#" }, | ||
"definitions": { | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"default": {} | ||
}, | ||
"properties": { | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"default": {} | ||
}, | ||
"patternProperties": { | ||
"type": "object", | ||
"additionalProperties": { "$ref": "#" }, | ||
"propertyNames": { "format": "regex" }, | ||
"default": {} | ||
}, | ||
"dependencies": { | ||
"type": "object", | ||
"additionalProperties": { | ||
"anyOf": [ | ||
{ "$ref": "#" }, | ||
{ "$ref": "#/definitions/stringArray" } | ||
] | ||
} | ||
}, | ||
"propertyNames": { "$ref": "#" }, | ||
"const": true, | ||
"enum": { | ||
"type": "array", | ||
"items": true, | ||
"minItems": 1, | ||
"uniqueItems": true | ||
}, | ||
"type": { | ||
"anyOf": [ | ||
{ "$ref": "#/definitions/simpleTypes" }, | ||
{ | ||
"type": "array", | ||
"items": { "$ref": "#/definitions/simpleTypes" }, | ||
"minItems": 1, | ||
"uniqueItems": true | ||
} | ||
] | ||
}, | ||
"format": { "type": "string" }, | ||
"contentMediaType": { "type": "string" }, | ||
"contentEncoding": { "type": "string" }, | ||
"if": { "$ref": "#" }, | ||
"then": { "$ref": "#" }, | ||
"else": { "$ref": "#" }, | ||
"allOf": { "$ref": "#/definitions/schemaArray" }, | ||
"anyOf": { "$ref": "#/definitions/schemaArray" }, | ||
"oneOf": { "$ref": "#/definitions/schemaArray" }, | ||
"not": { "$ref": "#" } | ||
}, | ||
"default": true | ||
} |
Oops, something went wrong.