136136
137137BASE = pathlib .Path (__file__ ).resolve ().parent / "docs" / "dyn"
138138
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"
140142
141143parser = argparse .ArgumentParser (description = __doc__ )
142144
143145parser .add_argument (
144146 "--discovery_uri_template" ,
145- default = DISCOVERY_URI ,
147+ default = DISCOVERY_URI_TEMPLATE ,
146148 help = "URI Template for discovery." ,
147149)
148150
@@ -390,7 +392,11 @@ def document_collection_recursive(
390392
391393
392394def 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 ,
394400):
395401 """Document the given API.
396402
@@ -400,16 +406,11 @@ def document_api(
400406 uri (str): URI of the API's discovery document
401407 doc_destination_dir (str): relative path where the reference
402408 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
404410 artifacts should be saved.
405411 """
406412 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 )
413414
414415 if resp .status == 200 :
415416 discovery = json .loads (content )
@@ -494,26 +495,33 @@ def generate_all_api_documents(
494495 directory_uri = DIRECTORY_URI ,
495496 doc_destination_dir = BASE ,
496497 artifact_destination_dir = DISCOVERY_DOC_DIR ,
498+ discovery_uri_template = DISCOVERY_URI_TEMPLATE ,
497499):
498500 """Retrieve discovery artifacts and fetch reference documentations
499501 for all apis listed in the public discovery directory.
500502 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
503505 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
505507 artifacts should be saved.
508+ discovery_uri_template (Optional[str]): URI template of the API's discovery
509+ document.
506510 """
507511 api_directory = collections .defaultdict (list )
508512 http = build_http ()
509513 resp , content = http .request (directory_uri )
510514 if resp .status == 200 :
511515 directory = json .loads (content )["items" ]
512516 for api in directory :
517+ uri = uritemplate .expand (
518+ discovery_uri_template or api ["discoveryRestUrl" ],
519+ {"api" : api ["name" ], "apiVersion" : api ["version" ]},
520+ )
513521 document_api (
514522 api ["name" ],
515523 api ["version" ],
516- api [ "discoveryRestUrl" ] ,
524+ uri ,
517525 doc_destination_dir ,
518526 artifact_destination_dir ,
519527 )
@@ -555,4 +563,5 @@ def generate_all_api_documents(
555563 generate_all_api_documents (
556564 directory_uri = FLAGS .directory_uri ,
557565 doc_destination_dir = FLAGS .dest ,
566+ discovery_uri_template = FLAGS .discovery_uri_template ,
558567 )
0 commit comments