Project : get_invalid_validation
Project_GetInvalidValidation.RdGet invalid JSON schema validation results for the child entities of a container entity.
Value
An object containing the validation response, all validation messages, and the validation exception details.
Note
This only checks the direct children of this entity. It does not check this entity itself, and it does not check grandchildren (entities nested two or more levels below this entity).
Examples
if (FALSE) { # \dontrun{
## Using this function
# Retrieving invalid validation results for a project. This example demonstrates
# how to get detailed invalid validation results for child entities within a container.
# Set the PROJECT_NAME variable to your project name.
library(synapser)
synLogin()
# Define Project and JSON schema info
PROJECT_NAME = "test_json_schema_project" # replace with your project name
FILE_PATH = "~/Sample.txt" # replace with your test file path
PROJECT_ID = synFindEntityId(name = PROJECT_NAME)
ORG_NAME = "UniqueOrg" # replace with your organization name
SCHEMA_NAME = "myTestSchema" # replace with your schema name
VERSION = "0.0.1"
SCHEMA_URI = sprintf("%s-%s-%s", ORG_NAME, SCHEMA_NAME, VERSION)
# Create the organization and JSON schema used in this example.
my_test_org = Organization(name = ORG_NAME) |> synStore()
schema_definition = list(
"$id" = "mySchema",
type = "object",
properties = list(
foo = list(type = "string"),
baz = list(type = "string", const = "example_value"),
bar = list(type = "integer")
),
required = list("foo")
)
test_schema = JSONSchema(name = SCHEMA_NAME, organization_name = ORG_NAME) |> synStore(
json_schema_options = StoreJSONSchemaOptions(schema_body = schema_definition, version = VERSION)
)
# Get the test project
test_project = Project(id = PROJECT_ID)
# Bind JSON schema to the project
bound_schema = test_project |> synBindSchema(
json_schema_uri = SCHEMA_URI,
enable_derived_annotations = TRUE
)
cat("Bound schema to project:\n")
bound_schema
# Create a file within the project with invalid annotations to generate invalid results
invalid_file1 = File(
path = FILE_PATH, # assumes you have something here or adjust path
parent_id = PROJECT_ID
)
invalid_file1$annotations = list(foo = 123, bar = "not_an_integer") # both invalid
invalid_file1 = invalid_file1 |> synStore()
cat("Created file with invalid annotations\n")
Sys.sleep(2) # Allow time for processing
# Get invalid validation results
# synGetInvalidValidation() returns a Python generator, wrapped as a
# GeneratorWrapper -- materialize it with as.list() before iterating,
# since R's for() can't drive a Python generator directly.
invalid_results = as.list(test_project |> synGetInvalidValidation())
cat("Invalid validation items found:\n")
for (child in invalid_results) {
cat(sprintf("Invalid validation item: %s\n", child))
}
} # }