Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add links to rpc and rest documentation in repo-metadata.json #9913

Merged
merged 1 commit into from Sep 28, 2023

Conversation

alicejli
Copy link
Contributor

@alicejli alicejli commented Sep 28, 2023

As part of updating overviews in Cloud RAD, we would like to link to the language-agnostic RPC / REST documentation for each module if it exists.

That documentation is generated via a totally separate process from client library generation, so coverage is spotty and there are lots of inconsistencies in directory naming. Therefore, it isn't pruduct to assume all modules have RPC/REST documentation.
This is an initial population of URIs for REST / RPC reference that exist. Ongoing maintenance / population of these URIs to be discussed in future discussion about repo-metadata.json maintenance.

Sample script that parses each repo-metadata.json file for a product_documentation URI, creates a generic RPC/REST variation, curls it to see if it exists, and then writes it back if it does:

#!/bin/bash

# Find all .repo-metadata.json files in the current directory and its subdirectories
find . -type f -name '.repo-metadata.json' | while read -r file; do
    # Extract product_documentation values from each file
    product_documentation=$(jq -r '.product_documentation' "$file")

    # Form new documentation URLs
    if [[ "$product_documentation" == *"docs/" ]]; then
        rest_documentation="${product_documentation}reference/rest"
        rpc_documentation="${product_documentation}reference/rpc"
    elif [[ "$product_documentation" == *"docs" ]]; then
        # Add "/reference/rest" to product_documentation
        rest_documentation="${product_documentation}/reference/rest"
        rpc_documentation="${product_documentation}/reference/rpc"
    elif [[ "$product_documentation" == *"/" ]]; then
      rest_documentation="${product_documentation}docs/reference/rest"
      rpc_documentation="${product_documentation}docs/reference/rpc"
    else
        rest_documentation="${product_documentation}/docs/reference/rest"
        rpc_documentation="${product_documentation}/docs/reference/rpc"
    fi

    # Send HTTP requests and get status codes for rest and rpc documentation URLs
    http_status_rest=$(curl -o /dev/null -s -w "%{http_code}" "$rest_documentation")
    http_status_rpc=$(curl -o /dev/null -s -w "%{http_code}" "$rpc_documentation")

    # Build jq command to update the JSON file if the status code is 200
    jq_cmd='.'
    if [[ "$http_status_rest" -eq 200 ]]; then
        jq_cmd+=' | . + {rest_documentation: $rest_doc}'
    fi
    if [[ "$http_status_rpc" -eq 200 ]]; then
        jq_cmd+=' | . + {rpc_documentation: $rpc_doc}'
    fi

    # Update the .repo-metadata.json file with rest_documentation and rpc_documentation fields
    jq --arg rest_doc "$rest_documentation" --arg rpc_doc "$rpc_documentation" "$jq_cmd" "$file" > temp.json && mv temp.json "$file"
done

Out of 162 repo-metadata.json files, 124 had valid product_documentation links (e.g. return http status = 200).

Out of those, these are the repos containing either (or both) an invalid rpc/rest documentation link based on the generic URI variation: https://paste.googleplex.com/5546150802227200

@alicejli alicejli marked this pull request as ready for review September 28, 2023 16:14
@burkedavison
Copy link
Contributor

💯

@alicejli alicejli added the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 28, 2023
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Sep 28, 2023
@alicejli alicejli merged commit 453c1b7 into main Sep 28, 2023
30 checks passed
@alicejli alicejli deleted the addRpcRestDocumentationURI branch September 28, 2023 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants