Repository navigation
fix(openapi3): emit SSE response examples on OpenAPI 3.2.0 - #12291
Open
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
Open
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
Yashvardhan Thanvi (Thanatos9404) wants to merge 1 commit into
Conversation
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
|
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
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.
Fixes #11090
With
openapi-versions: ["3.2.0"], an@opExampleon an operation that returnsSSEStream<T>was missing from the output: thetext/event-streamresponse haditemSchemabut noexamples, and no diagnostic was reported. With 3.0.0 or 3.1.0 the same example is emitted next toschema: { type: string }.Cause
In
getBodyContentEntry(packages/openapi3/src/openapi.ts), the 3.2.0 stream branch builds the media type withattachSSEItemSchemaand returns it as soon as it is not empty. The@opExamplevalues were only turned intoexample/examplesafter 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
itemSchemamedia 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 placesexamplesnext toitemSchemathe same way as next toschema(section 4.14.6.2), and the JSONL example in that section also puts the whole raw stream in a singlevalue.The playground example from the issue now gives:
A
JsonlStreamof an@eventsunion 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 noitemSchema(for example aJsonlStreamof a plain model) already took the regular path and are unchanged.Tests
New tests in
test/sse.test.tscompile the example from the issue:examplesis emitted next toitemSchema. This fails onmain(examplesisundefined) and passes with the fix.examplesis still emitted next toschema: { type: string }, with thestreams-not-supportedwarning. These pass before and after.The full
@typespec/openapi3test suite passes (74 files, 2706 tests).prettier --check,oxlint --type-aware --deny-warningsandcspellare clean on the changed files.