Skip to content

grpc/codegen: allow overriding proto json_name#3857

Merged
raphael merged 1 commit intogoadesign:v3from
ilCollez:v3
Dec 13, 2025
Merged

grpc/codegen: allow overriding proto json_name#3857
raphael merged 1 commit intogoadesign:v3from
ilCollez:v3

Conversation

@ilCollez
Copy link
Contributor

Summary

  • extend the DSL with Meta("proto:tag:json", ...) so designers can override the json_name emitted in generated protobuf definitions
  • plumb the metadata through grpc/codegen/protobuf.go, emitting [json_name = "..."] on both regular fields and oneof members when present
  • update the DSL documentation to mention the new metadata key and add unit tests that cover the option for structs and oneofs

Motivation

Some downstream consumers rely on protobuf JSON descriptors whose field names must diverge from the default lower_snake_case. Prior to this change there was no way to control the descriptor in Goa-generated protos without patching the generated files. The new metadata brings parity with the existing struct-tag overrides and keeps designs self-contained.

Example

DSL:

var Item = Type("Item", func() {
    Field(1, "ID", String, func() {
        Meta("proto:tag:json", "identifier")
    })
})

Generated .proto fragment

message Item {
    string id = 1 [json_name = "identifier"];
}

Generated Go struct (.pb.go)

type Item struct {
    Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"identifier,omitempty"`
}

@raphael
Copy link
Member

raphael commented Dec 13, 2025

Looks great, thank you!

@raphael raphael merged commit ad48ff2 into goadesign:v3 Dec 13, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants