Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo committed Aug 1, 2024
1 parent ab17c9f commit 741c4e1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 6 additions & 32 deletions packages/ui/app/src/api-playground/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -128,7 +127,6 @@ export function stringifyFetch({
}

const snippetTemplate = endpoint.snippetTemplates?.typescript;
const [resolvedTemplateSnippet, setResolvedTemplateSnippet] = useState<Snippets.Snippet | null>(null);

if (snippetTemplate != null && isSnippetTemplatesEnabled) {
const resolver = new SnippetTemplateResolver({
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -265,7 +251,6 @@ export function stringifyPythonRequests({
}

const snippetTemplate = endpoint.snippetTemplates?.python;
const [resolvedTemplateSnippet, setResolvedTemplateSnippet] = useState<Snippets.Snippet | null>(null);

if (snippetTemplate != null && isSnippetTemplatesEnabled) {
const resolver = new SnippetTemplateResolver({
Expand All @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion servers/fdr/src/controllers/snippets/getSnippetsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export function getSnippetsService(app: FdrApplication): SnippetsService {
endpointSnippetTemplate,
});

snippets.push(await templateResolver.resolve());
snippets.push(templateResolver.resolve());
}

return res.send(snippets);
Expand Down

0 comments on commit 741c4e1

Please sign in to comment.