cdm_data_loaders.readers.jsonschema_xsv.xsv_validator.schema_utils ¶
XSV-specific JSON Schema validation and header generation utilities.
ValidatedXsvSchema
pydantic-model
¶
Bases: ValidatedSchema
A JSON Schema to be used for parsing and validating XSV data.
Show JSON schema:
Fields:
-
jsonschema(dict[str, Any])
Validators:
-
validate_jsonschema→jsonschema
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/schema_utils.py
has_xsv_parser_config
property
¶
Whether or not this schema has custom fields for parsing XSV files.
has_xsv_metaschema
property
¶
Whether or not this schema has the custom metaschema URI indicating it holds XSV metadata.
required_cols
property
¶
Retrieve the list of headers from the top-level required field.
validate_jsonschema
pydantic-validator
¶
Validate the JSON schema in the jsonschema field and ensure it can be used for xsv validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict[str, Any]
|
the schema |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
the validated schema |
Raises:
| Type | Description |
|---|---|
ValueError
|
if there is no |
jsonschema.exceptions.SchemaError
|
if the schema is invalid |
jsonschema.exceptions.ValidationError
|
if the schema fails validation |
ValueError
|
if there are no |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/schema_utils.py
validate_jsonschema ¶
Ensure that a given file contains a valid XSV JSON schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
Path
|
path to the JSON Schema file |
required |
Returns:
| Type | Description |
|---|---|
ValidatedXsvSchema
|
validated XSV JSON Schema |
Raises:
| Type | Description |
|---|---|
jsonschema.exceptions.SchemaError
|
if the schema is invalid |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/schema_utils.py
generate_first_pass_schema ¶
Given a full schema file, generate a schema to perform a loose first-pass validation with.
The first pass schema is used for verifying that the top-level columns are correct; no further checks are performed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validated_schema
|
ValidatedXsvSchema
|
parsed, validated JSON schema |
required |
Returns:
| Type | Description |
|---|---|
ValidatedXsvSchema
|
the validated first pass schema |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/schema_utils.py
generate_header ¶
generate_header(
validated_schema: ValidatedXsvSchema,
target_dir: DirectoryPath,
header_file_name: NonEmptyStr = "header.txt",
delimiter: CharStr = "\t",
) -> Path
Generate a header file for an xSV file from a JSON Schema.
If no file name is supplied, the header file is saved as header.txt.
The top level required properties are assumed to be the columns of the xSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validated_schema
|
ValidatedXsvSchema
|
parsed, validated JSON schema |
required |
target_dir
|
DirectoryPath
|
directory in which to save the file |
required |
header_file_name
|
NonEmptyStr
|
name for the header file, defaults to "header.txt" |
'header.txt'
|
delimiter
|
CharStr
|
delimiter to use for the headers, defaults to "\t" |
'\t'
|
Returns:
| Type | Description |
|---|---|
Path
|
path to the newly-created header.txt file |
Source code in src/cdm_data_loaders/readers/jsonschema_xsv/xsv_validator/schema_utils.py
get_schema_parsing_metadata ¶
Read in the schema parser config information from the supplied schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validated_schema
|
ValidatedXsvSchema
|
parsed, validated JSON schema |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
parsed xsv schema metadata |
Raises:
| Type | Description |
|---|---|
ValueError
|
if no xsv config information is found in the schema |