To build and run this tool, you will need the following tools:
- JDK 8+
- Maven 3.3.9+
To build the standalone jar, run the following command from the repository root:
mvn packageTo run the unit tests, execute the following command:
mvn testTo automatically format the Java source files, use the following Bazel command:
bazelisk run :google_java_format --enable_workspaceNOTE: This project is pinned to Bazel 7.x to ensure compatibility with
its current build rules. A .bazelversion file is included in the
root directory. When using bazelisk, it will automatically download
and use the correct version.
After performing the build, you obtain the API protocol buffer file and GAPIC
configuration files derived from the sample compute.v1.json Discovery file
(included in this repository) by running the following command from the
repository root:
java \
-jar target/target/discovery-converter-app.jar \
--discovery_doc_path=src/test/resources/google/cloud/compute/v1/compute.v1.json \
--output_file_path=google/cloud/compute/v1/compute \
--input_config_path=src/test/resources/google/cloud/compute/v1/compute.v1.config.input.json \
--output_config_path=google/cloud/compute/v1/compute.v1.config.output.json \
--enums_as_strings=TrueCheck the google/cloud/compute/v1 directory for the resulting compute.proto,
compute_grpc_service_config.json, and compute_gapic.yaml files.
You can also generate each of the files above individually by using distinct generator binaries for each.
- To generate just
compute.proto, run:
java \
-jar target/target/disco-to-proto3-converter-app.jar \
--discovery_doc_path=src/test/resources/google/cloud/compute/v1/compute.v1.json \
--output_file_path=google/cloud/compute/v1/compute.proto \
--input_config_path=src/test/resources/google/cloud/compute/v1/compute.v1.config.input.json \
--output_config_path=google/cloud/compute/v1/compute.v1.config.output.json \
--enums_as_strings=TrueTo generate just compute_grpc_service_config.json, run:
java \
-jar target/service-config-generator-app.jar \
--discovery_doc_path=src/test/resources/google/cloud/compute/v1/compute.v1.json \
--output_file_path=google/cloud/compute/v1/compute_grpc_service_config.json \
--input_config_path=src/test/resources/google/cloud/compute/v1/compute.v1.config.input.json \
--output_config_path=google/cloud/compute/v1/compute.v1.config.output.json \
--enums_as_strings=TrueTo generate just compute_gapic.yaml, run:
java \
-jar target/gapic-yaml-generator-app.jar \
--discovery_doc_path=src/test/resources/google/cloud/compute/v1/compute.v1.json \
--output_file_path=google/cloud/compute/v1/compute_gapic.yaml \
--input_config_path=src/test/resources/google/cloud/compute/v1/compute.v1.config.input.json \
--output_config_path=google/cloud/compute/v1/compute.v1.config.output.json \
--enums_as_strings=TrueYou can package the converter in a Docker image and run it as follows:
-
To build the container, use an invocation like
docker build --no-cache -t disco-converter:test . -
If you need to inspect the container, run it with a shell entrypoint:
docker run --entrypoint /bin/bash -it disco-converter:test
-
To run the container in a manner similar to above, mount the local directories containing your input and output files. For example
docker run -v $(pwd):/apis converter:test \ --discovery_doc_path=/apis/src/test/resources/google/cloud/compute/v1/compute.v1.json \ --output_file_path=/apis/google/cloud/compute/v1/compute \ --input_config_path=/apis/src/test/resources/google/cloud/compute/v1/compute.v1.config.input.json \ --output_config_path=/apis/google/cloud/compute/v1/compute.v1.config.output.json \ --enums_as_strings=True
The converter can also be used from Bazel via the proto_from_disco bazel rule
like the following:
load(
"@com_google_disco_to_proto3_converter//rules_gapic:disco_to_proto.bzl",
"proto_from_disco",
)
proto_from_disco(
name = "compute",
src = "//:src/test/resources/compute.v1.json",
)This is not an officially supported Google product