Skip to content

Chore/greptile json codec rule - #2667

Merged
mromaszewicz merged 2 commits into
oapi-codegen:mainfrom
mromaszewicz:chore/greptile-json-codec-rule
Nov 11, 2026
Merged

mromaszewicz merged 2 commits into
oapi-codegen:mainfrom
mromaszewicz:chore/greptile-json-codec-rule

Conversation

@mromaszewicz

@mromaszewicz mromaszewicz commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Generated code is moving to the process-wide JSON codec in runtime
v1.9.0 (#2665), so that runtime.SetJSONCodec applies to all of it. A
template that calls encoding/json directly escapes the codec without any
test noticing, because the default codec is encoding/json.

Add a review rule that flags direct json.Marshal, json.Unmarshal,
json.NewEncoder and json.NewDecoder calls in templates and in code that
emits generated source, names the runtime function to use for each, and
protects the buffer-before-WriteHeader ordering of the strict response.
It lists what is exempt: json.RawMessage, json.Number, json.Valid, the
UseNumber probe in the union template, JSON a web framework handles, and
the generator's own use of encoding/json.

Co-Authored-By: Claude noreply@anthropic.com

mromaszewicz and others added 2 commits November 10, 2026 20:41
.greptile/config.json began with two opening braces, so it has not been
valid JSON since it was last edited, and the strictness and *.gen.go
settings in it could not be parsed. Remove the extra brace.

.greptile/rules.md had two sections numbered 5. The schema-merging rule,
which comes last, becomes section 8.

Co-Authored-By: Claude <noreply@anthropic.com>
Generated code is moving to the process-wide JSON codec in runtime
v1.9.0 (oapi-codegen#2665), so that runtime.SetJSONCodec applies to all of it. A
template that calls encoding/json directly escapes the codec without any
test noticing, because the default codec is encoding/json.

Add a review rule that flags direct json.Marshal, json.Unmarshal,
json.NewEncoder and json.NewDecoder calls in templates and in code that
emits generated source, names the runtime function to use for each, and
protects the buffer-before-WriteHeader ordering of the strict response.
It lists what is exempt: json.RawMessage, json.Number, json.Valid, the
UseNumber probe in the union template, JSON a web framework handles, and
the generator's own use of encoding/json.

Co-Authored-By: Claude <noreply@anthropic.com>
@mromaszewicz
mromaszewicz requested a review from a team as a code owner November 11, 2026 04:45
@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with the existing non-blocking wording concern still open.

Findings

  1. P2 Codec support is overstated ▶
Fix with agent prompt
### Issue 1
.greptile/rules.md:undefined-119
The new rule describes a migration that the current templates have not made. `client.tmpl:119` still emits `json.Marshal(body)`, and `strict/strict-interface.tmpl:92` still emits `json.NewEncoder(&buf).Encode(...)`, not `runtime.JSONMarshalWrite`. This could lead maintainers to believe one `runtime.SetJSONCodec` call already covers all generated JSON.

Describe codec use as a requirement for future changes instead. Keep the buffering requirement, which matches the current strict response template.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds review guidance for generated JSON to use the runtime codec.

  • Reviewers now check generated JSON calls against the runtime codec.
  • The review configuration now starts with a single opening brace.

Reviews (2) · Last reviewed commit: "chore: add a Greptile rule that generate..." · Reviewed by Greptile

Comment thread .greptile/rules.md Resolved
@mromaszewicz
mromaszewicz merged commit 223850d into oapi-codegen:main Nov 11, 2026
14 checks passed
@mromaszewicz
mromaszewicz deleted the chore/greptile-json-codec-rule branch November 11, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant