fix(gen): report unimplemented SSE server response encoding at IR time - #1711
Merged
Conversation
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
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Two fixes for the v1.22.0 SSE regression:
openapi/parser: only auto-enable SSE mode fortext/event-streammedia when the schema is not a raw byte stream (type: string/format: binary/ no schema, mirroringgen.isStream). Such schemas fall back to the pre-v1.22io.Readerpath and generate a workingContent-Type: text/event-stream+io.Copyresponse encoder again — verified byte-for-byte equivalent behavior against a real v1.20.3 checkout. An explicitx-ogen-sse-event-shapeextension is still honored regardless of the schema.gen: for typed (structured-schema) SSE responses, which server generation genuinely does not support yet, raiseErrNotImplemented("sse server response encoding")during IR generation (only whenpaths/server/webhooks/serveris enabled) instead of failing insideWriteSourceat template-execution time.Fixes #1710
Why
Since v1.22.0 the parser auto-treats every
text/event-streamresponse as typed SSE:WriteSource, i.e. after--cleanwiped the target directory and outside thefail()/trySkipmachinery, so--cleandestroyed working projects, andignore_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 workingio.Reader-based server encoder, as in v1.20.3.text/event-stream+ structured schema, server enabled: error surfaces during IR building, before--cleanruns;ignore_not_implementedskips the operation viatrySkipand the generated package compiles.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 thesse server response encodingskip rule; the harness asserts the rule is genuinely exercised. Fails without thegenfix, passes with it.go test . ./gen/... ./openapi/... ./cmd/...green (includes wikimedia/openai SSE example specs).