Skip to content

Feat/generic forward methods - #156

Merged
fredbi merged 3 commits into
go-openapi:masterfrom
fredbi:feat/generic-forward-methods
Aug 23, 2026
Merged

fredbi merged 3 commits into
go-openapi:masterfrom
fredbi:feat/generic-forward-methods

Conversation

@fredbi

@fredbi fredbi commented Aug 23, 2026

Copy link
Copy Markdown
Member

Change type

Please select: 🆕 New feature or enhancement|🔧 Bug fix'|📃 Documentation update

Short description

Fixes

Full description

Checklist

  • I have signed all my commits with my name and email (see DCO. This does not require a PGP-signed commit
  • I have rebased and squashed my work, so only one commit remains
  • I have added tests to cover my changes.
  • I have properly enriched go doc comments in code.
  • I have properly documented any breaking change.

fredbi and others added 2 commits August 23, 2026 17:55
go1.27 accepts type parameters on methods, so the 55 generic assertions
become methods of the Assertions type: a.EqualT(expected, actual) next to
assert.EqualT(t, expected, actual). Eventually, Never, Consistently and
EventuallyWith gain a method for the first time; being generic without a T
suffix, they had none at all.

The methods land in assert/assert_forward_go127.go and
require/require_forward_go127.go, guarded by //go:build go1.27. A go1.25 or
go1.26 build drops those files and keeps the package-level functions.

Codegen:
- Function.ForwardGoBuild returns max(source guard, go1.27) for a generic
  function, so ErrorAsType and NotErrorAsType (guarded go1.26) join the
  go1.27 file and a future go1.28 generic assertion would get its own;
- Generate runs a second partition loop over ForwardBuildVariants, and
  selectVariant takes the partitioning key, SourceGoBuild or ForwardGoBuild;
- the forward templates render both partitions from one body, since
  GenericName and GenericCallName fall back to Name for a plain function.

Doc site:
- method rows for generic assertions carry a goversion "go1.27" badge;
- every assertion now counts 4 variants per package, where generics counted
  2: package_variants 446 -> 556, total API surface 902 -> 1122.

The go.work toolchain floor moves to go1.27.0. TestToolchainFloorCoversGuards
only scans internal/assertions, so it does not enforce this guard: codegen
emits it, and the go.work comment records why the floor must cover it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
The per-function tabs rendered by doc_page.md.gotmpl listed signatures the
generated packages do not have:

- every require row carried a bool return, though a require assertion calls
  FailNow instead of returning: `require.Equal(t T, ...) bool`;
- the method formatted row dropped the return for assert, and spelled its
  variadic `args ..any`;
- helpers picked up formatted and method rows, so common.md linked to
  require.CallerInfof and (*Assertions).ObjectsAreEqual, neither of which is
  generated: assertion_helpers.gotmpl emits the package-level function alone,
  with no t T parameter to format against.

The template now blanks the return for a require assertion, keeps it for a
require helper such as CallerInfo, and renders the three variant rows only
for assertions.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@codecov

codecov Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.31756% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.65%. Comparing base (001435e) to head (7f32ae7).
⚠️ Report is 5 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
require/require_forward_go127.go 97.81% 12 Missing ⚠️
codegen/internal/generator/generator.go 88.23% 2 Missing ⚠️
codegen/internal/model/buildtags.go 97.91% 1 Missing ⚠️
codegen/internal/model/documentation.go 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #156      +/-   ##
==========================================
+ Coverage   93.35%   93.65%   +0.30%     
==========================================
  Files         103      106       +3     
  Lines       12875    13793     +918     
==========================================
+ Hits        12019    12918     +899     
- Misses        849      868      +19     
  Partials        7        7              

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

x/tools/imports formats every file the generator writes with the go/parser of
the toolchain running codegen. Before go1.27 that parser rejects a generic
method with "method must have no type parameters", whatever //go:build line
the generated file carries, so a run that emits the go1.27 forward files
cannot complete and the oldstable CI leg failed on three tests.

- forward_generics_test.go carries //go:build go1.27: every test in it drives
  the generator over a generic assertion;
- TestExecute, which runs the whole pipeline over internal/assertions, skips
  when a probe parse of a generic method fails. The rest of main_test.go still
  runs, TestExecuteMultiplePackages included: it sets includeFwd and includeGen
  to false, so it emits no method at all.

codegen already needed a toolchain recent enough to observe guarded source
files; it now also needs one that can parse what it emits. The go.work floor
records that, but GOTOOLCHAIN=local ignores a toolchain directive, which is how
the oldstable leg reaches go1.26 in the first place.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
@fredbi
fredbi merged commit 92d111b into go-openapi:master Aug 23, 2026
25 checks passed
@fredbi
fredbi deleted the feat/generic-forward-methods branch August 23, 2026 16:29
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