Skip to content

feat: adds support for describing SSE in OpenAPI 3.2.0#67461

Merged
Youssef1313 merged 9 commits into
dotnet:mainfrom
baywet:feat/sse-openapi
Jul 7, 2026
Merged

feat: adds support for describing SSE in OpenAPI 3.2.0#67461
Youssef1313 merged 9 commits into
dotnet:mainfrom
baywet:feat/sse-openapi

Conversation

@baywet

@baywet baywet commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

fixes #64379

Examples

# SseItem<Todo>
responses:
  '200':
    description: OK
    content:
      text/event-stream:
        itemSchema:
          type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/Todo'
            event:
              type: string
            id:
              type: string

# SseItem<UnionPet> where UnionPet = Kitten | Puppy
responses:
  '200':
    description: OK
    content:
      text/event-stream:
        itemSchema:
          type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/UnionPet'
            event:
              type: string
              enum:
                - Kitten
                - Puppy
            id:
              type: string

# SseItem<Vehicle>, where Vehicle is an abstract base type with JSON discriminators
responses:
  '200':
    description: OK
    content:
      text/event-stream:
        itemSchema:
          type: object
          required:
            - data
          properties:
            data:
              $ref: '#/components/schemas/Vehicle'
            event:
              type: string
              enum:
                - car
                - truck
                - plane
            id:
              type: string

CC @martincostello

Copilot AI review requested due to automatic review settings June 29, 2026 14:50
@baywet baywet requested a review from a team as a code owner June 29, 2026 14:50

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.

Pull request overview

Adds OpenAPI document generation support for Server-Sent Events (SSE) responses by emitting OpenAPI 3.2-style sequential media type metadata (itemSchema) for text/event-stream, including deriving event enum values from unions and polymorphic discriminator mappings.

Changes:

  • Detect text/event-stream responses whose response type is SseItem<T> and emit an SSE “item schema” instead of a normal media-type schema.
  • Populate the SSE item schema with data, event, and id properties, and infer event enums from union cases and discriminator mappings when available.
  • Add tests validating itemSchema usage and event enum inference for plain, union, and discriminator-based payload types.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/OpenApi/src/Services/OpenApiDocumentService.cs Detect SSE responses and generate text/event-stream media types using ItemSchema, including event enum inference from unions/discriminators.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentService/OpenApiDocumentServiceTests.Responses.cs Adds coverage for SSE itemSchema output and validates event schema behavior for different payload shapes.

Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
@baywet baywet changed the title feat/sse openapi feat: adds support for describing SSE in OpenAPI 3.2.0 Jun 29, 2026
@baywet baywet requested a review from Copilot June 29, 2026 16:29

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.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
baywet added 8 commits July 2, 2026 12:48
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
Signed-off-by: Vincent Biret <vincentbiret@hotmail.com>
Comment thread src/OpenApi/src/Services/OpenApiDocumentService.cs Outdated
Co-authored-by: Stephen Halter <shalter+msft@microsoft.com>
@baywet baywet requested a review from halter73 July 3, 2026 12:11
@Youssef1313 Youssef1313 merged commit cf20285 into dotnet:main Jul 7, 2026
25 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 8, 2026
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.

OpenAPI 3.2 Support for Server Sent Events

5 participants