Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

entproto: enum values with special characters are not supported #3498

Closed
2 tasks done
jamslinger opened this issue Apr 20, 2023 · 0 comments · Fixed by ent/contrib#487
Closed
2 tasks done

entproto: enum values with special characters are not supported #3498

jamslinger opened this issue Apr 20, 2023 · 0 comments · Fixed by ent/contrib#487

Comments

@jamslinger
Copy link

Ent allows enum Values with special characters as long as they are valid Go identifiers. For NamedValues anything is allowed. In entproto the keys of the configured enum mapping must match the values of the field.Enum but if those contain special characters, the protobuf and gRPC service generation currently fails.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Protobuf message and gRPC service generation fails for field.Enum with values containing special characters:

func (Logo) Fields() []ent.Field {
	return []ent.Field{
		field.Enum("mimeType").
			NamedValues(
				"JPEG", "image/jpeg",
				"PNG", "image/png",
				"SVG", "image/svg+xml").
			Annotations(
				entproto.Field(2), 
				entproto.Enum(map[string]int32{
					"image/jpeg":    1,
					"image/png":     2,
					"image/svg+xml": 3,
				}),
			),
		field.Bytes("content").Annotations(entproto.Field(3)),
	}
}

func (Logo) Annotations() []schema.Annotation {
	return []schema.Annotation{
		entproto.Message(),
		entproto.Service(),
	}
}

Expected Behavior 🤔

Message and service generation should succeed while preserving the Proto Style Guide for value names:

message Logo {
  int64 id = 1;

  MimeType mimeType = 2;

  bytes content = 3;

  enum MimeType {
    MIME_TYPE_UNSPECIFIED = 0;

    MIME_TYPE_IMAGE_JPEG = 1;

    MIME_TYPE_IMAGE_PNG = 2;

    MIME_TYPE_IMAGE_SVG_XML = 3;
  }
}

Steps to Reproduce 🕹

Steps:

  1. Create an ent schema with field.Enum
  2. Define enum Values or NamedValues containing special characters ([^a-zA-Z0-9_]+)
  3. Add entproto.Field and entproto.Enum field annotations
  4. Add entproto annotation to generate protobuf message and gRPC service
  5. Attempt message and service generation

Your Environment 🌎

I'm using the

Tech Version
Go 1.19.0
Ent 0.12.0
Database SQLite
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 a pull request may close this issue.

1 participant