From fa8ee2a067ada18ca2257b316b82dd2f48239798 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Tue, 2 Jan 2024 03:06:08 +0000 Subject: [PATCH 1/4] Allow generating SDKs locally without Fern token --- .../commands/generate/generateAPIWorkspace.ts | 7 ++++- .../generate/generateAPIWorkspaces.ts | 28 +++++++++++-------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts index cf280ba8c72..d96e85642ee 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts @@ -25,7 +25,7 @@ export async function generateWorkspace({ version: string | undefined; groupName: string | undefined; shouldLogS3Url: boolean; - token: FernToken; + token?: FernToken; useLocalDocker: boolean; keepDocker: boolean; }): Promise { @@ -59,6 +59,11 @@ export async function generateWorkspace({ context }); } else { + if (!token) { + return context.failAndThrow( + `Must provide token if 'useLocalDocker' is false` + ); + } await runRemoteGenerationForAPIWorkspace({ workspace, organization, diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts index 12aa50abe22..3b63072f495 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts @@ -1,4 +1,4 @@ -import { createOrganizationIfDoesNotExist } from "@fern-api/auth"; +import { createOrganizationIfDoesNotExist, FernToken, FernUserToken } from "@fern-api/auth"; import { askToLogin } from "@fern-api/login"; import { Project } from "@fern-api/project-loader"; import { convertOpenApiWorkspaceToFernWorkspace, FernWorkspace } from "@fern-api/workspace-loader"; @@ -22,20 +22,24 @@ export async function generateAPIWorkspaces({ useLocalDocker: boolean; keepDocker: boolean; }): Promise { - const token = await cliContext.runTask(async (context) => { - return askToLogin(context); - }); - - if (token.type === "user") { - await cliContext.runTask(async (context) => { - await createOrganizationIfDoesNotExist({ - organization: project.config.organization, - token, - context - }); + let token: FernToken | undefined = undefined; + if (!useLocalDocker) { + token = await cliContext.runTask(async (context) => { + return askToLogin(context); }); + + if (token.type === "user") { + await cliContext.runTask(async (context) => { + await createOrganizationIfDoesNotExist({ + organization: project.config.organization, + token: token as FernUserToken, + context + }); + }); + } } + cliContext.instrumentPostHogEvent({ orgId: project.config.organization, command: "fern generate", From e9557bc86e0c83180e71b82a53a23847e89d2aa3 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Tue, 2 Jan 2024 04:07:50 +0000 Subject: [PATCH 2/4] fmt --- .../cli/cli/src/commands/generate/generateAPIWorkspace.ts | 4 +--- .../cli/cli/src/commands/generate/generateAPIWorkspaces.ts | 3 +-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts index d96e85642ee..42e3f5a6f63 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts @@ -60,9 +60,7 @@ export async function generateWorkspace({ }); } else { if (!token) { - return context.failAndThrow( - `Must provide token if 'useLocalDocker' is false` - ); + return context.failAndThrow(`Must provide token if 'useLocalDocker' is false`); } await runRemoteGenerationForAPIWorkspace({ workspace, diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts index 3b63072f495..9c47fe4517c 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspaces.ts @@ -27,7 +27,7 @@ export async function generateAPIWorkspaces({ token = await cliContext.runTask(async (context) => { return askToLogin(context); }); - + if (token.type === "user") { await cliContext.runTask(async (context) => { await createOrganizationIfDoesNotExist({ @@ -39,7 +39,6 @@ export async function generateAPIWorkspaces({ } } - cliContext.instrumentPostHogEvent({ orgId: project.config.organization, command: "fern generate", From 7115173b4855d9d0455568aeb0ea2b39e3b1b3ee Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Tue, 2 Jan 2024 04:15:39 +0000 Subject: [PATCH 3/4] lint --- packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts index 42e3f5a6f63..45d99c36aa4 100644 --- a/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts +++ b/packages/cli/cli/src/commands/generate/generateAPIWorkspace.ts @@ -60,7 +60,7 @@ export async function generateWorkspace({ }); } else { if (!token) { - return context.failAndThrow(`Must provide token if 'useLocalDocker' is false`); + return context.failAndThrow("Must provide token if 'useLocalDocker' is false"); } await runRemoteGenerationForAPIWorkspace({ workspace, From aeead951a8a16e227386ad0599dae11fc447b77e Mon Sep 17 00:00:00 2001 From: MasterPtato Date: Thu, 15 Feb 2024 23:22:56 +0000 Subject: [PATCH 4/4] Remove `x-fern-*` headers from generated client --- .../src/GeneratedSdkClientClassImpl.ts | 44 +++++++++---------- .../src/AbstractGeneratorCli.ts | 2 + 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts b/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts index 323e8ef2514..eeef8712ad5 100644 --- a/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts +++ b/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts @@ -14,23 +14,23 @@ import { VariableDeclaration, VariableId } from "@fern-fern/ir-sdk/api"; -import { getTextOfTsNode, JavaScriptRuntime, maybeAddDocs, NpmPackage, PackageId } from "@fern-typescript/commons"; +import { JavaScriptRuntime, NpmPackage, PackageId, getTextOfTsNode, maybeAddDocs } from "@fern-typescript/commons"; import { GeneratedSdkClientClass, SdkContext } from "@fern-typescript/contexts"; import { ErrorResolver, PackageResolver } from "@fern-typescript/resolvers"; import { InterfaceDeclarationStructure, OptionalKind, PropertySignatureStructure, Scope, ts } from "ts-morph"; +import { GeneratedHeader } from "./GeneratedHeader"; +import { GeneratedWrappedService } from "./GeneratedWrappedService"; import { GeneratedDefaultEndpointRequest } from "./endpoint-request/GeneratedDefaultEndpointRequest"; import { GeneratedFileUploadEndpointRequest } from "./endpoint-request/GeneratedFileUploadEndpointRequest"; -import { GeneratedNonThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedNonThrowingEndpointResponse"; -import { GeneratedThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse"; -import { GeneratedDefaultEndpointImplementation } from "./endpoints/default/GeneratedDefaultEndpointImplementation"; import { GeneratedEndpointImplementation } from "./endpoints/GeneratedEndpointImplementation"; import { GeneratedFileDownloadEndpointImplementation } from "./endpoints/GeneratedFileDownloadEndpointImplementation"; import { GeneratedStreamingEndpointImplementation } from "./endpoints/GeneratedStreamingEndpointImplementation"; +import { GeneratedDefaultEndpointImplementation } from "./endpoints/default/GeneratedDefaultEndpointImplementation"; +import { GeneratedNonThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedNonThrowingEndpointResponse"; +import { GeneratedThrowingEndpointResponse } from "./endpoints/default/endpoint-response/GeneratedThrowingEndpointResponse"; import { getNonVariablePathParameters } from "./endpoints/utils/getNonVariablePathParameters"; import { getParameterNameForPathParameter } from "./endpoints/utils/getParameterNameForPathParameter"; import { getLiteralValueForHeader, isLiteralHeader } from "./endpoints/utils/isLiteralHeader"; -import { GeneratedHeader } from "./GeneratedHeader"; -import { GeneratedWrappedService } from "./GeneratedWrappedService"; export declare namespace GeneratedSdkClientClassImpl { export interface Init { @@ -483,24 +483,24 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass { this.getReferenceToOption(this.getOptionKeyForAuthHeader(header)) ) })), - { - header: this.intermediateRepresentation.sdkConfig.platformHeaders.language, - value: ts.factory.createStringLiteral("JavaScript") - } + // { + // header: this.intermediateRepresentation.sdkConfig.platformHeaders.language, + // value: ts.factory.createStringLiteral("JavaScript") + // } ]; - if (this.npmPackage != null) { - headers.push( - { - header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkName, - value: ts.factory.createStringLiteral(this.npmPackage.packageName) - }, - { - header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkVersion, - value: ts.factory.createStringLiteral(this.npmPackage.version) - } - ); - } + // if (this.npmPackage != null) { + // headers.push( + // { + // header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkName, + // value: ts.factory.createStringLiteral(this.npmPackage.packageName) + // }, + // { + // header: this.intermediateRepresentation.sdkConfig.platformHeaders.sdkVersion, + // value: ts.factory.createStringLiteral(this.npmPackage.version) + // } + // ); + // } return headers; } diff --git a/generators/typescript/utils/abstract-generator-cli/src/AbstractGeneratorCli.ts b/generators/typescript/utils/abstract-generator-cli/src/AbstractGeneratorCli.ts index d5e439d27e4..bd6a892daf4 100644 --- a/generators/typescript/utils/abstract-generator-cli/src/AbstractGeneratorCli.ts +++ b/generators/typescript/utils/abstract-generator-cli/src/AbstractGeneratorCli.ts @@ -33,6 +33,8 @@ export abstract class AbstractGeneratorCli { public async run(pathToConfig: string): Promise { const configStr = await readFile(pathToConfig); const rawConfig = JSON.parse(configStr.toString()); + // Fix weird bug + rawConfig.whitelabel = false; const config = await GeneratorExecParsing.GeneratorConfig.parseOrThrow( { ...rawConfig,