Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
127 changes: 127 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,15 @@

BASE = pathlib.Path(__file__).resolve().parent / "docs" / "dyn"

DIRECTORY_URI = "https://www.googleapis.com/discovery/v1/apis"
# Obtain the discovery index and artifacts from googleapis/discovery-artifact-manager
DIRECTORY_URI = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/index.json"
DISCOVERY_URI_TEMPLATE = "https://raw.githubusercontent.com/googleapis/discovery-artifact-manager/master/discoveries/{api}.{apiVersion}.json"

parser = argparse.ArgumentParser(description=__doc__)

parser.add_argument(
"--discovery_uri_template",
default=DISCOVERY_URI,
default=DISCOVERY_URI_TEMPLATE,
help="URI Template for discovery.",
)

Expand Down Expand Up @@ -390,7 +392,11 @@ def document_collection_recursive(


def document_api(
name, version, uri, doc_destination_dir, artifact_destination_dir=DISCOVERY_DOC_DIR
name,
version,
uri,
doc_destination_dir,
artifact_destination_dir=DISCOVERY_DOC_DIR,
):
"""Document the given API.

Expand All @@ -400,16 +406,11 @@ def document_api(
uri (str): URI of the API's discovery document
doc_destination_dir (str): relative path where the reference
documentation should be saved.
artifact_destination_dir (str): relative path where the discovery
artifact_destination_dir (Optional[str]): relative path where the discovery
artifacts should be saved.
"""
http = build_http()
resp, content = http.request(
uri
or uritemplate.expand(
FLAGS.discovery_uri_template, {"api": name, "apiVersion": version}
)
)
resp, content = http.request(uri)

if resp.status == 200:
discovery = json.loads(content)
Expand Down Expand Up @@ -494,26 +495,33 @@ def generate_all_api_documents(
directory_uri=DIRECTORY_URI,
doc_destination_dir=BASE,
artifact_destination_dir=DISCOVERY_DOC_DIR,
discovery_uri_template=DISCOVERY_URI_TEMPLATE,
):
"""Retrieve discovery artifacts and fetch reference documentations
for all apis listed in the public discovery directory.
args:
directory_uri (str): uri of the public discovery directory.
doc_destination_dir (str): relative path where the reference
directory_uri (Optional[str]): uri of the public discovery directory.
doc_destination_dir (Optional[str]): relative path where the reference
documentation should be saved.
artifact_destination_dir (str): relative path where the discovery
artifact_destination_dir (Optional[str]): relative path where the discovery
artifacts should be saved.
discovery_uri_template (Optional[str]): URI template of the API's discovery
document.
"""
api_directory = collections.defaultdict(list)
http = build_http()
resp, content = http.request(directory_uri)
if resp.status == 200:
directory = json.loads(content)["items"]
for api in directory:
uri = uritemplate.expand(
discovery_uri_template or api["discoveryRestUrl"],
{"api": api["name"], "apiVersion": api["version"]},
)
document_api(
api["name"],
api["version"],
api["discoveryRestUrl"],
uri,
doc_destination_dir,
artifact_destination_dir,
)
Expand Down Expand Up @@ -555,4 +563,5 @@ def generate_all_api_documents(
generate_all_api_documents(
directory_uri=FLAGS.directory_uri,
doc_destination_dir=FLAGS.dest,
discovery_uri_template=FLAGS.discovery_uri_template,
)
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ <h3>Method Details</h3>
],
&quot;vpcNetworkSources&quot;: [ # The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.
{ # The originating network source in Google Cloud.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network. TODO (b/332744441): annotate this field with custom_org_policy_accessibility when cl/640698580 will be rolled out.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network.
&quot;network&quot;: &quot;A String&quot;, # Required. Network name. If the network is not part of the organization, the `compute.network.get` permission must be granted to the caller. Format: `//compute.googleapis.com/projects/{PROJECT_ID}/global/networks/{NETWORK_NAME}` Example: `//compute.googleapis.com/projects/my-project/global/networks/network-1`
&quot;vpcIpSubnetworks&quot;: [ # CIDR block IP subnetwork specification. The IP address must be an IPv4 address and can be a public or private IP address. Note that for a CIDR IP address block, the specified IP address portion must be properly truncated (i.e. all the host bits must be zero) or the input is considered malformed. For example, &quot;192.0.2.0/24&quot; is accepted but &quot;192.0.2.1/24&quot; is not. If empty, all IP addresses are allowed.
&quot;A String&quot;,
Expand Down Expand Up @@ -299,7 +299,7 @@ <h3>Method Details</h3>
],
&quot;vpcNetworkSources&quot;: [ # The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.
{ # The originating network source in Google Cloud.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network. TODO (b/332744441): annotate this field with custom_org_policy_accessibility when cl/640698580 will be rolled out.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network.
&quot;network&quot;: &quot;A String&quot;, # Required. Network name. If the network is not part of the organization, the `compute.network.get` permission must be granted to the caller. Format: `//compute.googleapis.com/projects/{PROJECT_ID}/global/networks/{NETWORK_NAME}` Example: `//compute.googleapis.com/projects/my-project/global/networks/network-1`
&quot;vpcIpSubnetworks&quot;: [ # CIDR block IP subnetwork specification. The IP address must be an IPv4 address and can be a public or private IP address. Note that for a CIDR IP address block, the specified IP address portion must be properly truncated (i.e. all the host bits must be zero) or the input is considered malformed. For example, &quot;192.0.2.0/24&quot; is accepted but &quot;192.0.2.1/24&quot; is not. If empty, all IP addresses are allowed.
&quot;A String&quot;,
Expand Down Expand Up @@ -385,7 +385,7 @@ <h3>Method Details</h3>
],
&quot;vpcNetworkSources&quot;: [ # The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.
{ # The originating network source in Google Cloud.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network. TODO (b/332744441): annotate this field with custom_org_policy_accessibility when cl/640698580 will be rolled out.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network.
&quot;network&quot;: &quot;A String&quot;, # Required. Network name. If the network is not part of the organization, the `compute.network.get` permission must be granted to the caller. Format: `//compute.googleapis.com/projects/{PROJECT_ID}/global/networks/{NETWORK_NAME}` Example: `//compute.googleapis.com/projects/my-project/global/networks/network-1`
&quot;vpcIpSubnetworks&quot;: [ # CIDR block IP subnetwork specification. The IP address must be an IPv4 address and can be a public or private IP address. Note that for a CIDR IP address block, the specified IP address portion must be properly truncated (i.e. all the host bits must be zero) or the input is considered malformed. For example, &quot;192.0.2.0/24&quot; is accepted but &quot;192.0.2.1/24&quot; is not. If empty, all IP addresses are allowed.
&quot;A String&quot;,
Expand Down Expand Up @@ -474,7 +474,7 @@ <h3>Method Details</h3>
],
&quot;vpcNetworkSources&quot;: [ # The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.
{ # The originating network source in Google Cloud.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network. TODO (b/332744441): annotate this field with custom_org_policy_accessibility when cl/640698580 will be rolled out.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network.
&quot;network&quot;: &quot;A String&quot;, # Required. Network name. If the network is not part of the organization, the `compute.network.get` permission must be granted to the caller. Format: `//compute.googleapis.com/projects/{PROJECT_ID}/global/networks/{NETWORK_NAME}` Example: `//compute.googleapis.com/projects/my-project/global/networks/network-1`
&quot;vpcIpSubnetworks&quot;: [ # CIDR block IP subnetwork specification. The IP address must be an IPv4 address and can be a public or private IP address. Note that for a CIDR IP address block, the specified IP address portion must be properly truncated (i.e. all the host bits must be zero) or the input is considered malformed. For example, &quot;192.0.2.0/24&quot; is accepted but &quot;192.0.2.1/24&quot; is not. If empty, all IP addresses are allowed.
&quot;A String&quot;,
Expand Down Expand Up @@ -577,7 +577,7 @@ <h3>Method Details</h3>
],
&quot;vpcNetworkSources&quot;: [ # The request must originate from one of the provided VPC networks in Google Cloud. Cannot specify this field together with `ip_subnetworks`.
{ # The originating network source in Google Cloud.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network. TODO (b/332744441): annotate this field with custom_org_policy_accessibility when cl/640698580 will be rolled out.
&quot;vpcSubnetwork&quot;: { # Sub-segment ranges inside of a VPC Network. # Sub-segment ranges of a VPC network.
&quot;network&quot;: &quot;A String&quot;, # Required. Network name. If the network is not part of the organization, the `compute.network.get` permission must be granted to the caller. Format: `//compute.googleapis.com/projects/{PROJECT_ID}/global/networks/{NETWORK_NAME}` Example: `//compute.googleapis.com/projects/my-project/global/networks/network-1`
&quot;vpcIpSubnetworks&quot;: [ # CIDR block IP subnetwork specification. The IP address must be an IPv4 address and can be a public or private IP address. Note that for a CIDR IP address block, the specified IP address portion must be properly truncated (i.e. all the host bits must be zero) or the input is considered malformed. For example, &quot;192.0.2.0/24&quot; is accepted but &quot;192.0.2.1/24&quot; is not. If empty, all IP addresses are allowed.
&quot;A String&quot;,
Expand Down
Loading