Use any instead of interface#2438
Conversation
Greptile SummaryThis PR mechanically replaces all uses of
Confidence Score: 4/5Safe 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.
|
| 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{}`. | |||
There was a problem hiding this 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.
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 { |
There was a problem hiding this comment.
This doesn't look right 🤔 But I guess it is?
The
anykeyword has now been around for years, standardize on its use.