Skip to content

Normalize FieldDescriptor#type; add #json_name and #default_value#17

Merged
cocoahero merged 1 commit into
mainfrom
feature/field-conveniences
Jul 7, 2026
Merged

Normalize FieldDescriptor#type; add #json_name and #default_value#17
cocoahero merged 1 commit into
mainfrom
feature/field-conveniences

Conversation

@cocoahero

@cocoahero cocoahero commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

Three small FieldDescriptor conveniences for codegen.

Changes

  • #type — overrides the delegated type enum to a plain symbol for every field: the TYPE_ prefix is dropped and the rest downcased (:TYPE_INT32:int32, :TYPE_MESSAGE:message, :TYPE_ENUM:enum). For :message/:enum fields use #type_descriptor (or #key/#value for maps) to resolve the referenced type. descriptor.type is read in exactly one place — the normalization itself — and the type predicates (#message?/#enum?/#group?) and map detection are all defined in terms of #type.
  • #json_name — the JSON name computed by protoc (lowerCamelCase unless overridden with the json_name option).
  • #default_value — the explicit proto2 default as a string, or nil when none was declared (proto3 fields never carry defaults).

Testing

  • New tests: #type normalizes across scalar and message fields; #json_name including a camelCased case (published_atpublishedAt); #default_value via a synthetic proto2-style field, and nil when absent.
  • Library-only change — no fixture regeneration needed.
  • bin/rake (test + rubocop): 80 runs, 208 assertions, 0 failures, rubocop clean.

@cocoahero cocoahero force-pushed the feature/field-conveniences branch from 96d2709 to e60793e Compare July 7, 2026 19:55
@cocoahero cocoahero changed the title Add FieldDescriptor#scalar_type, #json_name, #default_value Normalize FieldDescriptor#type; add #json_name and #default_value Jul 7, 2026
@cocoahero cocoahero force-pushed the feature/field-conveniences branch from e60793e to 2d84690 Compare July 7, 2026 19:57
- #type: override the delegated type enum to a plain symbol for every
  field, dropping the TYPE_ prefix and downcasing (:TYPE_INT32 -> :int32,
  :TYPE_MESSAGE -> :message). descriptor.type is read in exactly one place
  (the normalization); the type predicates and map detection are defined
  in terms of #type.
- #json_name: the protoc-computed JSON name.
- #default_value: the proto2 default as a string, or nil when absent.
@cocoahero cocoahero force-pushed the feature/field-conveniences branch from 2d84690 to 69d56ca Compare July 7, 2026 19:58
@cocoahero cocoahero merged commit faf71b1 into main Jul 7, 2026
5 checks passed
@cocoahero cocoahero deleted the feature/field-conveniences branch July 7, 2026 19:59
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