Retrieve discovery artifacts and fetch reference documentations for all apis listed in the public discovery directory. args: directory_uri (Optional[str]): uri of the public discovery directory. doc_destination_dir (Optional[str]): relative path where the reference
(
directory_uri=DIRECTORY_URI,
doc_destination_dir=BASE,
artifact_destination_dir=DISCOVERY_DOC_DIR,
discovery_uri_template=DISCOVERY_URI_TEMPLATE,
)
| 492 | |
| 493 | |
| 494 | def generate_all_api_documents( |
| 495 | directory_uri=DIRECTORY_URI, |
| 496 | doc_destination_dir=BASE, |
| 497 | artifact_destination_dir=DISCOVERY_DOC_DIR, |
| 498 | discovery_uri_template=DISCOVERY_URI_TEMPLATE, |
| 499 | ): |
| 500 | """Retrieve discovery artifacts and fetch reference documentations |
| 501 | for all apis listed in the public discovery directory. |
| 502 | args: |
| 503 | directory_uri (Optional[str]): uri of the public discovery directory. |
| 504 | doc_destination_dir (Optional[str]): relative path where the reference |
| 505 | documentation should be saved. |
| 506 | artifact_destination_dir (Optional[str]): relative path where the discovery |
| 507 | artifacts should be saved. |
| 508 | discovery_uri_template (Optional[str]): URI template of the API's discovery |
| 509 | document. |
| 510 | """ |
| 511 | api_directory = collections.defaultdict(list) |
| 512 | http = build_http() |
| 513 | resp, content = http.request(directory_uri) |
| 514 | if resp.status == 200: |
| 515 | directory = json.loads(content)["items"] |
| 516 | for api in directory: |
| 517 | uri = uritemplate.expand( |
| 518 | discovery_uri_template or api["discoveryRestUrl"], |
| 519 | {"api": api["name"], "apiVersion": api["version"]}, |
| 520 | ) |
| 521 | document_api( |
| 522 | api["name"], |
| 523 | api["version"], |
| 524 | uri, |
| 525 | doc_destination_dir, |
| 526 | artifact_destination_dir, |
| 527 | ) |
| 528 | api_directory[api["name"]].append(api["version"]) |
| 529 | |
| 530 | # sort by api name and version number |
| 531 | for api in api_directory: |
| 532 | api_directory[api] = sorted(api_directory[api]) |
| 533 | api_directory = collections.OrderedDict( |
| 534 | sorted(api_directory.items(), key=lambda x: x[0]) |
| 535 | ) |
| 536 | |
| 537 | markdown = [] |
| 538 | for api, versions in api_directory.items(): |
| 539 | markdown.append("## %s" % api) |
| 540 | for version in versions: |
| 541 | markdown.append( |
| 542 | "* [%s](http://googleapis.github.io/google-api-python-client/docs/dyn/%s_%s.html)" |
| 543 | % (version, api, safe_version(version)) |
| 544 | ) |
| 545 | markdown.append("\n") |
| 546 | |
| 547 | with open(doc_destination_dir / "index.md", "w") as f: |
| 548 | markdown = "\n".join(markdown) |
| 549 | f.write(markdown) |
| 550 | |
| 551 | else: |
no test coverage detected
searching dependent graphs…