entproto: support field.JSON with int slices
- Dominant language
- Go
- Stars
- 17.2k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
Earlier, [support for `field.Strings`](https://github.com/ent/contrib/pull/285) was introduced and it would be great, to also have support for integer slices. There has been [a similar attempt](https://github.com/ent/contrib/pull/414) but the PR is closed. I'd like to pick this up again.
- [x] I have searched the [issues](https://github.com/ent/ent/issues) of this repository and believe that this is not a duplicate.
## Summary 💡
I think, instead of supporting `field.Ints` and translating between `int` and the protobuf's `int64`, it would make sense to use `field.JSON` and only support types that match protobuf's supported integer types like:
```
func (MessageWithInts) Fields() []ent.Field {
return []ent.Field{
field.JSON("int32s", []int32{}).Annotations(entproto.Field(2)),
field.JSON("int64s", []int64{}).Annotations(entproto.Field(3)),
field.JSON("uint32s", []uint32{}).Annotations(entproto.Field(4)),
field.JSON("uint64s", []uint64{}).Annotations(entproto.Field(5)),
}
}
```
The changes are similar to what was done for `field.Strings`. However, it's additionally required to [reset the field converter](https://github.com/ent/contrib/blob/4a4cd3b02de86d54d0c9ff08b02aaae13dfb2d37/entproto/cmd/protoc-gen-entgrpc/converter.go#L118) in the `serviceGenerator` to avoid generating services that attempt to do things like `x := int64([]int64)`.
## Motivation 🔦
Support integer slices for protobuf and gRPC service generation.
Contributor guide
Research direction
Review the existing field.Strings support and the linked closed attempt, then inspect entproto/cmd/protoc-gen-entgrpc/converter.go, especially serviceGenerator and its field converter handling. Verify that the listed JSON integer slice types are supported in protobuf and gRPC service generation without invalid conversions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, grpc
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100