Skip to content

Commit

Permalink
feat: add new keyword isValidIdentifier #59
Browse files Browse the repository at this point in the history
  • Loading branch information
theisuru committed Feb 20, 2023
1 parent 4e08272 commit 606b246
Show file tree
Hide file tree
Showing 14 changed files with 641 additions and 47 deletions.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,64 @@ Data:
}
```

### isValidIdentifier
Evaluates if a given *identifier* has a correct format using identifiers.org resolution API. The keyword is applicable to the `string` data type.

The keyword will do an asynchronous call to the [identifier.org API](https://resolver.api.identifiers.org/) to resolve the URL for the given CURIE.
Being an async validation step, whenever used in a schema, the schema must have the flag: `"$async": true` in its object root.

The keyword has two properties: `prefixes` and `prefix`. Only one of them is allowed in a block and `prefix` will take the priority in case both are provided.
- `prefix` define one namespace/prefix for the expected identifier/accession. In the data, field should only contain the ID/accession without the namespace.
- `prefixes` define a set of allowed namespaces/prefixes. In the data, field should contain a valid CURIE (namespace:id format)

:warning: At the moment only the format of the identifier/accession is checked against the identifier.org. Therefore, this does not guarantee the existence of the data record.

#### isValidIdentifier example 1
Schema:
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$async": true,
"properties": {
"SampleId": {
"type": "string",
"isValidIdentifier": {
"prefix": "biosample"
}
}
}
}
```
Data:
```json
{
"SampleId": "SAMEA2397676"
}
```

#### isValidIdentifier example 2
Schema:
```json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$async": true,
"properties": {
"resourceId": {
"type": "string",
"isValidIdentifier": {
"prefixes": ["biosample", "arrayexpress"]
}
}
}
}
```
Data:
```json
{
"resourceId": "biosample:SAMEA2397676"
}
```

## Running in Docker
A Dockerized version of biovalidator is available on [quay.io](https://quay.io/repository/ebi-ait/biovalidator).
This image can be used to run the validator without cloning this repository.
Expand Down
4 changes: 4 additions & 0 deletions examples/objects/isValidIdentifier-single-prefix_pass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sampleName": "test sample",
"SampleId": "SAMEA2397676"
}
4 changes: 4 additions & 0 deletions examples/objects/isValidIdentifier_fail.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sampleName": "test sample",
"SampleId": "biosample:INVALID_ID"
}
4 changes: 4 additions & 0 deletions examples/objects/isValidIdentifier_fail_namespace.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sampleName": "test sample",
"SampleId": "arrayexpress:E-MEXP-1712"
}
4 changes: 4 additions & 0 deletions examples/objects/isValidIdentifier_pass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"sampleName": "test sample",
"SampleId": "biosample:SAMEA2397676"
}
27 changes: 27 additions & 0 deletions examples/schemas/isValidIdentifier-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"$id": "http://subs/isValidIdentifier-schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Test schema for BioSample accession",
"$async": true,
"additionalProperties": false,
"required": [
"SampleId"
],
"title": "disease_ontology",
"properties": {
"sampleName": {
"description": "The text for the term as the user provides it.",
"type": "string"
},
"SampleId": {
"description": "An optional ontology reference in format where prefix_ indicates which ontology",
"type": "string",
"isValidIdentifier": {
"prefixes": [
"biosample"
]
}
}
},
"type": "object"
}
25 changes: 25 additions & 0 deletions examples/schemas/isValidIdentifier-single-prefix-schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$id": "http://subs/isValidIdentifier-schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "Test schema for BioSample accession",
"$async": true,
"additionalProperties": false,
"required": [
"SampleId"
],
"title": "disease_ontology",
"properties": {
"sampleName": {
"description": "The text for the term as the user provides it.",
"type": "string"
},
"SampleId": {
"description": "An optional ontology reference in format where prefix_ indicates which ontology",
"type": "string",
"isValidIdentifier": {
"prefix": "biosample"
}
}
},
"type": "object"
}
Loading

0 comments on commit 606b246

Please sign in to comment.