fix(openapi3): emit SSE response examples on OpenAPI 3.2.0 by Thanatos9404 · Pull Request #12291 · microsoft/typespec · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/openapi3/src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,8 @@ function createOAPIEmitter(
return { schema: getRawBinarySchema(contentType) } as OpenAPI3MediaType;
}

const oai3Examples = examples && getExampleOrExamples(program, examples);

// Check if this is a stream response (only for responses)
if (sseModule && isResponseContent) {
// Use getStreamMetadata to check if this is a stream response
Expand All @@ -1278,13 +1280,12 @@ function createOAPIEmitter(
(type: Type) => callSchemaEmitter(type, visibility, false, "application/json"),
);
if (Object.keys(mediaType).length > 0) {
return mediaType;
return { ...mediaType, ...oai3Examples };
}
}
}
}

const oai3Examples = examples && getExampleOrExamples(program, examples);
switch (body.bodyKind) {
case "single":
return {
Expand Down
53 changes: 53 additions & 0 deletions packages/openapi3/test/sse.test.ts