Skip to content

fix(openapi3): emit SSE response examples on OpenAPI 3.2.0 - #12291

Open
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
microsoft:mainfrom
Thanatos9404:fix/openapi3-sse-examples-3-2
Open

Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
microsoft:mainfrom
Thanatos9404:fix/openapi3-sse-examples-3-2

Conversation

@Thanatos9404

Copy link
Copy Markdown

Fixes #11090

With openapi-versions: ["3.2.0"], an @opExample on an operation that returns SSEStream<T> was missing from the output: the text/event-stream response had itemSchema but no examples, and no diagnostic was reported. With 3.0.0 or 3.1.0 the same example is emitted next to schema: { type: string }.

Cause

In getBodyContentEntry (packages/openapi3/src/openapi.ts), the 3.2.0 stream branch builds the media type with attachSSEItemSchema and returns it as soon as it is not empty. The @opExample values were only turned into example/examples after that branch, on the regular path that 3.0.0 and 3.1.0 fall through to.

Fix

Compute the examples before the stream branch and add them to the itemSchema media type as well. The example value itself is unchanged: it is the serialized body, the same string 3.0.0 and 3.1.0 already emit. OpenAPI 3.2.0 places examples next to itemSchema the same way as next to schema (section 4.14.6.2), and the JSONL example in that section also puts the whole raw stream in a single value.

The playground example from the issue now gives:

text/event-stream:
  itemSchema: {...} # unchanged by this PR
  examples:
    Example stream:
      summary: Example stream
      value: |+
        data: {"type":"message","text":"hello"}

A JsonlStream of an @events union goes through the same branch, so it keeps its examples on 3.2.0 too (checked by compiling a sample; there is no new test for it). Streams that get no itemSchema (for example a JsonlStream of a plain model) already took the regular path and are unchanged.

Tests

New tests in test/sse.test.ts compile the example from the issue:

  • 3.2.0: examples is emitted next to itemSchema. This fails on main (examples is undefined) and passes with the fix.
  • 3.0.0 and 3.1.0: examples is still emitted next to schema: { type: string }, with the streams-not-supported warning. These pass before and after.

The full @typespec/openapi3 test suite passes (74 files, 2706 tests). prettier --check, oxlint --type-aware --deny-warnings and cspell are clean on the changed files.

For a stream response on OpenAPI 3.2.0, `getBodyContentEntry` builds the
media type with `itemSchema` and returns it before the `@opExample`
values are turned into `example`/`examples`, so the examples were
dropped without a diagnostic. On 3.0.0 and 3.1.0 the same response falls
through to the regular path and keeps them next to
`schema: { type: string }`.

Compute the examples before the stream branch and add them to the
`itemSchema` media type too. The value is the serialized body, as on
3.0.0 and 3.1.0.

Fixes microsoft#11090

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:openapi3 Issues for @typespec/openapi3 emitter label Oct 16, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:openapi3 Issues for @typespec/openapi3 emitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SSEStream response examples are not emitted on OpenAPI 3.2.0

2 participants