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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions generator/integration_tests/test2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

type: google.api.Service
config_version: 3
name: test.googleapis.com
title: Test2

apis:
- name: google.test.rest.only.v1.GoldenRestOnly
21 changes: 21 additions & 0 deletions generator/integration_tests/test_deprecated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2025 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

type: google.api.Service
config_version: 3
name: test.googleapis.com
title: Test Deprecated

apis:
- name: google.test.deprecated.v1.DeprecatedService
60 changes: 37 additions & 23 deletions generator/internal/scaffold_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -326,44 +326,59 @@ void GenerateMetadata(
void GenerateScaffold(
std::map<std::string, std::string> const& vars,
std::string const& scaffold_templates_path, std::string const& output_path,
google::cloud::cpp::generator::ServiceConfiguration const& service) {
google::cloud::cpp::generator::ServiceConfiguration const& service,
ScaffoldFiles scaffold_files) {
using Generator = std::function<void(
std::ostream&, std::map<std::string, std::string> const&)>;
struct Destination {
std::string name;
Generator generator;
} files[] = {
{"README.md", GenerateReadme},
{"BUILD.bazel", GenerateBuild},
{"CMakeLists.txt", GenerateCMakeLists},
{"doc/main.dox", GenerateDoxygenMainPage},
{"doc/environment-variables.dox", GenerateDoxygenEnvironmentPage},
{"doc/override-authentication.dox", GenerateOverrideAuthenticationPage},
{"doc/override-endpoint.dox", GenerateOverrideEndpointPage},
{"doc/override-retry-policies.dox", GenerateOverrideRetryPoliciesPage},
{"doc/options.dox", GenerateDoxygenOptionsPage},
{"quickstart/README.md", GenerateQuickstartReadme},
{"quickstart/quickstart.cc", GenerateQuickstartSkeleton},
{"quickstart/CMakeLists.txt", GenerateQuickstartCMake},
{"quickstart/Makefile", GenerateQuickstartMakefile},
{"quickstart/BUILD.bazel", GenerateQuickstartBuild},
{"quickstart/.bazelrc", GenerateQuickstartBazelrc},
};

MakeDirectory(output_path + "/");
auto const destination =
output_path + "/" + LibraryPath(service.product_path());
MakeDirectory(destination);
MakeDirectory(destination + "doc/");
MakeDirectory(destination + "quickstart/");

std::vector<Destination> files;
if (scaffold_files == ScaffoldFiles::kDocDir) {
files = {
{"doc/environment-variables.dox", GenerateDoxygenEnvironmentPage},
{"doc/override-authentication.dox", GenerateOverrideAuthenticationPage},
{"doc/override-endpoint.dox", GenerateOverrideEndpointPage},
{"doc/override-retry-policies.dox", GenerateOverrideRetryPoliciesPage},
{"doc/options.dox", GenerateDoxygenOptionsPage},
};
} else {
MakeDirectory(destination + "quickstart/");
files = {
{"README.md", GenerateReadme},
{"BUILD.bazel", GenerateBuild},
{"CMakeLists.txt", GenerateCMakeLists},
{"doc/main.dox", GenerateDoxygenMainPage},
{"doc/environment-variables.dox", GenerateDoxygenEnvironmentPage},
{"doc/override-authentication.dox", GenerateOverrideAuthenticationPage},
{"doc/override-endpoint.dox", GenerateOverrideEndpointPage},
{"doc/override-retry-policies.dox", GenerateOverrideRetryPoliciesPage},
{"doc/options.dox", GenerateDoxygenOptionsPage},
{"quickstart/README.md", GenerateQuickstartReadme},
{"quickstart/quickstart.cc", GenerateQuickstartSkeleton},
{"quickstart/CMakeLists.txt", GenerateQuickstartCMake},
{"quickstart/Makefile", GenerateQuickstartMakefile},
{"quickstart/BUILD.bazel", GenerateQuickstartBuild},
{"quickstart/.bazelrc", GenerateQuickstartBazelrc},
};
std::ifstream is(scaffold_templates_path + kWorkspaceTemplate);
auto const contents = std::string{std::istreambuf_iterator<char>(is), {}};
std::ofstream os(destination + "quickstart/WORKSPACE.bazel");
GenerateQuickstartWorkspace(os, vars, contents);
}
Comment on lines +344 to +376

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is code duplication in this if-else block. The list of documentation files to be generated (environment-variables.dox, override-authentication.dox, etc.) is present in both the if branch (lines 347-351) and the else branch (lines 360-364). To improve maintainability and avoid potential inconsistencies in the future, consider extracting this common list of files into a separate variable and using it in both branches.


for (auto const& f : files) {
std::ofstream os(destination + f.name);
f.generator(os, vars);
}
std::ifstream is(scaffold_templates_path + kWorkspaceTemplate);
auto const contents = std::string{std::istreambuf_iterator<char>(is), {}};
std::ofstream os(destination + "quickstart/WORKSPACE.bazel");
GenerateQuickstartWorkspace(os, vars, contents);
}

void GenerateReadme(std::ostream& os,
Expand Down Expand Up @@ -547,7 +562,6 @@ which should give you a taste of the $title$ C++ client library API.
void GenerateDoxygenEnvironmentPage(
std::ostream& os, std::map<std::string, std::string> const& variables) {
auto constexpr kText = R"""(/*!

@page $library$-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
8 changes: 7 additions & 1 deletion generator/internal/scaffold_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,17 @@ void GenerateMetadata(
google::cloud::cpp::generator::ServiceConfiguration const& service,
bool allow_placeholders);

enum class ScaffoldFiles {
kAll,
kDocDir, // Does not include main.dox due to all the hand edits.
};

/// Generates the build and documentation scaffold for @p service.
void GenerateScaffold(
std::map<std::string, std::string> const& vars,
std::string const& scaffold_templates_path, std::string const& output_path,
google::cloud::cpp::generator::ServiceConfiguration const& service);
google::cloud::cpp::generator::ServiceConfiguration const& service,
ScaffoldFiles = ScaffoldFiles::kAll);

///@{
/// @name Generators for each scaffold file.
Expand Down
21 changes: 21 additions & 0 deletions generator/standalone_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <google/protobuf/compiler/command_line_interface.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also to double check my understanding, is there were the doc generation logic lives?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dox file templates are generated from calling GenerateScaffold. Additional content is injected when update-library-landing-dox.sh is invoked.

#include <google/protobuf/text_format.h>
#include <algorithm>
#include <array>
#include <fstream>
#include <future>
#include <iostream>
Expand Down Expand Up @@ -231,6 +232,26 @@ std::vector<std::future<google::cloud::Status>> GenerateCodeFromProtos(
if (generate_scaffold) {
GenerateScaffold(scaffold_vars, generator_args.scaffold_templates_path,
generator_args.output_path, service);
} else {
static constexpr std::array<char const*, 4> kOmittedDocDirs = {
"google/cloud/bigtable", "google/cloud/compute",
"google/cloud/pubsub", "google/cloud/spanner"};

Comment on lines +243 to +246
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you provide some context into why these modules are being excluded?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments to document the rationale.

if (!service.omit_client() &&
!std::any_of(kOmittedDocDirs.begin(), kOmittedDocDirs.end(),
[&](auto s) {
// TODO(#15652): Remove when service is turned down.
if (absl::StartsWith(service.product_path(),
"google/cloud/pubsublite")) {
return false;
}
return absl::StartsWith(service.product_path(), s);
})) {
GenerateScaffold(
scaffold_vars, generator_args.scaffold_templates_path,
generator_args.output_path, service,
google::cloud::generator_internal::ScaffoldFiles::kDocDir);
}
Comment on lines +247 to +261

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic within this if condition, particularly the lambda passed to std::any_of, is a bit complex due to the special handling for pubsublite. To improve readability, I suggest separating the general check against kOmittedDocDirs from the special case logic for pubsublite.

      bool omit_doc_dir = std::any_of(
          kOmittedDocDirs.begin(), kOmittedDocDirs.end(),
          [&](auto s) { return absl::StartsWith(service.product_path(), s); });
      // TODO(#15652): Remove when service is turned down.
      if (absl::StartsWith(service.product_path(), "google/cloud/pubsublite")) {
        omit_doc_dir = false;
      }
      if (!service.omit_client() && !omit_doc_dir) {
        GenerateScaffold(
            scaffold_vars, generator_args.scaffold_templates_path,
            generator_args.output_path, service,
            google::cloud::generator_internal::ScaffoldFiles::kDocDir);
      }

}
if (!service.omit_repo_metadata()) {
GenerateMetadata(scaffold_vars, generator_args.output_path, service,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page accessapproval-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page accessapproval-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page accesscontextmanager-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page accesscontextmanager-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page advisorynotifications-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page advisorynotifications-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/aiplatform/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page aiplatform-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/aiplatform/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page aiplatform-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/alloydb/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page alloydb-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/alloydb/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page alloydb-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/apigateway/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apigateway-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/apigateway/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apigateway-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/apigeeconnect/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apigeeconnect-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apigeeconnect-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/apikeys/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apikeys-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/apikeys/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apikeys-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/appengine/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page appengine-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/appengine/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page appengine-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/apphub/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page apphub-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page artifactregistry-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page artifactregistry-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/asset/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page asset-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/asset/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page asset-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page assuredworkloads-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page assuredworkloads-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/automl/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page automl-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/automl/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page automl-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/backupdr/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page backupdr-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page baremetalsolution-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page baremetalsolution-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/batch/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page batch-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/batch/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page batch-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/beyondcorp/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page beyondcorp-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
1 change: 0 additions & 1 deletion google/cloud/beyondcorp/doc/override-retry-policies.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page beyondcorp-override-retry Override Retry, Backoff, and Idempotency Policies

When it is safe to do so, the library automatically retries requests that fail
Expand Down
1 change: 0 additions & 1 deletion google/cloud/bigquery/doc/environment-variables.dox
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/*!

@page bigquery-env Environment Variables

A number of environment variables can be used to configure the behavior of
Expand Down
Loading