136
136
137
137
BASE = pathlib .Path (__file__ ).resolve ().parent / "docs" / "dyn"
138
138
139
- DIRECTORY_URI = "https://www.googleapis.com/discovery/v1/apis"
139
+ # Obtain the discovery index and artifacts from googleapis/discovery-artifact-manager
140
+ DIRECTORY_URI = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/index.json"
141
+ DISCOVERY_URI_TEMPLATE = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/{api}.{apiVersion}.json"
140
142
141
143
parser = argparse .ArgumentParser (description = __doc__ )
142
144
143
145
parser .add_argument (
144
146
"--discovery_uri_template" ,
145
- default = DISCOVERY_URI ,
147
+ default = DISCOVERY_URI_TEMPLATE ,
146
148
help = "URI Template for discovery." ,
147
149
)
148
150
@@ -390,7 +392,11 @@ def document_collection_recursive(
390
392
391
393
392
394
def document_api (
393
- name , version , uri , doc_destination_dir , artifact_destination_dir = DISCOVERY_DOC_DIR
395
+ name ,
396
+ version ,
397
+ uri ,
398
+ doc_destination_dir ,
399
+ artifact_destination_dir = DISCOVERY_DOC_DIR ,
394
400
):
395
401
"""Document the given API.
396
402
@@ -400,16 +406,11 @@ def document_api(
400
406
uri (str): URI of the API's discovery document
401
407
doc_destination_dir (str): relative path where the reference
402
408
documentation should be saved.
403
- artifact_destination_dir (str): relative path where the discovery
409
+ artifact_destination_dir (Optional[ str] ): relative path where the discovery
404
410
artifacts should be saved.
405
411
"""
406
412
http = build_http ()
407
- resp , content = http .request (
408
- uri
409
- or uritemplate .expand (
410
- FLAGS .discovery_uri_template , {"api" : name , "apiVersion" : version }
411
- )
412
- )
413
+ resp , content = http .request (uri )
413
414
414
415
if resp .status == 200 :
415
416
discovery = json .loads (content )
@@ -494,26 +495,33 @@ def generate_all_api_documents(
494
495
directory_uri = DIRECTORY_URI ,
495
496
doc_destination_dir = BASE ,
496
497
artifact_destination_dir = DISCOVERY_DOC_DIR ,
498
+ discovery_uri_template = DISCOVERY_URI_TEMPLATE ,
497
499
):
498
500
"""Retrieve discovery artifacts and fetch reference documentations
499
501
for all apis listed in the public discovery directory.
500
502
args:
501
- directory_uri (str): uri of the public discovery directory.
502
- doc_destination_dir (str): relative path where the reference
503
+ directory_uri (Optional[ str] ): uri of the public discovery directory.
504
+ doc_destination_dir (Optional[ str] ): relative path where the reference
503
505
documentation should be saved.
504
- artifact_destination_dir (str): relative path where the discovery
506
+ artifact_destination_dir (Optional[ str] ): relative path where the discovery
505
507
artifacts should be saved.
508
+ discovery_uri_template (Optional[str]): URI template of the API's discovery
509
+ document.
506
510
"""
507
511
api_directory = collections .defaultdict (list )
508
512
http = build_http ()
509
513
resp , content = http .request (directory_uri )
510
514
if resp .status == 200 :
511
515
directory = json .loads (content )["items" ]
512
516
for api in directory :
517
+ uri = uritemplate .expand (
518
+ discovery_uri_template or api ["discoveryRestUrl" ],
519
+ {"api" : api ["name" ], "apiVersion" : api ["version" ]},
520
+ )
513
521
document_api (
514
522
api ["name" ],
515
523
api ["version" ],
516
- api [ "discoveryRestUrl" ] ,
524
+ uri ,
517
525
doc_destination_dir ,
518
526
artifact_destination_dir ,
519
527
)
@@ -555,4 +563,5 @@ def generate_all_api_documents(
555
563
generate_all_api_documents (
556
564
directory_uri = FLAGS .directory_uri ,
557
565
doc_destination_dir = FLAGS .dest ,
566
+ discovery_uri_template = FLAGS .discovery_uri_template ,
558
567
)
0 commit comments