@@ -390,7 +390,7 @@ def document_collection_recursive(
390
390
391
391
392
392
def document_api (
393
- name , version , uri , doc_destination_dir , artifact_destination_dir = DISCOVERY_DOC_DIR
393
+ name , version , uri , doc_destination_dir , artifact_destination_dir = DISCOVERY_DOC_DIR , discovery_uri_template = None
394
394
):
395
395
"""Document the given API.
396
396
@@ -402,14 +402,23 @@ def document_api(
402
402
documentation should be saved.
403
403
artifact_destination_dir (str): relative path where the discovery
404
404
artifacts should be saved.
405
+ discovery_uri_template (str): URI template of the API's discovery document.
406
+ If this parameter is set, the `uri` parameter is ignored and the uri
407
+ will be created from this template.
405
408
"""
406
- http = build_http ()
407
- resp , content = http .request (
408
- uri
409
- or uritemplate .expand (
409
+ # Use the discovery_uri_template to create the uri if provided
410
+ if discovery_uri_template :
411
+ uri = uritemplate .expand (
412
+ discovery_uri_template , {"api" : name , "apiVersion" : version }
413
+ )
414
+
415
+ if not uri :
416
+ uritemplate .expand (
410
417
FLAGS .discovery_uri_template , {"api" : name , "apiVersion" : version }
411
418
)
412
- )
419
+
420
+ http = build_http ()
421
+ resp , content = http .request (uri )
413
422
414
423
if resp .status == 200 :
415
424
discovery = json .loads (content )
@@ -494,6 +503,7 @@ def generate_all_api_documents(
494
503
directory_uri = DIRECTORY_URI ,
495
504
doc_destination_dir = BASE ,
496
505
artifact_destination_dir = DISCOVERY_DOC_DIR ,
506
+ discovery_uri_template = None ,
497
507
):
498
508
"""Retrieve discovery artifacts and fetch reference documentations
499
509
for all apis listed in the public discovery directory.
@@ -503,6 +513,9 @@ def generate_all_api_documents(
503
513
documentation should be saved.
504
514
artifact_destination_dir (str): relative path where the discovery
505
515
artifacts should be saved.
516
+ discovery_uri_template (str): URI template of the API's discovery document.
517
+ If this parameter is set, the `uri` parameter is ignored and the uri
518
+ will be created from this template.
506
519
"""
507
520
api_directory = collections .defaultdict (list )
508
521
http = build_http ()
@@ -516,6 +529,7 @@ def generate_all_api_documents(
516
529
api ["discoveryRestUrl" ],
517
530
doc_destination_dir ,
518
531
artifact_destination_dir ,
532
+ discovery_uri_template ,
519
533
)
520
534
api_directory [api ["name" ]].append (api ["version" ])
521
535
0 commit comments