Synchronize strict servers#2350
Conversation
Bring the fiber and iris strict-server interface templates back into parity with the canonical stdhttp template (`strict-interface.tmpl`). Four pieces of drift were addressed: 1. Nullable / optional response-header serialization. Both templates now use the same three-way switch on `.IsNullable` / `.IsOptional` / default that PR oapi-codegen#2301 introduced for stdhttp, so unspecified nullable values and nil optional pointers are skipped instead of being stringified into the wire header. 2. Response-header struct field types. The `{{$opid}}{{$statusCode}}ResponseHeaders` struct now uses `{{.GoTypeDef}}` (pointer/nullable-aware) rather than the raw `{{.Schema.TypeDecl}}`, matching the type that the typed-body Visit function expects. 3. `$ref` Text responses. The fixed-status-code + ref branch now matches Multipart and Text together (PR oapi-codegen#2225), so `$ref` text responses alias directly to the component response type. Iris additionally drops its unconditional `type X string` short-circuit, which previously masked `$ref`, `$hasHeaders`, and `$fixedStatusCode` for any text response. 4. `$ref` name qualification (fiber only). Switch from `ucFirst` to `ucFirstWithPkgName` so external-ref response types carry their package qualifier, matching stdhttp and iris. Regenerated fixtures under `internal/test/strict-server/{fiber,iris}/server.gen.go` demonstrate the change for items (1) and (2); items (3) and (4) have no existing fiber/iris fixture coverage. The no-content `Visit*Response` branch still renders headers unconditionally in all three templates (including stdhttp); that gap is tracked separately (oapi-codegen#2349) and not addressed here. Fixes: oapi-codegen#2331 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR synchronizes the fiber and iris strict-server interface templates with the canonical Confidence Score: 4/5Safe to merge; all findings are P2 — the breaking field-type change is intentional and fixes a bug, but warrants release-note callout. All findings are P2: the No files require special attention; the template changes look structurally correct and match stdhttp.
|
| Filename | Overview |
|---|---|
| pkg/codegen/templates/strict/strict-fiber-interface.tmpl | Brings fiber strict interface into parity with stdhttp: switches to ucFirstWithPkgName, GoTypeDef for header fields, adds nullable/optional header guard, and extends the $ref alias branch to Text responses. Breaking change for users with nullable/optional header fields (string → *string). |
| pkg/codegen/templates/strict/strict-iris-interface.tmpl | Brings iris strict interface into parity with stdhttp: removes the unconditional type X string text-response short-circuit, uses GoTypeDef, adds nullable/optional header guards, and extends the $ref alias branch to Text responses. No fixture coverage for the text $ref path. |
| internal/test/strict-server/fiber/server.gen.go | Regenerated correctly: NullableHeader/OptionalHeader changed from string to *string and Visit function now checks for nil before setting headers. Diff scope matches the stated change. |
| internal/test/strict-server/iris/server.gen.go | Regenerated correctly: same nullable/optional header changes as fiber. Diff scope matches the stated change. |
Comments Outside Diff (1)
-
pkg/codegen/templates/strict/strict-iris-interface.tmpl, line 162-181 (link)No-content Visit*Response branch still emits headers unconditionally
The no-content
Visit*Responsebranch still callsHeader().Set(...)for every header without checkingIsNullable/IsOptional, meaning nullable unspecified headers are serialized as their zero-value string. The same gap exists in the fiber and stdhttp templates (tracked in Strict-server: no-content Visit*Response skips nullable/optional header gating #2349). This PR brings the body-bearing branches into parity but the no-content branch remains inconsistent within the same template.
Reviews (1): Last reviewed commit: "Synchronize strict servers" | Re-trigger Greptile
Bring the fiber and iris strict-server interface templates back into parity with the canonical stdhttp template (
strict-interface.tmpl). Four pieces of drift were addressed:Nullable / optional response-header serialization. Both templates now use the same three-way switch on
.IsNullable/.IsOptional/ default that PR support optional/nullable response headers #2301 introduced for stdhttp, so unspecified nullable values and nil optional pointers are skipped instead of being stringified into the wire header.Response-header struct field types. The
{{$opid}}{{$statusCode}}ResponseHeadersstruct now uses{{.GoTypeDef}}(pointer/nullable-aware) rather than the raw{{.Schema.TypeDecl}}, matching the type that the typed-body Visit function expects.$refText responses. The fixed-status-code + ref branch now matches Multipart and Text together (PR fix(strict-server): generate correct type for$reftext responses #2225), so$reftext responses alias directly to the component response type. Iris additionally drops its unconditionaltype X stringshort-circuit, which previously masked$ref,$hasHeaders, and$fixedStatusCodefor any text response.$refname qualification (fiber only). Switch fromucFirsttoucFirstWithPkgNameso external-ref response types carry their package qualifier, matching stdhttp and iris.Regenerated fixtures under
internal/test/strict-server/{fiber,iris}/server.gen.godemonstrate the change for items (1) and (2); items (3) and (4) have no existing fiber/iris fixture coverage.The no-content
Visit*Responsebranch still renders headers unconditionally in all three templates (including stdhttp); that gap is tracked separately (#2349) and not addressed here.Fixes: #2331