Skip to content

Commit

Permalink
fix(cli): generate sse examples (#5420)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi authored Dec 15, 2024
1 parent f0ee23d commit 8f7ce9f
Show file tree
Hide file tree
Showing 12 changed files with 288 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ export class ExampleEndpointFactory {
if (example != null) {
if (endpoint.response?.type === "json") {
responseExamples.push([undefined, EndpointResponseExample.withoutStreaming(example)]);
} else if (endpoint.response?.type === "streamingJson") {
} else if (
endpoint.response?.type === "streamingJson" ||
endpoint.response?.type === "streamingSse"
) {
responseExamples.push([undefined, EndpointResponseExample.withStreaming([example])]);
}
}
Expand All @@ -131,7 +134,10 @@ export class ExampleEndpointFactory {
if (example != null) {
if (endpoint.response?.type === "json") {
responseExamples.push([exampleId, EndpointResponseExample.withoutStreaming(example)]);
} else if (endpoint.response?.type === "streamingJson") {
} else if (
endpoint.response?.type === "streamingJson" ||
endpoint.response?.type === "streamingSse"
) {
responseExamples.push([exampleId, EndpointResponseExample.withStreaming([example])]);
}
}
Expand Down Expand Up @@ -493,7 +499,7 @@ function getResponseSchema(response: ResponseWithExample | null | undefined): Sc
if (response == null) {
return undefined;
}
if (response.type !== "json" && response.type !== "streamingJson") {
if (response.type !== "json" && response.type !== "streamingJson" && response.type !== "streamingSse") {
return { type: "unsupported" };
}
return { type: "present", schema: response.schema, examples: response.fullExamples ?? [] };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,14 @@ function convertResolvedResponse({
return ResponseWithExample.streamingSse({
description: resolvedResponse.description,
responseProperty: undefined,
schema: convertSchemaWithExampleToSchema(
convertSchema(
textEventStreamObject.schema,
false,
context,
responseBreadcrumbs,
source,
namespace
)
fullExamples: textEventStreamObject.examples,
schema: convertSchema(
textEventStreamObject.schema,
false,
context,
responseBreadcrumbs,
source,
namespace
),
source
});
Expand Down Expand Up @@ -209,15 +208,14 @@ function convertResolvedResponse({
return ResponseWithExample.streamingSse({
description: resolvedResponse.description,
responseProperty: undefined,
schema: convertSchemaWithExampleToSchema(
convertSchema(
jsonMediaObject.schema,
false,
context,
responseBreadcrumbs,
source,
namespace
)
fullExamples: jsonMediaObject.examples,
schema: convertSchema(
jsonMediaObject.schema,
false,
context,
responseBreadcrumbs,
source,
namespace
),
source
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2101,6 +2101,27 @@ service:
"root.SessionsEventsRequestUnprocessableEntityError",
"root.SessionsEventsRequestInternalServerError",
],
"examples": [
{
"path-parameters": {
"id": "6aac6f73-bd89-4a76-ab32-5a6c422e8b0b",
},
"response": {
"stream": [
{
"data": {
"code": "code",
"event": "event",
"message": "message",
},
"event": "error",
"id": 1,
"retry": 1,
},
],
},
},
],
"method": "GET",
"pagination": undefined,
"path": "/sessions/{id}/events",
Expand Down Expand Up @@ -2771,6 +2792,18 @@ service:
- root.SessionsEventsRequestNotFoundError
- root.SessionsEventsRequestUnprocessableEntityError
- root.SessionsEventsRequestInternalServerError
examples:
- path-parameters:
id: 6aac6f73-bd89-4a76-ab32-5a6c422e8b0b
response:
stream:
- event: error
data:
code: code
event: event
message: message
id: 1
retry: 1
audiences:
- public
source:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
"create": {
"auth": false,
"docs": undefined,
"examples": [
{
"request": {
"prompt": "prompt",
},
"response": {
"stream": [
"string",
],
},
},
],
"method": "POST",
"pagination": undefined,
"path": "/completions/chat",
Expand Down Expand Up @@ -103,6 +115,12 @@
docs: Success!
type: string
format: sse
examples:
- request:
prompt: prompt
response:
stream:
- string
source:
openapi: ../openapi.yml
",
Expand Down
Loading

0 comments on commit 8f7ce9f

Please sign in to comment.