Skip to content

Commit 1f26726

Browse files
authored
Merge pull request #360 from biothings/fix-validation-merge
Fix for Issue #354 - Schema Viewer Displaying Inherited Properties
2 parents 1c3537c + 022ba0a commit 1f26726

File tree

4 files changed

+469
-2
lines changed

4 files changed

+469
-2
lines changed

discovery/handlers/api/schema.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,10 @@ class SchemaViewHandler(APIBaseHandler):
362362
"ns": {
363363
"type": str
364364
}, # indicates the special target namespace of the schema, e.g. schema.org or bioschemas.
365+
"validation_merge": {
366+
"type": bool,
367+
"default": False
368+
}, # whether to merge validation schemas from parent classes
365369
}
366370
}
367371

@@ -395,7 +399,9 @@ async def get(self):
395399
doc = self.request.body
396400
if doc:
397401
doc = json.loads(doc)
398-
validator_options = {"validation_merge": False, "raise_on_validation_error": False}
402+
# Use the validation_merge parameter from query args, defaults to False
403+
validation_merge = getattr(self.args, 'validation_merge', False)
404+
validator_options = {"validation_merge": validation_merge, "raise_on_validation_error": False}
399405
if self.args.ns:
400406
if self.args.ns == "schema.org":
401407
# do no load any base schemas

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
git+https://github.com/biothings/biothings_schema.py@d79b05c#egg=biothings_schema
1+
git+https://github.com/biothings/biothings_schema.py@2144cd6#egg=biothings_schema
22
# git+https://github.com/biothings/biothings.api.git@0.12.x#egg=biothings
33

