Skip to content

Commit

Permalink
allow passing in environment
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo committed Aug 1, 2024
1 parent 741c4e1 commit d9f9e4d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
7 changes: 5 additions & 2 deletions packages/template-resolver/src/ResolutionUtilities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { APIV1Read, FdrClient } from "@fern-api/fdr-sdk";

export async function getApiDefinition(apiDefinitionId: string): Promise<APIV1Read.ApiDefinition | undefined> {
const fdr = new FdrClient();
export async function getApiDefinition(
apiDefinitionId: string,
environment: string | undefined,
): Promise<APIV1Read.ApiDefinition | undefined> {
const fdr = new FdrClient({ environment });
const apiDefinitionResponse = await fdr.api.v1.read.getApi(apiDefinitionId);
if (apiDefinitionResponse.ok) {
return apiDefinitionResponse.body;
Expand Down
22 changes: 14 additions & 8 deletions packages/template-resolver/src/SnippetTemplateResolutionHolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@ export class SnippetTemplateResolutionHolder {
private maybeObjectFlattener: ObjectFlattener | undefined;
private maybeApiDefinitionId: string | undefined;

private fdrEnvironmentUrl: string | undefined;

private apiDefinitionHasBeenRequested: boolean;

constructor({
maybeApiDefinition,
maybeApiDefinitionId,
}: {
maybeApiDefinition?: APIV1Read.ApiDefinition;
maybeApiDefinitionId?: string;
}) {
constructor(
{
maybeApiDefinition,
maybeApiDefinitionId,
}: {
maybeApiDefinition?: APIV1Read.ApiDefinition;
maybeApiDefinitionId?: string;
},
environment?: string,
) {
this.fdrEnvironmentUrl = environment;
this.maybeApiDefinition = maybeApiDefinition;
this.maybeApiDefinitionId = maybeApiDefinitionId;

Expand All @@ -37,7 +43,7 @@ export class SnippetTemplateResolutionHolder {
// If we were not provided an API definition, try to get it from FDR
if (this.maybeApiDefinitionId != null && !this.apiDefinitionHasBeenRequested) {
this.apiDefinitionHasBeenRequested = true;
this.maybeApiDefinition = await getApiDefinition(this.maybeApiDefinitionId);
this.maybeApiDefinition = await getApiDefinition(this.maybeApiDefinitionId, this.fdrEnvironmentUrl);
return this.maybeApiDefinition;
}

Expand Down

0 comments on commit d9f9e4d

Please sign in to comment.