diff --git a/generator/internal/stub_generator.cc b/generator/internal/stub_generator.cc index d8a992e9ce9a..06292aeda736 100644 --- a/generator/internal/stub_generator.cc +++ b/generator/internal/stub_generator.cc @@ -77,9 +77,14 @@ Status StubGenerator::GenerateHeader() { std::vector mixin_headers = absl::StrSplit(vars("mixin_proto_grpc_header_paths"), ','); HeaderSystemIncludes(mixin_headers); + bool include_lro_header = + HasLongrunningMethod() && + std::find(mixin_headers.begin(), mixin_headers.end(), + "google/longrunning/operations.grpc.pb.h") == + mixin_headers.end(); HeaderSystemIncludes( {vars("proto_grpc_header_path"), - HasLongrunningMethod() ? "google/longrunning/operations.grpc.pb.h" : "", + include_lro_header ? "google/longrunning/operations.grpc.pb.h" : "", "memory", "utility"}); auto result = HeaderOpenNamespaces(NamespaceType::kInternal); diff --git a/generator/internal/stub_rest_generator.cc b/generator/internal/stub_rest_generator.cc index 97e876e07b9f..2921d5090ea3 100644 --- a/generator/internal/stub_rest_generator.cc +++ b/generator/internal/stub_rest_generator.cc @@ -58,11 +58,15 @@ Status StubRestGenerator::GenerateHeader() { std::vector mixin_headers = absl::StrSplit(vars("mixin_proto_header_paths"), ','); HeaderSystemIncludes(mixin_headers); - HeaderSystemIncludes({vars("proto_header_path"), - HasLongrunningMethod() - ? vars("longrunning_operation_include_header") - : "", - "memory"}); + bool include_lro_header = + HasLongrunningMethod() && + std::find(mixin_headers.begin(), mixin_headers.end(), + vars("longrunning_operation_include_header")) == + mixin_headers.end(); + HeaderSystemIncludes( + {vars("proto_header_path"), + include_lro_header ? vars("longrunning_operation_include_header") : "", + "memory"}); auto result = HeaderOpenNamespaces(NamespaceType::kInternal); if (!result.ok()) return result;