FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: handle untyped strict JSON responses by Boulea7 · Pull Request #2514 · oapi-codegen/oapi-codegen · GitHub

fix: handle untyped strict JSON responses - #2514

Open
Boulea7 wants to merge 2 commits into
oapi-codegen:mainfrom
Boulea7:fix/issue-1328-untyped-json-responses
Open

fix: handle untyped strict JSON responses#2514
Boulea7 wants to merge 2 commits into
oapi-codegen:mainfrom
Boulea7:fix/issue-1328-untyped-json-responses

Conversation

Boulea7 commented Aug 10, 2026
edited
Loading

Copy link
Copy Markdown

Summary

  • wrap strict JSON responses when the generated Go body type cannot be used as a method receiver, covering untyped schemas, interfaces, and pointers
  • preserve the existing direct response API for receiver-compatible JSON types and opaque named x-go-type declarations
  • keep reusable external response envelopes convertible across standard, Fiber, and Iris strict-server templates

Scope

  • changes are limited to response receiver classification and the four strict response templates
  • no external reference qualification changes are included
  • non-JSON multipart callbacks and unsupported-media io.Reader envelopes keep their existing representation

Testing

  • make tidy (no module file changes)
  • make test
  • make generate
  • make lint (0 issues in all modules)
  • targeted code-generation tests for standard, Fiber, and Iris strict servers
  • cross-package response_cast compilation coverage for concrete, untyped, interface, pointer, header-bearing, multipart, opaque named, generic, and unsupported-media responses

AI assistance

This change was developed with AI assistance.

Fixes #1328

Boulea7 requested a review from a team as a code owner August 10, 2026 18:01

greptile-apps Bot commented Aug 10, 2026
edited
Loading

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR replaces the earlier external-reference work with a focused strict JSON response fix.

  • Classifies JSON body types according to whether Go permits them as method receivers.
  • Wraps untyped, interface, and pointer response bodies while retaining direct response types for receiver-compatible declarations.
  • Applies the representation consistently across standard, Fiber, and Iris strict templates.
  • Adds generated cross-package fixtures covering reusable responses, headers, multipart callbacks, opaque named types, generics, and unsupported media.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains, and the previously reported external-reference issue is avoided because the focused replacement no longer changes externalref.go.

Important Files Changed

Filename Overview
pkg/codegen/operations.go Adds strict-response receiver classification and reusable-response header ownership without reintroducing the previously reported external-reference qualification path.
pkg/codegen/templates/strict/strict-interface.tmpl Uses wrapper bodies only when the classified JSON type cannot serve as a method receiver.
pkg/codegen/templates/strict/strict-fiber-interface.tmpl Mirrors the strict response representation and serialization behavior for Fiber.
pkg/codegen/templates/strict/strict-iris-interface.tmpl Mirrors the strict response representation and serialization behavior for Iris.
pkg/codegen/templates/strict/strict-responses.tmpl Keeps reusable strict response envelopes aligned with operation-specific response types.
pkg/codegen/operations_test.go Adds focused generation coverage for receiver-compatible and wrapper-requiring response body types.
internal/test/references/multipackage/response_cast/issue_test.go Adds compile-time cross-package conversion coverage across the supported strict template families.

Reviews (2): Last reviewed commit: "test: cover strict JSON response receive..." | Re-trigger Greptile

Comment thread pkg/codegen/externalref.go Outdated
Boulea7 marked this pull request as draft August 11, 2026 05:38

Copy link
Copy Markdown
Contributor

This also fixes #2525, which @mromaszewicz filed during review of #2522 (same bug as #1328). I was about to start on it and found this PR instead, so I took it for a spin rather than duplicate the work.

I merged the branch onto current main and generated strict-server code for every shape from #2525: schema: {}, type: "null", a 3.1 multi-type union, and a $ref to a named union component. Each one produces the Body wrapper and compiles, with the ref case classified by its underlying schema. Regenerating the committed fixtures on the merged tree produces no diff, so the output is consistent with the generator after #2522 and #2526.

Two non-blocking suggestions:

  • The test specs are all OpenAPI 3.0.1. Since Map OpenAPI 3.1 multi-type unions to any #2522 merged, 3.1 multi-type unions and type: "null" also lower to any. The classification handles them, but a 3.1 fixture would pin that behavior against regressions.
  • The new tests are compile-time checks (conversions and struct literals). A round-trip through a strict handler asserting the JSON on the wire would also catch visitor regressions, not just type-shape ones.

Neither should hold this up. The wrapper shape matches what #2525 proposes, and wrapping only receiver-incompatible bodies keeps the direct API for everything that compiles today.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty schema in response

2 participants


Back | FazBrowse Home | New Git URL