Skip to content

Commit d5365fb

Browse files
authored
Added support for datatype(range) in supported properties (#91)
* updated docs * changed context and hydraclassprop * changes in doc_maker * check for range
1 parent f191e9e commit d5365fb

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

hydra_python_core/doc_maker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ def create_property(supported_property: Dict[str, Any]) -> Union[HydraLink, Hydr
332332
prop_require = supported_property[hydra['required']][0]['@value']
333333
prop_write = supported_property[hydra['writeable']][0]['@value']
334334

335+
for namespace in supported_property:
336+
if "range" in namespace:
337+
prop_range = supported_property[namespace][0]['@id']
338+
prop_ = HydraClassProp(prop=prop_id,
339+
title=prop_title,
340+
required=prop_require,
341+
read=prop_read,
342+
write=prop_write,
343+
range=prop_range)
344+
return prop_
345+
335346
prop_ = HydraClassProp(prop=prop_id,
336347
title=prop_title,
337348
required=prop_require,

hydra_python_core/doc_writer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,15 @@ def __init__(self,
186186
write: bool,
187187
required: bool,
188188
desc: str = "",
189-
) -> None:
189+
**kwargs) -> None:
190190
"""Initialize the Hydra_Prop."""
191191
self.prop = prop
192192
self.title = title
193193
self.read = read
194194
self.write = write
195195
self.required = required
196196
self.desc = desc
197+
self.kwargs = kwargs
197198

198199
def generate(self) -> Dict[str, Any]:
199200
"""Get the Hydra prop as a python dict."""
@@ -210,6 +211,8 @@ def generate(self) -> Dict[str, Any]:
210211
prop["property"] = self.prop
211212
if len(self.desc) > 0:
212213
prop["description"] = self.desc
214+
if "range" in self.kwargs:
215+
prop["range"] = self.kwargs["range"]
213216
return prop
214217

215218

@@ -781,6 +784,7 @@ def __init__(self,
781784
"supportedOperation": "hydra:supportedOperation",
782785
"label": "rdfs:label",
783786
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
787+
"xsd": "https://www.w3.org/TR/xmlschema-2/#",
784788
"domain": {
785789
"@type": "@id",
786790
"@id": "rdfs:domain"

hydra_python_core/namespace.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"search": hydraNamespace + "search",
7272
"view": hydraNamespace + "view"
7373
}
74+
7475
rdfNamespace = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
7576

7677
rdf = {

samples/doc_writer_sample_output.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
"method": "POST",
7878
"possibleStatus": [
7979
{
80-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
80+
"@context": "https://www.w3.org/ns/hydra/core",
8181
"@type": "Status",
8282
"description": "dummyClass updated.",
8383
"statusCode": 200,
@@ -98,7 +98,7 @@
9898
"method": "DELETE",
9999
"possibleStatus": [
100100
{
101-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
101+
"@context": "https://www.w3.org/ns/hydra/core",
102102
"@type": "Status",
103103
"description": "dummyClass deleted.",
104104
"statusCode": 200,
@@ -116,7 +116,7 @@
116116
"method": "PUT",
117117
"possibleStatus": [
118118
{
119-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
119+
"@context": "https://www.w3.org/ns/hydra/core",
120120
"@type": "Status",
121121
"description": "dummyClass successfully added.",
122122
"statusCode": 201,
@@ -134,7 +134,7 @@
134134
"method": "GET",
135135
"possibleStatus": [
136136
{
137-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
137+
"@context": "https://www.w3.org/ns/hydra/core",
138138
"@type": "Status",
139139
"description": "dummyClass returned.",
140140
"statusCode": 200,
@@ -186,7 +186,7 @@
186186
"method": "POST",
187187
"possibleStatus": [
188188
{
189-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
189+
"@context": "https://www.w3.org/ns/hydra/core",
190190
"@type": "Status",
191191
"description": "singleClass changed.",
192192
"statusCode": 200,
@@ -204,7 +204,7 @@
204204
"method": "DELETE",
205205
"possibleStatus": [
206206
{
207-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
207+
"@context": "https://www.w3.org/ns/hydra/core",
208208
"@type": "Status",
209209
"description": "singleClass deleted.",
210210
"statusCode": 200,
@@ -222,7 +222,7 @@
222222
"method": "PUT",
223223
"possibleStatus": [
224224
{
225-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
225+
"@context": "https://www.w3.org/ns/hydra/core",
226226
"@type": "Status",
227227
"description": "singleClass successfully added.",
228228
"statusCode": 201,
@@ -240,7 +240,7 @@
240240
"method": "GET",
241241
"possibleStatus": [
242242
{
243-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
243+
"@context": "https://www.w3.org/ns/hydra/core",
244244
"@type": "Status",
245245
"description": "singleClass returned.",
246246
"statusCode": 200,
@@ -308,7 +308,7 @@
308308
"method": "GET",
309309
"possibleStatus": [
310310
{
311-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
311+
"@context": "https://www.w3.org/ns/hydra/core",
312312
"@type": "Status",
313313
"description": "anotherSingleClass returned.",
314314
"statusCode": 200,
@@ -387,7 +387,7 @@
387387
"method": "PUT",
388388
"possibleStatus": [
389389
{
390-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
390+
"@context": "https://www.w3.org/ns/hydra/core",
391391
"@type": "Status",
392392
"description": "A new member in Extraclasses created",
393393
"statusCode": 201,
@@ -406,7 +406,7 @@
406406
"method": "POST",
407407
"possibleStatus": [
408408
{
409-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
409+
"@context": "https://www.w3.org/ns/hydra/core",
410410
"@type": "Status",
411411
"description": "If the entity was updatedfrom Extraclasses.",
412412
"statusCode": 200,
@@ -425,7 +425,7 @@
425425
"method": "DELETE",
426426
"possibleStatus": [
427427
{
428-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
428+
"@context": "https://www.w3.org/ns/hydra/core",
429429
"@type": "Status",
430430
"description": "If entity was deletedsuccessfully from Extraclasses.",
431431
"statusCode": 200,
@@ -479,7 +479,7 @@
479479
"method": "PUT",
480480
"possibleStatus": [
481481
{
482-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
482+
"@context": "https://www.w3.org/ns/hydra/core",
483483
"@type": "Status",
484484
"description": "A new member in dummyclasses created",
485485
"statusCode": 201,
@@ -498,7 +498,7 @@
498498
"method": "POST",
499499
"possibleStatus": [
500500
{
501-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
501+
"@context": "https://www.w3.org/ns/hydra/core",
502502
"@type": "Status",
503503
"description": "If the entity was updatedfrom dummyclasses.",
504504
"statusCode": 200,
@@ -517,7 +517,7 @@
517517
"method": "DELETE",
518518
"possibleStatus": [
519519
{
520-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
520+
"@context": "https://www.w3.org/ns/hydra/core",
521521
"@type": "Status",
522522
"description": "If entity was deletedsuccessfully from dummyclasses.",
523523
"statusCode": 200,
@@ -580,7 +580,7 @@
580580
"method": "POST",
581581
"possibleStatus": [
582582
{
583-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
583+
"@context": "https://www.w3.org/ns/hydra/core",
584584
"@type": "Status",
585585
"description": "singleClass changed.",
586586
"statusCode": 200,
@@ -600,7 +600,7 @@
600600
"method": "DELETE",
601601
"possibleStatus": [
602602
{
603-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
603+
"@context": "https://www.w3.org/ns/hydra/core",
604604
"@type": "Status",
605605
"description": "singleClass deleted.",
606606
"statusCode": 200,
@@ -620,7 +620,7 @@
620620
"method": "PUT",
621621
"possibleStatus": [
622622
{
623-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
623+
"@context": "https://www.w3.org/ns/hydra/core",
624624
"@type": "Status",
625625
"description": "singleClass successfully added.",
626626
"statusCode": 201,
@@ -640,7 +640,7 @@
640640
"method": "GET",
641641
"possibleStatus": [
642642
{
643-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
643+
"@context": "https://www.w3.org/ns/hydra/core",
644644
"@type": "Status",
645645
"description": "singleClass returned.",
646646
"statusCode": 200,
@@ -677,7 +677,7 @@
677677
"method": "GET",
678678
"possibleStatus": [
679679
{
680-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
680+
"@context": "https://www.w3.org/ns/hydra/core",
681681
"@type": "Status",
682682
"description": "anotherSingleClass returned.",
683683
"statusCode": 200,
@@ -728,7 +728,7 @@
728728
"method": "PUT",
729729
"possibleStatus": [
730730
{
731-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
731+
"@context": "https://www.w3.org/ns/hydra/core",
732732
"@type": "Status",
733733
"description": "A new member in Extraclasses created",
734734
"statusCode": 201,
@@ -747,7 +747,7 @@
747747
"method": "POST",
748748
"possibleStatus": [
749749
{
750-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
750+
"@context": "https://www.w3.org/ns/hydra/core",
751751
"@type": "Status",
752752
"description": "If the entity was updatedfrom Extraclasses.",
753753
"statusCode": 200,
@@ -766,7 +766,7 @@
766766
"method": "DELETE",
767767
"possibleStatus": [
768768
{
769-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
769+
"@context": "https://www.w3.org/ns/hydra/core",
770770
"@type": "Status",
771771
"description": "If entity was deletedsuccessfully from Extraclasses.",
772772
"statusCode": 200,
@@ -817,7 +817,7 @@
817817
"method": "PUT",
818818
"possibleStatus": [
819819
{
820-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
820+
"@context": "https://www.w3.org/ns/hydra/core",
821821
"@type": "Status",
822822
"description": "A new member in dummyclasses created",
823823
"statusCode": 201,
@@ -836,7 +836,7 @@
836836
"method": "POST",
837837
"possibleStatus": [
838838
{
839-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
839+
"@context": "https://www.w3.org/ns/hydra/core",
840840
"@type": "Status",
841841
"description": "If the entity was updatedfrom dummyclasses.",
842842
"statusCode": 200,
@@ -855,7 +855,7 @@
855855
"method": "DELETE",
856856
"possibleStatus": [
857857
{
858-
"@context": "https://raw.githubusercontent.com/HydraCG/Specifications/master/spec/latest/core/core.jsonld",
858+
"@context": "https://www.w3.org/ns/hydra/core",
859859
"@type": "Status",
860860
"description": "If entity was deletedsuccessfully from dummyclasses.",
861861
"statusCode": 200,

tests/test_doc_writer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def test_context_with_nothing(self):
2323
'supportedOperation': 'hydra:supportedOperation',
2424
'label': 'rdfs:label',
2525
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
26+
"xsd": "https://www.w3.org/TR/xmlschema-2/#",
2627
'domain': {
2728
'@type': '@id',
2829
'@id': 'rdfs:domain'

0 commit comments

Comments
 (0)