-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jsonschema for validating schemas
- Loading branch information
Showing
7 changed files
with
219 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ include *.txt | |
include *.rst | ||
prune dist | ||
prune build | ||
include src/omero_render/*.yaml |
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,2 @@ | ||
from .schema import validate_renderdef, validate_renderdef_batch | ||
__all__ = ['validate_renderdef', 'validate_renderdef_batch'] |
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,115 @@ | ||
--- | ||
|
||
$schema: https://json-schema.org/schema# | ||
$id: https://github.com/ome/omero-cli-render#renderdef-batch | ||
title: jsonschema for batch rendering configuration | ||
type: object | ||
additionalProperties: false | ||
# Top level objects beginning with _ will be ignored | ||
patternProperties: | ||
"^_": | ||
type: | ||
object | ||
|
||
# Python jsonschema doesn't support $ref so use YAML anchors instead | ||
definitions: | ||
channel: &channel | ||
type: object | ||
additionalProperties: false | ||
properties: | ||
active: | ||
title: Active channel | ||
type: boolean | ||
color: | ||
title: Channel color as HTML RGB triplet | ||
type: string | ||
label: | ||
title: Channel name | ||
type: string | ||
start: | ||
title: Start of rendering window, optional (needs end) | ||
type: number | ||
end: | ||
title: End of rendering window, optional (needs start) | ||
type: number | ||
min: | ||
title: Minimum pixel intensity, optional (needs max) | ||
type: number | ||
max: | ||
title: Maximum pixel intensity, optional (needs min) | ||
type: number | ||
|
||
renderdef: &renderdef | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- channels | ||
properties: | ||
channels: | ||
title: Dictionary of channels | ||
type: object | ||
additionalProperties: false | ||
patternProperties: | ||
"^[0-9]+$": | ||
title: Channel index, 1-based | ||
type: object | ||
properties: *channel | ||
# $ref: "#/definitions/channel" | ||
greyscale: | ||
title: Greyscale rendering, optional | ||
type: boolean | ||
z: | ||
title: Default Z plane index, 1-based, optional | ||
type: integer | ||
t: | ||
title: Default T plane index, 1-based, optional | ||
type: integer | ||
version: | ||
title: Version of the renderdef specification | ||
type: integer | ||
|
||
dataset: &dataset | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- name | ||
- renderdef | ||
properties: | ||
name: | ||
title: Name of Dataset | ||
type: string | ||
renderdef: *renderdef | ||
# $ref: "#/definitions/renderdef" | ||
|
||
project: &project | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- name | ||
properties: | ||
name: | ||
title: Name of Project | ||
type: string | ||
datasets: | ||
title: List of Datasets | ||
type: array | ||
minItems: 1 | ||
items: *dataset | ||
# $ref: "#/definitions/dataset" | ||
renderdef: *renderdef | ||
# $ref: "#/definitions/renderdef" | ||
|
||
properties: | ||
projects: | ||
title: List of Projects | ||
type: array | ||
minItems: 1 | ||
items: *project | ||
# $ref: "#/definitions/project" | ||
|
||
datasets: | ||
title: List of Datasets | ||
type: array | ||
minItems: 1 | ||
items: *dataset | ||
# $ref: "#/definitions/dataset" |
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,61 @@ | ||
--- | ||
|
||
$schema: https://json-schema.org/schema# | ||
$id: https://github.com/ome/omero-cli-render#renderdef | ||
title: jsonschema for render configuration file | ||
type: object | ||
additionalProperties: false | ||
required: | ||
- channels | ||
|
||
# Python jsonschema doesn't support $ref so use YAML anchors instead | ||
definitions: | ||
channel: &channel | ||
type: object | ||
additionalProperties: false | ||
properties: | ||
active: | ||
title: Active channel | ||
type: boolean | ||
color: | ||
title: Channel color as HTML RGB triplet | ||
type: string | ||
label: | ||
title: Channel name | ||
type: string | ||
start: | ||
title: Start of rendering window, optional (needs end) | ||
type: number | ||
end: | ||
title: End of rendering window, optional (needs start) | ||
type: number | ||
min: | ||
title: Minimum pixel intensity, optional (needs max) | ||
type: number | ||
max: | ||
title: Maximum pixel intensity, optional (needs min) | ||
type: number | ||
|
||
properties: | ||
channels: | ||
title: Dictionary of channels | ||
type: object | ||
additionalProperties: false | ||
patternProperties: | ||
"^[0-9]+$": | ||
title: Channel index, 1-based | ||
type: object | ||
properties: | ||
channel: *channel | ||
greyscale: | ||
title: Greyscale rendering, optional | ||
type: boolean | ||
z: | ||
title: Default Z plane index, 1-based, optional | ||
type: integer | ||
t: | ||
title: Default T plane index, 1-based, optional | ||
type: integer | ||
version: | ||
title: Version of the renderdef specification | ||
type: integer |
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,31 @@ | ||
import json | ||
from jsonschema import Draft7Validator | ||
from pkgutil import get_data | ||
import yaml | ||
|
||
|
||
def _validate(schema_name, renderdef): | ||
schemastr = get_data('omero_render', schema_name) | ||
yml = yaml.safe_load(schemastr) | ||
# Hack to expand anchors | ||
# https://stackoverflow.com/a/64993515 | ||
schema = json.loads(json.dumps(yml)) | ||
v = Draft7Validator(schema) | ||
# print(yaml.dump(schema)) | ||
# print(renderdef) | ||
# Hack to ensure YAML integer keys are JSON strings | ||
renderdef_json = json.loads(json.dumps(renderdef)) | ||
|
||
if not v.is_valid(renderdef_json): | ||
errs = '\n\n** '.join( | ||
['Invalid definition'] + | ||
['\n\n'.join(str(e) for e in v.iter_errors(renderdef_json))]) | ||
raise ValueError(errs) | ||
|
||
|
||
def validate_renderdef(renderdef): | ||
_validate('renderdef-schema.yaml', renderdef) | ||
|
||
|
||
def validate_renderdef_batch(renderdef): | ||
_validate('renderdef-batch-schema.yaml', renderdef) |