Skip to content

Conversation

@TBXark
Copy link

@TBXark TBXark commented Nov 10, 2024

proto3 supports using optional fields to define optional fields, so google/protobuf/wrappers.proto does not need to be used. This will make the generated code more concise.

The EnableOptionLabel can enable this feature for a specific Message individually.

// EnableOptionalLabel enables the optional label in the generated protobuf message instead of google/protobuf/wrappers.proto
func EnableOptionalLabel() MessageOption {
	return func(msg *message) {
		msg.EnableOptionalLabel = true
	}
}

@TBXark TBXark changed the title feat: Add proto3 optional label support entproto: Add proto3 optional label support Nov 10, 2024
Copilot AI review requested due to automatic review settings November 19, 2025 20:29
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for proto3 optional field labels as an alternative to using google/protobuf/wrappers.proto for optional fields, resulting in more concise generated code.

  • Introduces EnableOptionalLabel() MessageOption to enable proto3 optional labels per message
  • Updates field descriptor generation to use proto3 optional labels when enabled
  • Maintains backward compatibility by keeping the feature opt-in

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
entproto/message.go Adds EnableOptionalLabel() MessageOption and corresponding struct field
entproto/adapter.go Implements optional label logic in field descriptor generation, adds optionalFieldLabel constant, and updates function signatures
entproto/service.go Updates function call to match new toProtoFieldDescriptor signature

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

func extractProtoTypeDetails(f *gen.Field, enableOptionalLabel bool) (fieldType, error) {
if f.Type.Type == field.TypeJSON {
return extractJSONDetails(f)
return extractJSONDetails(f) // repeat fields are not required for optional label.
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected 'repeat' to 'repeated' for grammatical accuracy.

Suggested change
return extractJSONDetails(f) // repeat fields are not required for optional label.
return extractJSONDetails(f) // repeated fields are not required for optional label.

Copilot uses AI. Check for mistakes.
func extractProtoTypeDetails(f *gen.Field, enableOptionalLabel bool) (fieldType, error) {
if f.Type.Type == field.TypeJSON {
return extractJSONDetails(f)
return extractJSONDetails(f) // repeat fields are not required for optional label.
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment is unclear about why the enableOptionalLabel parameter is not passed to extractJSONDetails. Consider clarifying: 'JSON fields only support repeated (array) types, not optional labels.' This better explains that extractJSONDetails doesn't need the enableOptionalLabel parameter because it only handles repeated fields.

Suggested change
return extractJSONDetails(f) // repeat fields are not required for optional label.
return extractJSONDetails(f) // JSON fields only support repeated (array) types, not optional labels.

Copilot uses AI. Check for mistakes.
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.

1 participant