From f0d8ae675a35d4ea3a413c96df1038df401886e6 Mon Sep 17 00:00:00 2001 From: Victor Chudnovsky Date: Tue, 5 Dec 2023 15:52:24 -0800 Subject: [PATCH] fix(temporary): reorder imports to work around protobuf.js problem Apparently protobuf.js is not currently importing the Any type when any.proto is last in the import list, but the import does work if any.proto is higher in the import list. Pending a fix for this in protobuf.js, this change imports any.proto earlier to avoid triggering the problem. When protobuf.js if fixed, we can revert the change. --- .../discotoproto3converter/proto3/Proto3Writer.java | 10 +++++++--- .../compute/v1small/compute.error-any.proto.baseline | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/cloud/discotoproto3converter/proto3/Proto3Writer.java b/src/main/java/com/google/cloud/discotoproto3converter/proto3/Proto3Writer.java index 8d8ca30..aa77c9b 100644 --- a/src/main/java/com/google/cloud/discotoproto3converter/proto3/Proto3Writer.java +++ b/src/main/java/com/google/cloud/discotoproto3converter/proto3/Proto3Writer.java @@ -45,6 +45,13 @@ 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. + if (protoFile.HasAnyFields()) { + writer.println("import \"google/protobuf/any.proto\";"); + } + writer.println("import \"google/api/annotations.proto\";"); writer.println("import \"google/api/client.proto\";"); writer.println("import \"google/api/field_behavior.proto\";"); @@ -53,9 +60,6 @@ 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\";"); - } writer.println(); // File Options diff --git a/src/test/resources/google/cloud/compute/v1small/compute.error-any.proto.baseline b/src/test/resources/google/cloud/compute/v1small/compute.error-any.proto.baseline index 1c12c73..ac2495a 100644 --- a/src/test/resources/google/cloud/compute/v1small/compute.error-any.proto.baseline +++ b/src/test/resources/google/cloud/compute/v1small/compute.error-any.proto.baseline @@ -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