Replace old hand written slice sorting with slices package, and other built-in helpers - #2305
Conversation
Signed-off-by: Gaiaz Iusipov <g.iusipov@gmail.com>
|
You have two unrelated changes here - using modern packages, and the error compile time check. I would very happily merge the first part, as-is, however, since we are a code generator, we can ensure that the generated code always implements error, without having a compile time check for our own output. I don't think we need that second part. You've also only added that to the stdhttp server, and we try to keep as much parity between generated code as possible. |
|
Thanks. This kind of compile-time check is used in various Go projects as a guarantee that certain types implement an interface and that this behavior won’t accidentally break in the future. But I agree that it’s better if I remove those changes and keep only the set that introduces the use of the standard package. |
Signed-off-by: Gaiaz Iusipov <g.iusipov@gmail.com>
Greptile SummaryThis PR replaces hand-rolled helper wrappers ( Confidence Score: 5/5Safe to merge — all changes are pure style simplifications with no behavioral differences. Every substitution is semantically equivalent: No files require special attention.
|
| Filename | Overview |
|---|---|
| pkg/codegen/codegen.go | Replaces manual map/slice iteration patterns with slices/maps stdlib functions and removes MergeImports wrapper calls in favour of maps.Copy. |
| pkg/codegen/gather.go | Adopts slices.Concat, slices.SortFunc/cmp.Compare, pre-sized slice allocation, and adds compile-time fmt.Stringer interface assertions for SchemaPath and SchemaContext. |
| pkg/codegen/merge_schemas.go | Replaces manual double-loop map merges with maps.Copy and pre-sized map allocations for Extensions and Properties. |
| pkg/codegen/merge_schemas_v1.go | Replaces StringInArray with slices.Contains. |
| pkg/codegen/operations.go | Modernises with slices/cmp/maps, converts HasMaskedRequestContentTypes to pointer receiver (consistent with all other OperationDefinition methods), uses strings.SplitSeq iterator, pre-sizes slices/maps, and removes == false anti-patterns. |
| pkg/codegen/prune.go | Removes trivial stringInSlice wrapper; calls slices.Contains directly. |
| pkg/codegen/resolve_names.go | Replaces counted for loops with idiomatic for range forms where the loop variable was unused. |
| pkg/codegen/schema.go | Replaces StringInArray/sliceContains with slices.Contains, switches strings.Split to strings.SplitSeq iterator, removes == false anti-patterns. |
| pkg/codegen/template_helpers.go | Replaces all StringInArray calls with slices.Contains. |
| pkg/codegen/templates/stdhttp/std-http-handler.tmpl | Embeds http.Handler in ServeMux interface instead of the explicit ServeHTTP method declaration; updates doc comment to use Go doc link syntax. |
| pkg/codegen/typemapping.go | Removes ineffective omitempty from JSON struct-field tags (structs are never omitted by encoding/json), replaces manual map-copy loops with maps.Copy. |
| pkg/codegen/utils.go | Removes StringInArray, MergeImports, and sliceContains wrapper functions; simplifies SortedSecuritySchemeKeys with slices.Collect(maps.Keys(...)); replaces sort.Slice with slices.SortFunc+cmp.Or. |
Reviews (1): Last reviewed commit: "Merge branch 'main' into modernize" | Re-trigger Greptile
|
Thank you! |
In this PR I made small stylistic changes: using functions from standard packages (
maps.Copy,slices.Contains, etc.)