diff --git a/packages/template-resolver/src/SnippetTemplateResolutionHolder.ts b/packages/template-resolver/src/SnippetTemplateResolutionHolder.ts index 613e8aa9ec..082d590b64 100644 --- a/packages/template-resolver/src/SnippetTemplateResolutionHolder.ts +++ b/packages/template-resolver/src/SnippetTemplateResolutionHolder.ts @@ -14,8 +14,8 @@ export class SnippetTemplateResolutionHolder { maybeApiDefinition, maybeApiDefinitionId, }: { - maybeApiDefinition: APIV1Read.ApiDefinition | undefined; - maybeApiDefinitionId: string | undefined; + maybeApiDefinition?: APIV1Read.ApiDefinition; + maybeApiDefinitionId?: string; }) { this.maybeApiDefinition = maybeApiDefinition; this.maybeApiDefinitionId = maybeApiDefinitionId; diff --git a/packages/ui/app/src/api-playground/utils.ts b/packages/ui/app/src/api-playground/utils.ts index f28225a1a8..ae417095de 100644 --- a/packages/ui/app/src/api-playground/utils.ts +++ b/packages/ui/app/src/api-playground/utils.ts @@ -2,7 +2,6 @@ import { APIV1Read, Snippets } from "@fern-api/fdr-sdk"; import { SnippetTemplateResolver } from "@fern-api/template-resolver"; import { isNonNullish, isPlainObject, visitDiscriminatedUnion } from "@fern-ui/core-utils"; import { isEmpty, mapValues } from "lodash-es"; -import { useEffect, useState } from "react"; import { stringifyHttpRequestExampleToCurl } from "../api-page/examples/stringifyHttpRequestExampleToCurl"; import { ResolvedEndpointDefinition, @@ -128,7 +127,6 @@ export function stringifyFetch({ } const snippetTemplate = endpoint.snippetTemplates?.typescript; - const [resolvedTemplateSnippet, setResolvedTemplateSnippet] = useState(null); if (snippetTemplate != null && isSnippetTemplatesEnabled) { const resolver = new SnippetTemplateResolver({ @@ -146,22 +144,10 @@ export function stringifyFetch({ snippetTemplate, }, }); + const resolvedTemplate = resolver.resolve(); - // TODO: We should expose a .unresolve() method or similar on - // the resolved APIDefinition, so we can just pass that to - // .resolveWithFormatting() instead of having the resolver make a DB call - useEffect(() => { - const resolveTemplate = async () => { - const resolvedTemplate = await resolver.resolveWithFormatting(); - - setResolvedTemplateSnippet(resolvedTemplate); - }; - - resolveTemplate(); - }, []); - - if (resolvedTemplateSnippet && resolvedTemplateSnippet.type === "typescript") { - return resolvedTemplateSnippet.client; + if (resolvedTemplate.type === "typescript") { + return resolvedTemplate.client; } } @@ -265,7 +251,6 @@ export function stringifyPythonRequests({ } const snippetTemplate = endpoint.snippetTemplates?.python; - const [resolvedTemplateSnippet, setResolvedTemplateSnippet] = useState(null); if (snippetTemplate != null && isSnippetTemplatesEnabled) { const resolver = new SnippetTemplateResolver({ @@ -284,21 +269,10 @@ export function stringifyPythonRequests({ }, }); - // TODO: We should expose a .unresolve() method or similar on - // the resolved APIDefinition, so we can just pass that to - // .resolveWithFormatting() instead of having the resolver make a DB call - useEffect(() => { - const resolveTemplate = async () => { - const resolvedTemplate = await resolver.resolveWithFormatting(); - - setResolvedTemplateSnippet(resolvedTemplate); - }; - - resolveTemplate(); - }, []); + const resolvedTemplate = resolver.resolve(); - if (resolvedTemplateSnippet && resolvedTemplateSnippet.type === "python") { - return resolvedTemplateSnippet.sync_client; + if (resolvedTemplate.type === "python") { + return resolvedTemplate.sync_client; } } diff --git a/servers/fdr/src/controllers/snippets/getSnippetsService.ts b/servers/fdr/src/controllers/snippets/getSnippetsService.ts index 4d03f71054..20da24852b 100644 --- a/servers/fdr/src/controllers/snippets/getSnippetsService.ts +++ b/servers/fdr/src/controllers/snippets/getSnippetsService.ts @@ -83,7 +83,7 @@ export function getSnippetsService(app: FdrApplication): SnippetsService { endpointSnippetTemplate, }); - snippets.push(await templateResolver.resolve()); + snippets.push(templateResolver.resolve()); } return res.send(snippets);