Skip to content

Synchronize strict servers#2350

Merged
mromaszewicz merged 1 commit intooapi-codegen:mainfrom
mromaszewicz:fix/issue-2331
Apr 30, 2026
Merged

Synchronize strict servers#2350
mromaszewicz merged 1 commit intooapi-codegen:mainfrom
mromaszewicz:fix/issue-2331

Conversation

@mromaszewicz
Copy link
Copy Markdown
Member

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 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.

  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 fix(strict-server): generate correct type for $ref text responses  #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 (#2349) and not addressed here.

Fixes: #2331

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>
@mromaszewicz mromaszewicz requested a review from a team as a code owner April 30, 2026 04:01
@mromaszewicz mromaszewicz added the bug Something isn't working label Apr 30, 2026
@mromaszewicz mromaszewicz added this to the v2.7.0 milestone Apr 30, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 30, 2026

Greptile Summary

This PR synchronizes the fiber and iris strict-server interface templates with the canonical strict-interface.tmpl (stdhttp), fixing four areas of drift: nullable/optional response-header serialization, header struct field types (GoTypeDef instead of Schema.TypeDecl), $ref text-response aliasing, and package-qualified external ref names for fiber. The generated fixture diffs for items (1) and (2) look correct and appropriately scoped; items (3) and (4) have no existing fixture coverage, as the PR acknowledges.

Confidence Score: 4/5

Safe 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 string*string field type change is a compile-breaking change for downstream users (custom rule §3) but is fixing an incorrect prior behavior; the no-content header branch inconsistency is pre-existing and tracked in #2349; missing fixture coverage for the iris text $ref path is acknowledged by the author. No logic errors or security issues found.

No files require special attention; the template changes look structurally correct and match stdhttp.

Important Files Changed

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)

  1. pkg/codegen/templates/strict/strict-iris-interface.tmpl, line 162-181 (link)

    P2 No-content Visit*Response branch still emits headers unconditionally

    The no-content Visit*Response branch still calls Header().Set(...) for every header without checking IsNullable / 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

Comment thread pkg/codegen/templates/strict/strict-fiber-interface.tmpl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Strict-server templates: fiber and iris variants have drifted from stdhttp

1 participant