Skip to contents

Validate the entity against the bound JSON schema.

Usage

synValidateSchema(instance, synapse_client=NULL)

Arguments

instance

(EntityView) The EntityView instance to operate on.

synapse_client

(Optional[Synapse], optional) The Synapse client instance. If not provided, the last created instance from the Synapse class constructor will be used.

Value

The validation results.

Examples

if (FALSE) { # \dontrun{
## Using this function
    # Validating an EntityView against the bound JSON schema. This example demonstrates
    # how to validate an entity with annotations against its bound schema. Requires
    # the entity to have a schema already bound. 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

    PROJECT_ID = synFindEntityId(name = PROJECT_NAME)
    ORG_NAME = "UniqueOrg"  # replace with your organization name
    SCHEMA_NAME = "myTestSchema"  # replace with your schema name
    VIEW_NAME = "test_script_entityview"
    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"),
            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)
    )

    # Create a test EntityView of the files in the project
    test_view = EntityView(
        name = VIEW_NAME,
        parent_id = PROJECT_ID,
        scope_ids = list(PROJECT_ID),
        view_type_mask = 1L  # 1 = files
    ) |> synStore()
    cat("Created test EntityView:", VIEW_NAME, "\n")

    # Bind JSON schema to the EntityView
    bound_schema = test_view |> synBindSchema(
        json_schema_uri = SCHEMA_URI,
        enable_derived_annotations = TRUE
    )
    cat("Bound schema to EntityView:\n")
    bound_schema

    # Validate the EntityView against the bound schema
    test_view = test_view |> synSetProperties(
        annotations = list(foo = "test_value", bar = 42)  # Example annotations
    ) |> synStore()
    cat("Added annotations to EntityView and stored\n")
    Sys.sleep(2)  # Allow time for processing

    validation_response = test_view |> synValidateSchema()
    cat("EntityView validation response:\n")
    validation_response
} # }