-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restored most functionality and fixed some visual bugs
- Loading branch information
1 parent
13a1382
commit 42ff098
Showing
6 changed files
with
59 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,10 @@ | ||
import { EndpointDefinition } from "@fern-api/fdr-sdk/api-definition"; | ||
import { useMemo } from "react"; | ||
import { usePlaygroundBaseUrl } from "../utils/select-environment"; | ||
import { PlaygroundCodeSnippetResolver } from "./resolver"; | ||
import { useApiDefinition } from "./useApiDefinition"; | ||
|
||
export const resolveEnvironmentUrlInCodeSnippet = ( | ||
endpoint: EndpointDefinition, | ||
replacementBaseUrl: string | undefined, | ||
requestCodeSnippet: string, | ||
): string => { | ||
const urlToReplace = endpoint.environments?.find((env) => requestCodeSnippet.includes(env.baseUrl))?.baseUrl; | ||
return urlToReplace && replacementBaseUrl | ||
? requestCodeSnippet.replace(urlToReplace, replacementBaseUrl) | ||
: requestCodeSnippet; | ||
}; | ||
|
||
export function useSnippet(resolver: PlaygroundCodeSnippetResolver, lang: "curl" | "python" | "typescript"): string { | ||
const apiDefinition = useApiDefinition(resolver.context.node.apiDefinitionId, resolver.isSnippetTemplatesEnabled); | ||
const baseUrl = usePlaygroundBaseUrl(resolver.context.endpoint); | ||
|
||
// Resolve the code snippet | ||
const code = useMemo(() => resolver.resolve(lang, apiDefinition), [resolver, lang, apiDefinition]); | ||
return resolveEnvironmentUrlInCodeSnippet(resolver.context.endpoint, baseUrl, code); | ||
return useMemo(() => resolver.resolve(lang, apiDefinition), [resolver, lang, apiDefinition]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters