Skip to content

fix(gen): report unimplemented SSE server response encoding at IR time - #1711

Merged
ernado merged 3 commits into
mainfrom
fix/sse-server-response-encoding-skip
Jul 10, 2026
Merged

fix(gen): report unimplemented SSE server response encoding at IR time#1711
ernado merged 3 commits into
mainfrom
fix/sse-server-response-encoding-skip

Conversation

@ernado

@ernado ernado commented Jul 10, 2026

Copy link
Copy Markdown
Member

What

Two fixes for the v1.22.0 SSE regression:

  1. openapi/parser: only auto-enable SSE mode for text/event-stream media when the schema is not a raw byte stream (type: string / format: binary / no schema, mirroring gen.isStream). Such schemas fall back to the pre-v1.22 io.Reader path and generate a working Content-Type: text/event-stream + io.Copy response encoder again — verified byte-for-byte equivalent behavior against a real v1.20.3 checkout. An explicit x-ogen-sse-event-shape extension is still honored regardless of the schema.
  2. gen: for typed (structured-schema) SSE responses, which server generation genuinely does not support yet, raise ErrNotImplemented("sse server response encoding") during IR generation (only when paths/server / webhooks/server is enabled) instead of failing inside WriteSource at template-execution time.

Fixes #1710

Why

Since v1.22.0 the parser auto-treats every text/event-stream response as typed SSE:

  • Raw-stream schemas that generated a functional encoder in v1.20.3 (binary passthrough) now route to the unimplemented SSE server encoder and hard-fail — a true regression, restored by fix 1.
  • The unimplemented-feature error fired inside WriteSource, i.e. after --clean wiped the target directory and outside the fail()/trySkip machinery, so --clean destroyed working projects, and ignore_not_implemented: ["sse server response encoding"] did not suppress the error — fixed by 2.

Note: structured (non-stream) schemas under text/event-stream, such as the object schema in the issue's minimal repro, did not generate in v1.20.3 either (Content type "text/event-stream" is unsupported); with this PR they fail cleanly and skippably until server-side typed SSE encoding is implemented. Client-only generation of typed SSE (server features disabled) is unaffected.

After this change

  • text/event-stream + binary/raw-stream schema: generates a working io.Reader-based server encoder, as in v1.20.3.
  • text/event-stream + structured schema, server enabled: error surfaces during IR building, before --clean runs; ignore_not_implemented skips the operation via trySkip and the generated package compiles.
  • Client-only typed SSE: unchanged.

Testing

  • _testdata/positive/issue1710_stream.yml — binary-stream SSE spec generating with no ignore rules.
  • _testdata/positive/issue1710.yml — the issue's object-schema repro with the sse server response encoding skip rule; the harness asserts the rule is genuinely exercised. Fails without the gen fix, passes with it.
  • Parser unit tests: no auto-SSE for nil/string/binary schemas; explicit extension still honored.
  • End-to-end: default run fails before writing/cleaning anything; with the ignore config output compiles; binary-schema output compiles and matches v1.20.3's file set.
  • go test . ./gen/... ./openapi/... ./cmd/... green (includes wikimedia/openai SSE example specs).

ernado added 3 commits July 10, 2026 15:06
Raise ErrNotImplemented("sse server response encoding") during IR
generation, only when server generation is enabled, instead of failing
inside WriteSource at template execution time.

Previously the error fired after the target directory was cleaned and
outside the fail()/trySkip machinery, so:

- ogen --clean wiped previously generated files and left partial,
  unbuildable output;
- ignore_not_implemented could not suppress the error, and even when it
  appeared to, the generated package did not compile (missing response
  encoder).

Now the error surfaces before --clean runs, and ignore_not_implemented
skips the operation cleanly, producing compilable output. Client-only
SSE generation (server features disabled) is unaffected.

Fixes #1710
In v1.20.3, a text/event-stream response with a raw stream schema
(type: string, format: binary, or no schema) generated a functional
io.Reader-based response encoder. Since typed SSE support landed, the
parser auto-enables SSE mode for every text/event-stream media, which
routes such responses to the unimplemented SSE server encoder and
breaks previously working specs.

Only auto-enable SSE mode when the schema is not a raw byte stream
(mirrors gen.isStream). An explicit x-ogen-sse-event-shape extension is
still honored regardless of the schema.

Refs #1710
Narrow isBinaryStreamSchema so that only schema-less media and explicit
string/binary schemas fall back to the legacy io.Reader path. Schemas
without an explicit type, e.g. oneOf sums as used by the OpenAI spec,
must stay in SSE mode; treating them as byte streams broke generated
example code (check-generate CI failure).

Refs #1710
@ernado
ernado merged commit 474c0a8 into main Jul 10, 2026
15 checks passed
@ernado
ernado deleted the fix/sse-server-response-encoding-skip branch July 10, 2026 12:43
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.

bug: SSE response encoding regression in v1.22.0

1 participant