@@ -109,7 +109,9 @@ def generate(self) -> Dict[str, Any]:
109
109
"description" : self .desc ,
110
110
"entrypoint" : urljoin (self .base_url , self .entrypoint_endpoint ),
111
111
"supportedClass" : [
112
- x .generate () for x in parsed_classes + self .other_classes + collections + [self .entrypoint ]],
112
+ x .generate ()
113
+ for x in parsed_classes + self .other_classes + collections + [self .entrypoint ]
114
+ ],
113
115
"possibleStatus" : [status .generate () for status in self .possible_status ]
114
116
}
115
117
return doc
@@ -214,15 +216,16 @@ def generate(self) -> Dict[str, Any]:
214
216
class HydraClassOp ():
215
217
"""Template for a new supportedOperation."""
216
218
217
- def __init__ (self ,
218
- title : str ,
219
- method : str ,
220
- expects : Optional [str ],
221
- returns : Optional [str ],
222
- expects_header : List [str ] = [],
223
- returns_header : List [str ] = [],
224
- possible_status : List [Union ['HydraStatus' , 'HydraError' ]] = [],
225
- ) -> None :
219
+ def __init__ (
220
+ self ,
221
+ title : str ,
222
+ method : str ,
223
+ expects : Optional [str ],
224
+ returns : Optional [str ],
225
+ expects_header : List [str ] = [],
226
+ returns_header : List [str ] = [],
227
+ possible_status : List [Union ['HydraStatus' , 'HydraError' ]]= [],
228
+ ) -> None :
226
229
"""Initialize the Hydra_Prop."""
227
230
self .title = title
228
231
self .method = method
@@ -267,52 +270,59 @@ def __init__(
267
270
collection_name : str = None ,
268
271
collection_path : str = None ,
269
272
collection_description : str = None ,
270
- manages : Union [Dict [str , Any ], List ] = None ,
273
+ manages : Union [Dict [str , Any ], List ]= None ,
271
274
get : bool = True , post : bool = True , put : bool = True , delete : bool = True ) -> None :
272
275
"""Generate Collection for related resources."""
273
276
self .collection_id = "{}{}" .format (DocUrl .doc_url , quote (collection_name , safe = '' ))
274
277
self .name = collection_name
275
278
self .collection_description = collection_description
276
279
self .path = collection_path if collection_path else self .name
277
280
self .supportedOperation = list () # type: List
278
- self .supportedProperty = [HydraClassProp ("http://www.w3.org/ns/hydra/core#member" ,
279
- "members" ,
280
- True , True , False ,
281
- "The members of {}" .format (collection_name ))]
281
+ self .supportedProperty = [HydraClassProp (
282
+ "http://www.w3.org/ns/hydra/core#member" ,
283
+ "members" ,
284
+ True ,
285
+ True ,
286
+ False ,
287
+ "The members of {}" .format (collection_name ))]
282
288
self .manages = manages
283
289
284
290
if get :
285
- get_op = HydraCollectionOp ("_:{}_retrieve" .format (self .name ),
286
- "http://schema.org/FindAction" ,
287
- "GET" , "Retrieves all the members of {}" .format (self .name ),
288
- None , self .manages ['object' ], [], [], [])
291
+ get_op = HydraCollectionOp (
292
+ "_:{}_retrieve" .format (self .name ),
293
+ "http://schema.org/FindAction" ,
294
+ "GET" , "Retrieves all the members of {}" .format (self .name ),
295
+ None , self .manages ['object' ], [], [], [])
289
296
self .supportedOperation .append (get_op )
290
297
291
298
if put :
292
- put_op = HydraCollectionOp ("_:{}_create" .format (self .name ), "http://schema.org/AddAction" ,
293
- "PUT" , "Create new member in {}" .format (self .name ),
294
- self .manages ['object' ], self .manages ['object' ], [], [],
295
- [HydraStatus (code = 201 , desc = "A new member in {} created" .format (self .name ))]
296
- )
299
+ put_op = HydraCollectionOp (
300
+ "_:{}_create" .format (self .name ), "http://schema.org/AddAction" ,
301
+ "PUT" , "Create new member in {}" .format (self .name ),
302
+ self .manages ['object' ], self .manages ['object' ], [], [],
303
+ [HydraStatus (code = 201 , desc = "A new member in {} created" .format (self .name ))]
304
+ )
297
305
self .supportedOperation .append (put_op )
298
306
if post :
299
- post_op = HydraCollectionOp ("_:{}_update" .format (self .name ),
300
- "http://schema.org/UpdateAction" ,
301
- "POST" , "Update member of {} " .format (self .name ),
302
- self .manages ['object' ], self .manages ['object' ], [], [],
303
- [HydraStatus (code = 200 , desc = "If the entity was updated"
304
- "from {}." .format (self .name ))]
305
- )
307
+ post_op = HydraCollectionOp (
308
+ "_:{}_update" .format (self .name ),
309
+ "http://schema.org/UpdateAction" ,
310
+ "POST" , "Update member of {} " .format (self .name ),
311
+ self .manages ['object' ], self .manages ['object' ], [], [],
312
+ [HydraStatus (code = 200 , desc = "If the entity was updated"
313
+ "from {}." .format (self .name ))]
314
+ )
306
315
self .supportedOperation .append (post_op )
307
316
308
317
if delete :
309
- delete_op = HydraCollectionOp ("_:{}_delete" .format (self .name ),
310
- "http://schema.org/DeleteAction" ,
311
- "DELETE" , "Delete member of {} " .format (self .name ),
312
- self .manages ['object' ], self .manages ['object' ], [], [],
313
- [HydraStatus (code = 200 , desc = "If entity was deleted"
314
- "successfully from {}." .format (self .name ))]
315
- )
318
+ delete_op = HydraCollectionOp (
319
+ "_:{}_delete" .format (self .name ),
320
+ "http://schema.org/DeleteAction" ,
321
+ "DELETE" , "Delete member of {} " .format (self .name ),
322
+ self .manages ['object' ], self .manages ['object' ], [], [],
323
+ [HydraStatus (code = 200 , desc = "If entity was deleted"
324
+ "successfully from {}." .format (self .name ))]
325
+ )
316
326
self .supportedOperation .append (delete_op )
317
327
318
328
def generate (self ) -> Dict [str , Any ]:
@@ -343,7 +353,7 @@ def __init__(self,
343
353
returns : Optional [str ],
344
354
expects_header : List [str ] = [],
345
355
returns_header : List [str ] = [],
346
- possible_status : List [Union ['HydraStatus' , 'HydraError' ]] = [],
356
+ possible_status : List [Union ['HydraStatus' , 'HydraError' ]]= [],
347
357
) -> None :
348
358
"""Create method."""
349
359
self .id_ = id_
@@ -379,18 +389,19 @@ def __init__(self, base_url: str, entrypoint: str) -> None:
379
389
"""Initialize the Entrypoint."""
380
390
self .url = base_url
381
391
self .api = entrypoint
392
+ class_id = "{}?resource=EntryPoint" .format (urljoin (self .url , self .api ))
382
393
self .entrypoint = HydraClass ("EntryPoint" , "The main entry point or homepage of the API." ,
383
- _id = "{}#EntryPoint" . format ( urljoin ( self . url , self . api )) )
394
+ _id = class_id )
384
395
self .entrypoint .add_supported_op (EntryPointOp (
385
396
"_:entry_point" .format (base_url ), "GET" , "The APIs main entry point." , None , None ,
386
- type_ = "{}/{}# EntryPoint" .format (base_url , entrypoint )))
397
+ type_ = "{}/{}?resource= EntryPoint" .format (base_url , entrypoint )))
387
398
self .context = Context (
388
399
"{}{}" .format (
389
400
base_url ,
390
401
entrypoint ),
391
402
entrypoint = self )
392
403
393
- self .collections : List [ EntryPointCollection ] = []
404
+ self .collections = list ()
394
405
395
406
def add_Class (self , class_ : HydraClass ) -> None :
396
407
"""Add supportedProperty to the EntryPoint.
@@ -428,8 +439,8 @@ def generate(self) -> Dict[str, Any]:
428
439
def get (self ) -> Dict [str , str ]:
429
440
"""Create the EntryPoint object to be returnd for the get function."""
430
441
object_ = {
431
- "@context" : "{}{}/contexts/EntryPoint.jsonld" .format (self .url ,self .api ),
432
- "@id" : "{}{}" .format (self .url ,self .api ),
442
+ "@context" : "{}{}/contexts/EntryPoint.jsonld" .format (self .url , self .api ),
443
+ "@id" : "{}{}" .format (self .url , self .api ),
433
444
"@type" : "EntryPoint" ,
434
445
435
446
}
@@ -438,7 +449,7 @@ def get(self) -> Dict[str, str]:
438
449
if item .generate () in self .collections :
439
450
collection_returned = item .generate ()
440
451
collection_id = uri .replace (
441
- "{}EntryPoint" .format (DocUrl .doc_url ), "{}{}" .format (self .url ,self .api ))
452
+ "{}EntryPoint" .format (DocUrl .doc_url ), "{}{}" .format (self .url , self .api ))
442
453
collection_to_append = {
443
454
"@id" : collection_id ,
444
455
'title' : collection_returned ['hydra:title' ],
@@ -454,7 +465,7 @@ def get(self) -> Dict[str, str]:
454
465
455
466
else :
456
467
object_ [item .name ] = uri .replace (
457
- "{}EntryPoint" .format (DocUrl .doc_url ), "{}{}" .format (self .url ,self .api ))
468
+ "{}EntryPoint" .format (DocUrl .doc_url ), "{}{}" .format (self .url , self .api ))
458
469
459
470
return object_
460
471
@@ -554,7 +565,7 @@ def __init__(self,
554
565
returns : Optional [str ],
555
566
expects_header : List [str ] = [],
556
567
returns_header : List [str ] = [],
557
- possible_status : List [Union ['HydraStatus' , 'HydraError' ]] = [],
568
+ possible_status : List [Union ['HydraStatus' , 'HydraError' ]]= [],
558
569
type_ : Optional [str ] = None ,
559
570
label : str = "" ,
560
571
) -> None :
@@ -639,10 +650,10 @@ def __init__(self,
639
650
640
651
def generate (self ) -> Dict [str , Any ]:
641
652
"""Get IriTemplate as a python dict"""
642
- base_url = DocUrl .doc_url .rsplit ('/' ,2 )[0 ]
653
+ base_url = DocUrl .doc_url .rsplit ('/' , 2 )[0 ]
643
654
iri_template = {
644
655
"@type" : "hydra:IriTemplate" ,
645
- "hydra:template" : "{}{}" .format (base_url ,self .template ),
656
+ "hydra:template" : "{}{}" .format (base_url , self .template ),
646
657
"hydra:variableRepresentation" : self .variable_rep ,
647
658
"hydra:mapping" : [x .generate () for x in self .mapping ]
648
659
}
@@ -739,7 +750,8 @@ def __init__(self,
739
750
# context elements to the base Hydra context
740
751
if class_ is not None :
741
752
self .context = {"hydra" : "http://www.w3.org/ns/hydra/core#" ,
742
- "members" : "http://www.w3.org/ns/hydra/core#member" , "object" : "http://schema.org/object" ,
753
+ "members" : "http://www.w3.org/ns/hydra/core#member" ,
754
+ "object" : "http://schema.org/object" ,
743
755
class_ .title : class_ .id_ } # type: Dict[str, Any]
744
756
for prop in class_ .supportedProperty :
745
757
if isinstance (prop .prop , HydraLink ):
@@ -840,4 +852,4 @@ class DocUrl:
840
852
doc_url = ''
841
853
842
854
def __init__ (self , base_url : str , api_name : str , doc_name : str ) -> None :
843
- DocUrl .doc_url = "{}/{}# " .format (urljoin (base_url , api_name ), doc_name )
855
+ DocUrl .doc_url = "{}/{}?resource= " .format (urljoin (base_url , api_name ), doc_name )
0 commit comments