Skip to content

feat(gen): derive mappings with caller-supplied parameters#1771

Merged
ernado merged 1 commit into
mainfrom
feat/376-mapper-params
Jun 12, 2026
Merged

feat(gen): derive mappings with caller-supplied parameters#1771
ernado merged 1 commit into
mainfrom
feat/376-mapper-params

Conversation

@ernado

@ernado ernado commented Jun 12, 2026

Copy link
Copy Markdown
Member

Closes #376.

Problem

PR #374 dropped the Photo/InputPhotoInputPhotoFileLocation mappings
because InputPhotoFileLocation requires a thumb_size field that can't be
derived from the source constructor. As #376 notes, the generator could instead
emit AsInputPhotoFileLocation(thumbSize string) and let the caller pass it in.

Change

mappableFields now splits the target's unmappable fields:

  • conditional fields stay optional (left unset, as before);
  • thumb_size on file-location inputs becomes a method parameter (parameterField);
  • anything else still causes the mapping to be skipped (unchanged).

The generated concrete As-mappers render those fields as parameters and assign
them after the derived fields.

Generated API

// changed (thumb_size was previously left empty)
func (d *Document) AsInputDocumentFileLocation(thumbSize string) *InputDocumentFileLocation
func (i *InputDocument) AsInputDocumentFileLocation(thumbSize string) *InputDocumentFileLocation

// new (previously not generated)
func (p *Photo) AsInputPhotoFileLocation(thumbSize string) *InputPhotoFileLocation
func (i *InputPhoto) AsInputPhotoFileLocation(thumbSize string) *InputPhotoFileLocation

telegram/query/messages now uses these mappers instead of building the
location structs by hand.

Breaking: AsInputDocumentFileLocation() gains a thumbSize argument.
Pass "" to keep the previous behavior (full file, not a thumbnail).

Scope

The blast radius is exactly the four file-location mappers above — the
parameterized mappings carry a Constructor, so the slice/field wrapper
templates (which only handle constructor-less interface mappings) are untouched.

Tests

  • gen: unit tests for mappableFields (thumb_size → parameter; unmappable
    required field still skipped) and parameterField.
  • make check_generated clean; full build + telegram/query/messages race
    tests pass.

🤖 Generated with Claude Code

Target fields that can't be derived from the source constructor are now
exposed as parameters of the generated As-mapper instead of causing the
mapping to be skipped. thumb_size on file-location inputs is required by
the wire format but not present on the source, so the caller supplies it.

Document/InputDocument now have AsInputDocumentFileLocation(thumbSize
string) and Photo/InputPhoto gain a new AsInputPhotoFileLocation(thumbSize
string) (previously dropped in #374 because thumb_size is required).
telegram/query/messages uses these mappers instead of hand-building the
location structs.

Closes #376

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 71.10%. Comparing base (6ac0462) to head (570d001).

Files with missing lines Patch % Lines
gen/fields.go 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1771      +/-   ##
==========================================
+ Coverage   71.07%   71.10%   +0.03%     
==========================================
  Files         501      501              
  Lines       23500    23501       +1     
==========================================
+ Hits        16703    16711       +8     
+ Misses       5570     5569       -1     
+ Partials     1227     1221       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ernado ernado merged commit 44e82fd into main Jun 12, 2026
14 checks passed
@ernado ernado deleted the feat/376-mapper-params branch June 12, 2026 16:17
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.

gen: derive mappings with parameters

1 participant