Skip to content

Commit

Permalink
fix: Revert proto import order workaround
Browse files Browse the repository at this point in the history
This commit restores proto imports in the intended order, undoing the
workaround in #108 due
to protobufjs/protobuf.js#1954 now that the
solution protobufjs/protobuf.js#1960 is
implemented.
  • Loading branch information
vchudnov-g committed Jul 31, 2024
1 parent 5be8b3d commit ba5302b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,6 @@ public void writeToFile(PrintWriter writer, ProtoFile protoFile, boolean outputC

writer.println("package " + metadata.getProtoPkg() + ";\n");

// TODO: Place this import in the right alphabetical order. We are placing it here for now to
// work around an apparent bug in protobuf.js, where having this particular import be the last
// one makes the file not actually be imported.
// FIXME: --^
if (protoFile.HasAnyFields()) {
writer.println("import \"google/protobuf/any.proto\";");
}
if (protoFile.UsesStructProto()) {
writer.println("import \"google/protobuf/struct.proto\";");
}

writer.println("import \"google/api/annotations.proto\";");
writer.println("import \"google/api/client.proto\";");
writer.println("import \"google/api/field_behavior.proto\";");
Expand All @@ -64,6 +53,14 @@ public void writeToFile(PrintWriter writer, ProtoFile protoFile, boolean outputC
if (protoFile.isHasLroDefinitions()) {
writer.println("import \"google/cloud/extended_operations.proto\";");
}

if (protoFile.HasAnyFields()) {
writer.println("import \"google/protobuf/any.proto\";");
}
if (protoFile.UsesStructProto()) {
writer.println("import \"google/protobuf/struct.proto\";");
}

writer.println();

// File Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,13 @@ public void convertAnyFieldInError() throws IOException {
Paths.get(
"src", "test", "resources", prefix.toString(), "compute.error-any.proto.baseline");
String baselineBody = readFile(baselineFilePath);

System.out.printf(
"*** @Test:convertAnyFieldInError():\n Discovery path: %s\n Generated file: %s\n Baseline file: %s\n",
discoveryDocPath.toAbsolutePath(),
generatedFilePath.toAbsolutePath(),
baselineFilePath.toAbsolutePath());

assertEquals(baselineBody, actualBody);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ syntax = "proto3";

package google.cloud.compute.v1small;

import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/extended_operations.proto";
import "google/protobuf/any.proto";
import "google/protobuf/struct.proto";

//
// File Options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ syntax = "proto3";

package google.cloud.compute.v1small;

import "google/protobuf/any.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/cloud/extended_operations.proto";
import "google/protobuf/any.proto";

//
// File Options
Expand Down

0 comments on commit ba5302b

Please sign in to comment.