You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

集成protovalidate后推送Proto描述符至Google API Gateway遇无效描述符错误

集成protovalidate后推送描述符至Google API Gateway报错问题

我在构建部署于Google API Gateway的API时,为实现请求验证集成了protovalidate,但推送proto描述符至API Gateway时触发以下错误:

Error: Error creating ApiConfig: googleapi: Error 400: Invalid file descriptor set "./../../api-config/build/descriptors/api_descriptor.pb": generic::invalid_argument: Invalid file descriptor set "./../../api-config/build/descriptors/api_descriptor.pb": proto: message field "buf.validate.FieldPathElement.field_type" cannot resolve type: "google.protobuf.FieldDescriptorProto.Type" not found

使用Gradle构建描述符,即使手动运行protoc并显式引入google.protobuf.descriptor.proto仍会报错;只要构建中包含protovalidate依赖,即便未在proto文件中使用它,也会触发该问题。

当前Gradle配置文件(部分代码已注释以缩小排查范围):

import com.google.protobuf.gradle.*
import java.nio.file.Paths

plugins {
    id("kotlin")
    id("com.google.protobuf")
}

repositories {
    mavenCentral()
}

// ---- Versions ----
val protobufVersion = "4.31.1"
val grpcVersion = "1.71.0"
val grpcKotlinVersion = "1.4.3"
val protoValidateVersion = "0.12.0"

dependencies {
    // api("io.grpc:grpc-kotlin-stub:$grpcKotlinVersion")
    // api("com.google.protobuf:protobuf-kotlin:$protobufVersion")
    api("com.google.protobuf:protobuf-java:$protobufVersion")

    // implementation("io.grpc:grpc-protobuf:$grpcVersion")

    protobuf("com.google.api.grpc:proto-google-common-protos:2.41.0") // has google/api/*.proto
    // protobuf("com.google.protobuf:protoc:$protobufVersion")
    protobuf("build.buf:protovalidate:$protoValidateVersion")
}

sourceSets {
    named("main") {
        proto {
            srcDir("$projectDir/proto")   
            include("**.*.proto")
        }
    }
}

protobuf {
    protoc { artifact = "com.google.protobuf:protoc:$protobufVersion" }
    plugins {
        // create("grpc")   { artifact = "io.grpc:protoc-gen-grpc-java:$grpcVersion" }
        // create("grpckt") { artifact = "io.grpc:protoc-gen-grpc-kotlin:$grpcKotlinVersion:jdk8@jar" }
    }
    generateProtoTasks {
        all().configureEach {
            // Kotlin message classes
            // builtins { 
                // create("kotlin")
            // }

            // JVM/Kotlin stubs
            // plugins {
                // create("grpc")
                // create("grpckt")
            // }

            // Produce a descriptor set we can hand to Terraform
            
            this as GenerateProtoTask
            generateDescriptorSet = true
            descriptorSetOptions.apply {
                path = "$buildDir/descriptors/api_descriptor.pb"
                includeImports = true
                includeSourceInfo = true
            }
        }
    }
}

已尝试以下操作但均未解决问题:

  • 直接使用protoc构建描述符
  • 显式引入google.protobuf库
  • 显式引入google.protobuf.descriptor文件作为源

移除protovalidate依赖可解决错误,但无法使用其验证功能,寻求可行的解决方案。

内容的提问来源于stack exchange,提问作者John McGowan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 10:33:12