googleapis/gapic-generator

Error on fields with `optional` keyword and `REQUIRED` annotation

aohren opened this issue · 3 comments

gapic-generator throw an error on fields that have both the protoe3 optional keyword and a (google.api.field_behavior) = REQUIRED annotation.

For example, given the following field definition in a .proto file:

  optional string language = 14 [(google.api.field_behavior) = REQUIRED];

gapic generation fails with the following error:

ERROR: toplevel: oneof field language cannot be required (in method google.ads.googleads.v5.services.KeywordPlanIdeaService.GenerateKeywordIdeas)
ERROR: toplevel: Unexpected exception:
java.lang.NullPointerException
	at com.google.api.codegen.config.MethodConfig.createFieldNameConfigs(MethodConfig.java:192)
	at com.google.api.codegen.config.GapicMethodConfig.createGapicMethodConfigFromProto(GapicMethodConfig.java:242)
	at com.google.api.codegen.config.GapicInterfaceConfig.createMethodConfigMap(GapicInterfaceConfig.java:259)
	at com.google.api.codegen.config.GapicInterfaceConfig.createInterfaceConfig(GapicInterfaceConfig.java:146)
	at com.google.api.codegen.config.GapicProductConfig.createInterfaceConfigMap(GapicProductConfig.java:732)
	at com.google.api.codegen.config.GapicProductConfig.create(GapicProductConfig.java:354)
	at com.google.api.codegen.gapic.GapicGeneratorApp.process(GapicGeneratorApp.java:213)
	at com.google.api.tools.framework.tools.GenericToolDriverBase.run(GenericToolDriverBase.java:90)
	at com.google.api.tools.framework.tools.ToolDriverBase.run(ToolDriverBase.java:73)
	at com.google.api.codegen.GeneratorMain.gapicGeneratorMain(GeneratorMain.java:338)
	at com.google.api.codegen.GeneratorMain.main(GeneratorMain.java:184)

The microgenerator GAPIC protoc plugins (e.g. gapic-generator-csharp, gapic-generator-python) allow this without error. Should this be allowed thru in gapic-generator or are those other projects allowing invalid protos?

This sounds like a question to escalate to @lukesneeringer .

We decided that this pattern should not be supported. I am going to close this bug.

I have googleapis/api-linter#641 to track this in the linter.