Skip to content

Use any instead of interface#2438

Open
mromaszewicz wants to merge 1 commit into
oapi-codegen:mainfrom
mromaszewicz:chore/any
Open

Use any instead of interface#2438
mromaszewicz wants to merge 1 commit into
oapi-codegen:mainfrom
mromaszewicz:chore/any

Conversation

@mromaszewicz

Copy link
Copy Markdown
Member

The any keyword has now been around for years, standardize on its use.

@mromaszewicz
mromaszewicz requested a review from a team as a code owner July 6, 2026 20:50
@mromaszewicz mromaszewicz added the chore Any maintenance tasks that are regular, not as important to call out in the changelog label Jul 6, 2026
@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR mechanically replaces all uses of interface{} with the any alias across templates, codegen logic, generated fixtures, and documentation. Since any is a built-in alias for interface{} introduced in Go 1.18, this is a purely cosmetic change with no semantic impact on downstream users.

  • pkg/codegen/schema.go and template_helpers.go are updated in tandem: GoType string literals that drove code generation now emit any, and the corresponding string equality check in genResponseUnmarshal was updated to match.
  • All six strict-server templates and the shared union.tmpl, client.tmpl, callback-initiator.tmpl, and webhook-initiator.tmpl are consistently updated.
  • The YAML spec descriptions for the openapi31_nullable test fixtures were updated to reference *map[string]any, but the corresponding generated Go comments in spec_3_0/types.gen.go and spec_3_1/types.gen.go still say *map[string]interface{}; running make generate against the updated YAML will produce a diff on those comment lines and fail CI.

Confidence Score: 4/5

Safe to merge once the stale doc comments in the two generated nullable-test files are corrected by re-running the generator.

The YAML descriptions for the openapi31_nullable fixtures were updated to say *map[string]any, but the corresponding generated Go comments in spec_3_0/types.gen.go (line 10) and spec_3_1/types.gen.go (line 37) still reference the old *map[string]interface{} text. Regenerating from the updated YAML will produce different comment lines, so make generate will leave a diff and fail CI. Everything else in the PR is internally consistent and correct.

internal/test/openapi31_nullable/spec_3_0/types.gen.go and internal/test/openapi31_nullable/spec_3_1/types.gen.go need their doc comments regenerated to match the updated YAML descriptions.

Important Files Changed

Filename Overview
pkg/codegen/schema.go Replaced all three occurrences of "interface{}" with "any" as GoType string literals; the template_helpers.go string comparison was updated in sync, so code generation logic is consistent.
pkg/codegen/template_helpers.go Updated the TypeName string comparison from "interface{}" to "any" to match the GoType produced by schema.go; correctly aligned with the schema change.
pkg/codegen/templates/strict/strict-http.tmpl handler closure signature updated from interface{} to any; consistent with StrictHandlerFunc type already using any.
internal/test/openapi31_nullable/spec_3_0/types.gen.go Type updated from *map[string]interface{} to *map[string]any, but the doc comment still references the old interface{} spelling; the YAML description was updated, so regeneration would produce a diff and fail CI.
internal/test/openapi31_nullable/spec_3_1/types.gen.go Types updated to any, but the Extras and Metadata doc comments still reference *map[string]interface{} while the YAML description now says *map[string]any; regeneration would produce a diff.
pkg/codegen/templates/union.tmpl ValueByDiscriminator return type updated from interface{} to any in the template; consistent with the generated spec_3_1/types.gen.go.
README.md Documentation examples updated to reflect any instead of interface{} in generated code snippets.
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
internal/test/openapi31_nullable/spec_3_0/types.gen.go:10
**Stale generated-file comment after YAML description update**

The `spec_3_0.yaml` description was updated from `*map[string]interface{}` to `*map[string]any` (line 43 of the YAML), but the corresponding generated comment in this file was not regenerated and still reads the old text. When CI runs `make generate`, it will re-derive the Go comment from the YAML description and produce `*map[string]any`, leaving a diff that fails the "generated files must be up-to-date" check. The same stale comment exists at line 37 of `spec_3_1/types.gen.go`.

Reviews (2): Last reviewed commit: "Use `any` instead of `interface`" | Re-trigger Greptile

The `any` keyword has now been around for years, standardize on its
use.
@@ -8,7 +8,7 @@ type Pet struct {
// Extras Optional, nullable *unspecified* object (no `properties:`).
// 3.0 control case for the 3.1 `type: ["object","null"]`
// equivalent; expected shape: `*map[string]interface{}`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Stale generated-file comment after YAML description update

The spec_3_0.yaml description was updated from *map[string]interface{} to *map[string]any (line 43 of the YAML), but the corresponding generated comment in this file was not regenerated and still reads the old text. When CI runs make generate, it will re-derive the Go comment from the YAML description and produce *map[string]any, leaving a diff that fails the "generated files must be up-to-date" check. The same stale comment exists at line 37 of spec_3_1/types.gen.go.

Prompt To Fix With AI
This is a comment left during a code review.
Path: internal/test/openapi31_nullable/spec_3_0/types.gen.go
Line: 10

Comment:
**Stale generated-file comment after YAML description update**

The `spec_3_0.yaml` description was updated from `*map[string]interface{}` to `*map[string]any` (line 43 of the YAML), but the corresponding generated comment in this file was not regenerated and still reads the old text. When CI runs `make generate`, it will re-derive the Go comment from the YAML description and produce `*map[string]any`, leaving a diff that fails the "generated files must be up-to-date" check. The same stale comment exists at line 37 of `spec_3_1/types.gen.go`.

How can I resolve this? If you propose a fix, please make it concise.

bodyReader = strings.NewReader(bodyStr.Encode())
{{else if eq .NameTag "Text" -}}
if stringer, ok := interface{}(body).(fmt.Stringer); ok {
if stringer, ok := any(body).(fmt.Stringer); ok {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't look right 🤔 But I guess it is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Any maintenance tasks that are regular, not as important to call out in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants