Skip to content

Commit

Permalink
chore(snippets): generate curl snippets for api reference
Browse files Browse the repository at this point in the history
  • Loading branch information
dsinghvi committed Jan 15, 2025
1 parent b46c59e commit 4663d78
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/fern-docs/cache/src/ApiDefinitionLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
ApiDefinitionId,
ApiDefinitionV1ToLatest,
Transformer,
convertToCurl,
prune,
toSnippetHttpRequest,
type ApiDefinition,
type CodeSnippet,
type EndpointDefinition,
Expand Down Expand Up @@ -249,6 +251,29 @@ export class ApiDefinitionLoader {
(snippets[snippet.language] ??= []).push(snippet);
};

// Check if curl snippet exists
if (!snippets[APIV1Read.SupportedLanguage.Curl]?.length) {
const endpointAuth = endpoint.auth?.[0];
const curlCode = convertToCurl(
toSnippetHttpRequest(
endpoint,
example,
endpointAuth != null ? apiDefinition.auths[endpointAuth] : undefined
),
{
usesApplicationJsonInFormDataValue: false,
}
);
pushSnippet({
name: undefined,
language: APIV1Read.SupportedLanguage.Curl,
install: undefined,
code: curlCode,
generated: true,
description: undefined,
});
}

const snippet = new HTTPSnippet(
getHarRequest(endpoint, example, apiDefinition.auths, example.requestBody)
);
Expand Down

0 comments on commit 4663d78

Please sign in to comment.