Skip to content

Commit

Permalink
Utilize a single JSON_SCHEMA_FILE_RESOLVER setting for all defined sc…
Browse files Browse the repository at this point in the history
…hemas
  • Loading branch information
scottx611x committed Oct 16, 2017
1 parent a0a205d commit 2f1419f
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 30 deletions.
12 changes: 3 additions & 9 deletions refinery/analysis_manager/schemas/AnalysisConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@
"workflow_uuid"

],
"patterns": {
"uuid": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
}
},
"properties": {
"name": {
"type": "string"
},
"study_uuid": {
"$ref": "#/patterns/uuid"
"$ref": "core/schemas/Base.json#patterns/uuid"
},
"tool_uuid": {
"$ref": "#/patterns/uuid"
"$ref": "core/schemas/Base.json#patterns/uuid"
},
"user_id": {
"type": "number"
},
"workflow_uuid": {
"$ref": "#/patterns/uuid"
"$ref": "core/schemas/Base.json#patterns/uuid"
}
}
}
6 changes: 5 additions & 1 deletion refinery/analysis_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ def validate_analysis_config(analysis_config):
with open(settings.REFINERY_ANALYSIS_CONFIG_SCHEMA) as f:
schema = json.loads(f.read())
try:
validate(analysis_config, schema)
validate(
analysis_config,
schema,
resolver=settings.JSON_SCHEMA_FILE_RESOLVER
)
except ValidationError as e:
raise RuntimeError(
"Analysis Configuration is invalid: {}".format(e)
Expand Down
7 changes: 7 additions & 0 deletions refinery/config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from django.core.exceptions import ImproperlyConfigured

import djcelery
from jsonschema import RefResolver
import yaml

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -690,3 +691,9 @@ def get_setting(name, settings=local_settings, default=None):
BASE_DIR,
"refinery/tool_manager/schemas/WorkflowStep.json"
)

# Allow JSONSchema to find the JSON pointers to our schema files
JSON_SCHEMA_FILE_RESOLVER = RefResolver(
"file://{}/".format(os.path.join(BASE_DIR, "refinery")),
None
)

This comment has been minimized.

Copy link
@hackdna

hackdna Oct 16, 2017

Member

I think this only complicates things without a good reason.

File renamed without changes.
8 changes: 4 additions & 4 deletions refinery/tool_manager/schemas/ToolDefinition.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"type": "string"
},
"file_relationship": {
"$ref": "FileRelationship.json#"
"$ref": "tool_manager/schemas/FileRelationship.json#"
},
"parameters": {
"type": "array",
"items": {
"$ref": "GalaxyParameter.json#"
"$ref": "tool_manager/schemas/GalaxyParameter.json#"
}
},
"tool_type":{
Expand All @@ -48,12 +48,12 @@
"type": "string"
},
"file_relationship": {
"$ref": "FileRelationship.json#"
"$ref": "tool_manager/schemas/FileRelationship.json#"
},
"parameters": {
"type": "array",
"items": {
"$ref": "Parameter.json#"
"$ref": "tool_manager/schemas/Parameter.json#"
}
},
"tool_type":{
Expand Down
4 changes: 2 additions & 2 deletions refinery/tool_manager/schemas/ToolLaunchConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"file_relationships"
],
"properties": {
"dataset_uuid": {"$ref": "Base.json#patterns/uuid"},
"tool_definition_uuid": {"$ref": "Base.json#patterns/uuid"},
"dataset_uuid": {"$ref": "core/schemas/Base.json#patterns/uuid"},
"tool_definition_uuid": {"$ref": "core/schemas/Base.json#patterns/uuid"},
"file_relationships": {
"oneOf": [
{"type": "string"},
Expand Down
2 changes: 1 addition & 1 deletion refinery/tool_manager/schemas/WorkflowStep.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "array",
"items": {
"type": "object",
"$ref": "Parameter.json#"
"$ref": "tool_manager/schemas/Parameter.json#"
}
}
}
Expand Down
17 changes: 4 additions & 13 deletions refinery/tool_manager/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import glob
import json
import logging
import os
import uuid

from django.conf import settings
Expand All @@ -10,7 +9,7 @@

from bioblend.galaxy.client import ConnectionError
from django_docker_engine.docker_utils import DockerClientWrapper
from jsonschema import RefResolver, ValidationError, validate
from jsonschema import ValidationError, validate

from core.models import DataSet, Workflow, WorkflowEngine
from factory_boy.django_model_factories import (FileRelationshipFactory,
Expand All @@ -32,13 +31,6 @@
"https://github.com/refinery-platform/refinery-platform/wiki/"
"Annotating-&-Importing-Refinery-Tools#importing-refinery-tools"
)
# Allow JSON Schema to find the JSON pointers we define in our schemas
JSON_SCHEMA_FILE_RESOLVER = RefResolver(
"file://{}/".format(
os.path.join(settings.BASE_DIR, "refinery/tool_manager/schemas")
),
None
)


class AdminFieldPopulator(admin.ModelAdmin):
Expand Down Expand Up @@ -449,7 +441,6 @@ def validate_tool_annotation(annotation_dictionary):
properly.
:param annotation_dictionary: dict containing Tool annotation data
"""

with open(settings.REFINERY_TOOL_DEFINITION_SCHEMA) as f:
schema = json.loads(f.read())
annotation_to_validate = annotation_dictionary["annotation"]
Expand All @@ -459,7 +450,7 @@ def validate_tool_annotation(annotation_dictionary):
validate(
annotation_to_validate,
schema,
resolver=JSON_SCHEMA_FILE_RESOLVER
resolver=settings.JSON_SCHEMA_FILE_RESOLVER
)
except ValidationError as e:
raise RuntimeError(
Expand All @@ -484,7 +475,7 @@ def validate_workflow_step_annotation(workflow_step_dictionary):
validate(
workflow_step_dictionary,
schema,
resolver=JSON_SCHEMA_FILE_RESOLVER
resolver=settings.JSON_SCHEMA_FILE_RESOLVER
)
except ValidationError as e:
raise RuntimeError(
Expand All @@ -503,7 +494,7 @@ def validate_tool_launch_configuration(tool_launch_config):
validate(
tool_launch_config,
schema,
resolver=JSON_SCHEMA_FILE_RESOLVER
resolver=settings.JSON_SCHEMA_FILE_RESOLVER
)
except ValidationError as e:
raise RuntimeError(
Expand Down

0 comments on commit 2f1419f

Please sign in to comment.