-
Notifications
You must be signed in to change notification settings - Fork 351
Add OpenAPI 3.2 stream emission support with itemSchema #8888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 36 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
2b81e2f
Initial plan
Copilot 28788d5
Add SSE support infrastructure to OpenAPI 3.2
Copilot 9df9947
WIP: Add SSE support with debugging - stream detection in progress
Copilot 691b8b3
Merge branch 'main' into copilot/add-sse-support-to-openapi
baywet ac730e6
tests: fixes version requested for emission of streaming events
baywet 9d8fa9a
docs: adds the chronus entry for SSE support
baywet c64d3a4
chore: formatting
baywet 1caa061
chore: typo fix
baywet 559641d
Remove debug console.log statements
Copilot ca5cc53
chore: linting
baywet e6b39f7
fix: extension decorator should be used for terminal event
baywet 63c2f9d
tests: adds SEE import tests
baywet b949e79
Merge branch 'main' into copilot/add-sse-support-to-openapi
baywet 4ce7033
tests: fixes test definition for sse support
baywet 8ce3759
fix: extension is not getting emitted
baywet 0cb0f0c
chore: formatting
baywet b1f5ea6
feat; emit a warning when trying to emit sse on lower openapi versions
baywet 4154e85
tests: updates tests for see unsupported to also cover version 3.0.0
baywet 28c5cbc
Update .chronus/changes/copilot-add-sse-support-to-openapi-2025-10-3-…
baywet dfe7f1b
Refactor SSE tests and generalize stream support
Copilot dfc5338
tests: fixes badly indented extension in import definition
baywet 9766532
Merge branch 'main' into copilot/add-sse-support-to-openapi
baywet 3f5e1de
feat: import of sse
baywet fbd52ee
tests: linting
baywet df0c5de
Merge branch 'main' into copilot/add-sse-support-to-openapi
baywet e0ae77d
fix: use short name for events decorator when importing
baywet 3700ed7
fix: adds import for multipart request body in query and additional o…
baywet 4dde6a8
chore: refactoring
baywet 609f631
chore: refactor duplicated implementation of reference resolution
baywet f4db16f
fix: regression after events name change
baywet 5fa331b
chore: refactor duplicated constant
baywet 9e1f0b2
chore: refactoring to its own method
baywet cd74d5d
dev: adds a quick build script to make the local dev loop faster
baywet 2688d07
chore: refactoring to remove casts to any
baywet 1adfa34
Merge branch 'main' into copilot/add-sse-support-to-openapi
baywet e190414
chore: adds acronym to dictionary
baywet c2e5c76
chore: better types for the unit test definition
baywet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/copilot-add-sse-support-to-openapi-2025-10-3-14-40-45.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@typespec/openapi3" | ||
| --- | ||
|
|
||
| adds support for emission and import of SSE for OpenAPI 3.2 |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,6 +220,29 @@ function generateResponseExpressions({ | |
| } | ||
|
|
||
| return contents.map(([mediaType, content]) => { | ||
| // Special handling for Server-Sent Events | ||
| if (mediaType === "text/event-stream") { | ||
| context.markSSEUsage(); | ||
|
|
||
| // Check for itemSchema (OpenAPI 3.2 extension) | ||
| if ("itemSchema" in content && content.itemSchema) { | ||
| const itemSchema = content.itemSchema; | ||
| if (itemSchema && typeof itemSchema === "object" && "$ref" in itemSchema) { | ||
| const eventUnionType = context.generateTypeFromRefableSchema(itemSchema, operationScope); | ||
| return `SSEStream<${eventUnionType}>`; | ||
| } | ||
| } else if (content.schema && "$ref" in content.schema) { | ||
| // Fallback: use schema directly if no itemSchema | ||
| const eventUnionType = context.generateTypeFromRefableSchema( | ||
| content.schema, | ||
| operationScope, | ||
| ); | ||
| return `SSEStream<${eventUnionType}>`; | ||
|
Comment on lines
+234
to
+240
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong, we shouldn't fallback on the main schema for streaming as schema is bounded and that does not work with streams which don't have collections bounds |
||
| } | ||
|
|
||
| // If no proper schema reference, fall through to regular handling | ||
| } | ||
|
|
||
| // Attempt to emit just the Body or an intersection of Body & MappedResponse | ||
| // if there aren't any custom headers. | ||
| const bodySchema = content.schema; | ||
|
|
||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be moved down to the condition when we detected a valid case