Skip to content
Merged
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
101 changes: 99 additions & 2 deletions packages/fdr-sdk/src/api-definition/snippets/backfill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,103 @@ describe("backfillSnippets", () => {
expect(snippets?.swift).toBeUndefined();
});

it("should exclude curl when not specified in the language list", async () => {
it("should always include curl even when httpSnippets is false", async () => {
const apiDefinition: ApiDefinition = {
id: ApiDefinitionId("test-api"),
endpoints: {
[EndpointId("search")]: {
id: EndpointId("search"),
method: "POST",
path: [{ type: "literal", value: "/" }],
displayName: undefined,
operationId: undefined,
auth: undefined,
defaultEnvironment: undefined,
environments: [
{
id: EnvironmentId("default"),
baseUrl: "https://api.example.com/v1"
}
],
pathParameters: undefined,
queryParameters: undefined,
requestHeaders: undefined,
responseHeaders: undefined,
requests: undefined,
responses: undefined,
errors: undefined,
snippetTemplates: undefined,
protocol: undefined,
description: undefined,
availability: undefined,
namespace: undefined,
examples: [
{
name: "Basic Search",
description: "",
path: "/",
pathParameters: {},
queryParameters: {},
headers: {},
requestBody: {
type: "json",
value: {
query: "test"
}
},
responseStatusCode: 200,
responseBody: {
type: "json",
value: {
results: []
}
},
snippets: undefined
}
]
}
},
auths: {},
websockets: {},
webhooks: {},
types: {},
globalHeaders: [],
subpackages: {},
snippetsConfiguration: undefined
};

const flags = {
httpSnippets: false,
alwaysEnableJavaScriptFetch: true
};

const result = await backfillSnippets(apiDefinition, undefined, flags);

const endpoint = result.endpoints[EndpointId("search")];
expect(endpoint).toBeDefined();
const examples = endpoint?.examples;
expect(examples).toHaveLength(1);

const example = examples?.[0];
expect(example).toBeDefined();

const snippets = example?.snippets;
expect(snippets).toBeDefined();

expect(snippets?.curl).toBeDefined();
expect(snippets?.curl).toHaveLength(1);

expect(snippets?.python).toBeUndefined();
expect(snippets?.javascript).toBeUndefined();
expect(snippets?.go).toBeUndefined();
expect(snippets?.ruby).toBeUndefined();
expect(snippets?.java).toBeUndefined();
expect(snippets?.php).toBeUndefined();
expect(snippets?.csharp).toBeUndefined();
expect(snippets?.swift).toBeUndefined();
});

it("should always include curl even when not specified in the language list", async () => {
const apiDefinition: ApiDefinition = {
id: ApiDefinitionId("test-api"),
endpoints: {
Expand Down Expand Up @@ -202,7 +298,8 @@ describe("backfillSnippets", () => {
const snippets = example?.snippets;
expect(snippets).toBeDefined();

expect(snippets?.curl).toBeUndefined();
expect(snippets?.curl).toBeDefined();
expect(snippets?.curl).toHaveLength(1);
expect(snippets?.python).toBeDefined();
expect(snippets?.python).toHaveLength(1);
expect(snippets?.javascript).toBeDefined();
Expand Down
9 changes: 7 additions & 2 deletions packages/fdr-sdk/src/api-definition/snippets/backfill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,14 @@ async function backfillSnippetsForExample(
const httpSnippetLanguages = Array.isArray(httpSnippets) ? httpSnippets : null;

// Check if a language should be included in HTTP snippets (important-comment)
// If httpSnippets is true (boolean), include all languages
// If httpSnippets is an array, only include languages in the array
// curl is ALWAYS included regardless of httpSnippets configuration
// If httpSnippets is true (boolean), include all languages (important-comment)
// If httpSnippets is an array, only include languages in the array (important-comment)
const shouldIncludeLanguage = (language: string): boolean => {
// curl is always included, even when httpSnippets is false
if (language === "curl") {
return true;
}
if (!isHttpSnippetsEnabled) {
return false;
}
Expand Down