Skip to content

Commit

Permalink
fix: fdr generates stream examples correctly (#822)
Browse files Browse the repository at this point in the history
  • Loading branch information
abvthecity authored May 10, 2024
1 parent 8d96e84 commit 1b18dc5
Show file tree
Hide file tree
Showing 3 changed files with 194 additions and 5,055 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,7 @@ export function generateEndpointNonStreamResponseExample({
return {
...generateBaseEndpointExample({ endpointDefinition, apiDefinition, resolveTypeById }),
responseStatusCode: 200,
responseBodyV3: {
type: "json",
value: generateHttpResponseBodyExample(nonStreamResponse.shape, resolveTypeById),
},
responseBodyV3: generateHttpResponseBodyExample(nonStreamResponse.shape, resolveTypeById),
};
}

Expand All @@ -64,15 +61,10 @@ export function generateEndpointStreamResponseExample({
}): APIV1Write.ExampleEndpointCall {
const resolveTypeById = getResolveByTypeId(apiDefinition);

const responseChunkExample = generateHttpResponseBodyExample(streamResponse.shape, resolveTypeById);
return {
...generateBaseEndpointExample({ endpointDefinition, apiDefinition, resolveTypeById }),
responseStatusCode: 200,
responseBodyV3: {
type: "stream",
value: responseChunkExample != null ? [responseChunkExample, responseChunkExample] : [],
},
responseBody: undefined,
responseBodyV3: generateHttpResponseBodyExample(streamResponse.shape, resolveTypeById),
};
}

Expand All @@ -87,16 +79,9 @@ export function generateEndpointSuccessExample({
return {
...generateBaseEndpointExample({ endpointDefinition, apiDefinition, resolveTypeById }),
responseStatusCode: 200,
responseBody:
endpointDefinition.response != null
? generateHttpResponseBodyExample(endpointDefinition.response.type, resolveTypeById)
: undefined,
responseBodyV3:
endpointDefinition.response != null
? {
type: "json",
value: generateHttpResponseBodyExample(endpointDefinition.response.type, resolveTypeById),
}
? generateHttpResponseBodyExample(endpointDefinition.response.type, resolveTypeById)
: undefined,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,45 @@ function generateHttpJsonRequestBodyExample(
export function generateHttpResponseBodyExample(
type: APIV1Write.HttpResponseBodyShape,
resolveTypeById: ResolveTypeById,
): unknown {
): APIV1Write.ExampleEndpointResponse | undefined {
switch (type.type) {
case "object":
return generateExampleObject(type, resolveTypeById, false, new Set(), 0);
return {
type: "json",
value: generateExampleObject(type, resolveTypeById, false, new Set(), 0),
};
case "reference":
return generateExampleFromTypeReference(type.value, resolveTypeById, false, new Set(), 0);
return {
type: "json",
value: generateExampleFromTypeReference(type.value, resolveTypeById, false, new Set(), 0),
};
case "fileDownload":
return "";
return { type: "filename", value: "<filename>" };
case "streamingText":
return "example-text";
case "streamCondition":
return "example-text";
return { type: "stream", value: ["example-text"] };
case "stream": {
switch (type.shape.type) {
case "object":
return generateExampleObject(type.shape, resolveTypeById, false, new Set(), 0);
case "reference":
return generateExampleFromTypeReference(type.shape.value, resolveTypeById, false, new Set(), 0);
case "object": {
const chunk = generateExampleObject(type.shape, resolveTypeById, false, new Set(), 0);
return {
type: "stream",
value: [chunk, chunk],
};
}
case "reference": {
const chunk = generateExampleFromTypeReference(
type.shape.value,
resolveTypeById,
false,
new Set(),
0,
);
return {
type: "stream",
value: [chunk, chunk],
};
}
}
}
}
Expand Down
Loading

0 comments on commit 1b18dc5

Please sign in to comment.