44
biothings==1.0.2
Lines changed: 255 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,255 @@
1+
{
2+
"@context": {
3+
"schema": "http://schema.org/",
4+
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
5+
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
6+
"test": "http://discovery.biothings.io/test/"
7+
},
8+
"@graph": [
9+
{
10+
"@id": "test:GrandParentClass",
11+
"@type": "rdfs:Class",
12+
"rdfs:comment": "A grandparent class with validation",
13+
"rdfs:label": "GrandParentClass",
14+
"rdfs:subClassOf": {
15+
"@id": "schema:Thing"
16+
},
17+
"$validation": {
18+
"$schema": "http://json-schema.org/draft-07/schema#",
19+
"type": "object",
20+
"properties": {
21+
"grandParentProp1": {
22+
"description": "First property from grandparent",
23+
"type": "string"
24+
},
25+
"grandParentProp2": {
26+
"description": "Second property from grandparent",
27+
"type": "number"
28+
}
29+
},
30+
"required": ["grandParentProp1"]
31+
}
32+
},
33+
{
34+
"@id": "test:grandParentProp1",
35+
"@type": "rdf:Property",
36+
"rdfs:comment": "First property from grandparent",
37+
"rdfs:label": "grandParentProp1",
38+
"schema:domainIncludes": {
39+
"@id": "test:GrandParentClass"
40+
},
41+
"schema:rangeIncludes": {
42+
"@id": "schema:Text"
43+
}
44+
},
45+
{
46+
"@id": "test:grandParentProp2",
47+
"@type": "rdf:Property",
48+
"rdfs:comment": "Second property from grandparent",
49+
"rdfs:label": "grandParentProp2",
50+
"schema:domainIncludes": {
51+
"@id": "test:GrandParentClass"
52+
},
53+
"schema:rangeIncludes": {
54+
"@id": "schema:Number"
55+
}
56+
},
57+
{
58+
"@id": "test:ParentClass",
59+
"@type": "rdfs:Class",
60+
"rdfs:comment": "A parent class with some properties",
61+
"rdfs:label": "ParentClass",
62+
"rdfs:subClassOf": {
63+
"@id": "test:GrandParentClass"
64+
},
65+
"$validation": {
66+
"$schema": "http://json-schema.org/draft-07/schema#",
67+
"type": "object",
68+
"properties": {
69+
"parentProp1": {
70+
"description": "First property from parent",
71+
"type": "string"
72+
},
73+
"parentProp2": {
74+
"description": "Second property from parent",
75+
"type": "string"
76+
},
77+
"parentProp3": {
78+
"description": "Third property from parent",
79+
"type": "integer"
80+
}
81+
},
82+
"required": ["parentProp1", "parentProp2"]
83+
}
84+
},
85+
{
86+
"@id": "test:parentProp1",
87+
"@type": "rdf:Property",
88+
"rdfs:comment": "First property from parent",
89+
"rdfs:label": "parentProp1",
90+
"schema:domainIncludes": {
91+
"@id": "test:ParentClass"
92+
},
93+
"schema:rangeIncludes": {
94+
"@id": "schema:Text"
95+
}
96+
},
97+
{
98+
"@id": "test:parentProp2",
99+
"@type": "rdf:Property",
100+
"rdfs:comment": "Second property from parent",
101+
"rdfs:label": "parentProp2",
102+
"schema:domainIncludes": {
103+
"@id": "test:ParentClass"
104+
},
105+
"schema:rangeIncludes": {
106+
"@id": "schema:Text"
107+
}
108+
},
109+
{
110+
"@id": "test:parentProp3",
111+
"@type": "rdf:Property",
112+
"rdfs:comment": "Third property from parent",
113+
"rdfs:label": "parentProp3",
114+
"schema:domainIncludes": {
115+
"@id": "test:ParentClass"
116+
},
117+
"schema:rangeIncludes": {
118+
"@id": "schema:Integer"
119+
}
120+
},
121+
{
122+
"@id": "test:ChildClass",
123+
"@type": "rdfs:Class",
124+
"rdfs:comment": "A child class that extends ParentClass",
125+
"rdfs:label": "ChildClass",
126+
"rdfs:subClassOf": {
127+
"@id": "test:ParentClass"
128+
},
129+
"$validation": {
130+
"$schema": "http://json-schema.org/draft-07/schema#",
131+
"type": "object",
132+
"properties": {
133+
"childProp1": {
134+
"description": "First property specific to child",
135+
"type": "string"
136+
},
137+
"childProp2": {
138+
"description": "Second property specific to child",
139+
"type": "boolean"
140+
}
141+
},
142+
"required": ["childProp1"]
143+
}
144+
},
145+
{
146+
"@id": "test:childProp1",
147+
"@type": "rdf:Property",
148+
"rdfs:comment": "First property specific to child",
149+
"rdfs:label": "childProp1",
150+
"schema:domainIncludes": {
151+
"@id": "test:ChildClass"
152+
},
153+
"schema:rangeIncludes": {
154+
"@id": "schema:Text"
155+
}
156+
},
157+
{
158+
"@id": "test:childProp2",
159+
"@type": "rdf:Property",
160+
"rdfs:comment": "Second property specific to child",
161+
"rdfs:label": "childProp2",
162+
"schema:domainIncludes": {
163+
"@id": "test:ChildClass"
164+
},
165+
"schema:rangeIncludes": {
166+
"@id": "schema:Boolean"
167+
}
168+
},
169+
{
170+
"@id": "test:SecondParentClass",
171+
"@type": "rdfs:Class",
172+
"rdfs:comment": "A second parent class with different properties",
173+
"rdfs:label": "SecondParentClass",
174+
"rdfs:subClassOf": {
175+
"@id": "schema:Thing"
176+
},
177+
"$validation": {
178+
"$schema": "http://json-schema.org/draft-07/schema#",
179+
"type": "object",
180+
"properties": {
181+
"secondParentProp1": {
182+
"description": "First property from second parent",
183+
"type": "string"
184+
},
185+
"secondParentProp2": {
186+
"description": "Second property from second parent",
187+
"type": "number"
188+
}
189+
},
190+
"required": ["secondParentProp1"]
191+
}
192+
},
193+
{
194+
"@id": "test:secondParentProp1",
195+
"@type": "rdf:Property",
196+
"rdfs:comment": "First property from second parent",
197+
"rdfs:label": "secondParentProp1",
198+
"schema:domainIncludes": {
199+
"@id": "test:SecondParentClass"
200+
},
201+
"schema:rangeIncludes": {
202+
"@id": "schema:Text"
203+
}
204+
},
205+
{
206+
"@id": "test:secondParentProp2",
207+
"@type": "rdf:Property",
208+
"rdfs:comment": "Second property from second parent",
209+
"rdfs:label": "secondParentProp2",
210+
"schema:domainIncludes": {
211+
"@id": "test:SecondParentClass"
212+
},
213+
"schema:rangeIncludes": {
214+
"@id": "schema:Number"
215+
}
216+
},
217+
{
218+
"@id": "test:MultiParentChildClass",
219+
"@type": "rdfs:Class",
220+
"rdfs:comment": "A child class that extends BOTH ParentClass and SecondParentClass",
221+
"rdfs:label": "MultiParentChildClass",
222+
"rdfs:subClassOf": [
223+
{
224+
"@id": "test:ParentClass"
225+
},
226+
{
227+
"@id": "test:SecondParentClass"
228+
}
229+
],
230+
"$validation": {
231+
"$schema": "http://json-schema.org/draft-07/schema#",
232+
"type": "object",
233+
"properties": {
234+
"multiChildProp1": {
235+
"description": "Property specific to multi-parent child",
236+
"type": "string"
237+
}
238+
},
239+
"required": ["multiChildProp1"]
240+
}
241+
},
242+
{
243+
"@id": "test:multiChildProp1",
244+
"@type": "rdf:Property",
245+
"rdfs:comment": "Property specific to multi-parent child",
246+
"rdfs:label": "multiChildProp1",
247+
"schema:domainIncludes": {
248+
"@id": "test:MultiParentChildClass"
249+
},
250+
"schema:rangeIncludes": {
251+
"@id": "schema:Text"
252+
}
253+
}
254+
]
255+
}

0 commit comments

Comments
 (0)