diff --git a/packages/fdr-sdk/src/api-definition/snippets/backfill.test.ts b/packages/fdr-sdk/src/api-definition/snippets/backfill.test.ts index e40db99e92..59cc955371 100644 --- a/packages/fdr-sdk/src/api-definition/snippets/backfill.test.ts +++ b/packages/fdr-sdk/src/api-definition/snippets/backfill.test.ts @@ -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: { @@ -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(); diff --git a/packages/fdr-sdk/src/api-definition/snippets/backfill.ts b/packages/fdr-sdk/src/api-definition/snippets/backfill.ts index 424f179c93..edb7a5dec8 100644 --- a/packages/fdr-sdk/src/api-definition/snippets/backfill.ts +++ b/packages/fdr-sdk/src/api-definition/snippets/backfill.ts @@ -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; }