diff --git a/.eslintrc.js b/.eslintrc.js index 3aba8b6ca73..1b18e45c8d1 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -67,12 +67,7 @@ module.exports = { ignoreRestSiblings: true } ], - "@typescript-eslint/no-namespace": [ - "error", - { - allowDeclarations: true - } - ], + "@typescript-eslint/no-namespace": "off", "@typescript-eslint/explicit-module-boundary-types": [ "error", { @@ -129,7 +124,7 @@ module.exports = { { files: ['**/*.test.ts', '**/*.spec.ts'], rules: { - 'no-console': 'off' + 'no-console': 'off' } } ] diff --git a/generators/typescript/express/express-service-generator/src/GeneratedExpressServiceImpl.ts b/generators/typescript/express/express-service-generator/src/GeneratedExpressServiceImpl.ts index f0cff49a060..8991adf9530 100644 --- a/generators/typescript/express/express-service-generator/src/GeneratedExpressServiceImpl.ts +++ b/generators/typescript/express/express-service-generator/src/GeneratedExpressServiceImpl.ts @@ -7,7 +7,7 @@ import { Package, PathParameter } from "@fern-fern/ir-sdk/api"; -import { convertHttpPathToExpressRoute, getTextOfTsNode, maybeAddDocs, PackageId } from "@fern-typescript/commons"; +import { convertHttpPathToExpressRoute, getTextOfTsNode, maybeAddDocsNode, PackageId } from "@fern-typescript/commons"; import { ExpressContext, GeneratedExpressService } from "@fern-typescript/contexts"; import { ClassDeclaration, InterfaceDeclaration, Scope, ts } from "ts-morph"; @@ -82,7 +82,7 @@ export class GeneratedExpressServiceImpl implements GeneratedExpressService { name: this.serviceClassName, isExported: true }); - maybeAddDocs(serviceClass, this.package_.docs); + maybeAddDocsNode(serviceClass, this.package_.docs); serviceClass.addProperty({ scope: Scope.Private, diff --git a/generators/typescript/model/type-generator/src/alias/GeneratedAliasTypeImpl.ts b/generators/typescript/model/type-generator/src/alias/GeneratedAliasTypeImpl.ts index cace05d9a62..f2ba8810728 100644 --- a/generators/typescript/model/type-generator/src/alias/GeneratedAliasTypeImpl.ts +++ b/generators/typescript/model/type-generator/src/alias/GeneratedAliasTypeImpl.ts @@ -1,5 +1,11 @@ import { ExampleTypeShape, TypeReference } from "@fern-fern/ir-sdk/api"; -import { GetReferenceOpts, getTextOfTsNode, maybeAddDocs, writerToString } from "@fern-typescript/commons"; +import { + GetReferenceOpts, + getTextOfTsNode, + maybeAddDocsNode, + maybeAddDocsStructure, + writerToString +} from "@fern-typescript/commons"; import { BaseContext, NotBrandedGeneratedAliasType } from "@fern-typescript/contexts"; import { ModuleDeclarationStructure, @@ -36,7 +42,7 @@ export class GeneratedAliasTypeImpl type: getTextOfTsNode(context.type.getReferenceToType(this.shape).typeNode), isExported: true }; - maybeAddDocs(typeAlias, this.getDocs(context)); + maybeAddDocsStructure(typeAlias, this.getDocs(context)); return typeAlias; } diff --git a/generators/typescript/model/type-generator/src/alias/GeneratedBrandedStringAliasImpl.ts b/generators/typescript/model/type-generator/src/alias/GeneratedBrandedStringAliasImpl.ts index aca5a9765c7..e700272c7aa 100644 --- a/generators/typescript/model/type-generator/src/alias/GeneratedBrandedStringAliasImpl.ts +++ b/generators/typescript/model/type-generator/src/alias/GeneratedBrandedStringAliasImpl.ts @@ -3,7 +3,8 @@ import { GetReferenceOpts, getTextOfTsKeyword, getTextOfTsNode, - maybeAddDocs, + maybeAddDocsNode, + maybeAddDocsStructure, writerToString } from "@fern-typescript/commons"; import { BrandedGeneratedAliasType, BaseContext } from "@fern-typescript/contexts"; @@ -73,7 +74,7 @@ export class GeneratedBrandedStringAliasImpl ), isExported: true }; - maybeAddDocs(typeAlias, this.getDocs(context)); + maybeAddDocsStructure(typeAlias, this.getDocs(context)); return typeAlias; } diff --git a/generators/typescript/model/type-generator/src/enum/GeneratedEnumTypeImpl.ts b/generators/typescript/model/type-generator/src/enum/GeneratedEnumTypeImpl.ts index 87158f9830d..df5a6ac7e10 100644 --- a/generators/typescript/model/type-generator/src/enum/GeneratedEnumTypeImpl.ts +++ b/generators/typescript/model/type-generator/src/enum/GeneratedEnumTypeImpl.ts @@ -3,7 +3,8 @@ import { GetReferenceOpts, getTextOfTsNode, getWriterForMultiLineUnionType, - maybeAddDocs + maybeAddDocsNode, + maybeAddDocsStructure } from "@fern-typescript/commons"; import { BaseContext, GeneratedEnumType } from "@fern-typescript/contexts"; import { @@ -59,7 +60,7 @@ export class GeneratedEnumTypeImpl ) }; - maybeAddDocs(type, this.getDocs(context)); + maybeAddDocsStructure(type, this.getDocs(context)); return type; } diff --git a/generators/typescript/model/type-generator/src/object/GeneratedObjectTypeImpl.ts b/generators/typescript/model/type-generator/src/object/GeneratedObjectTypeImpl.ts index 355e6dfbbcb..922adde37ba 100644 --- a/generators/typescript/model/type-generator/src/object/GeneratedObjectTypeImpl.ts +++ b/generators/typescript/model/type-generator/src/object/GeneratedObjectTypeImpl.ts @@ -6,7 +6,13 @@ import { TypeDeclaration, TypeReference } from "@fern-fern/ir-sdk/api"; -import { GetReferenceOpts, getTextOfTsNode, maybeAddDocs, TypeReferenceNode } from "@fern-typescript/commons"; +import { + GetReferenceOpts, + getTextOfTsNode, + maybeAddDocsNode, + maybeAddDocsStructure, + TypeReferenceNode +} from "@fern-typescript/commons"; import { GeneratedObjectType, BaseContext } from "@fern-typescript/contexts"; import { InterfaceDeclarationStructure, @@ -71,9 +77,9 @@ export class GeneratedObjectTypeImpl return this.generatePropertiesInternal(context).map(({ name, type, hasQuestionToken, docs }) => { const propertyNode: PropertySignatureStructure = { kind: StructureKind.PropertySignature, - name: name, + name, type: getTextOfTsNode(type), - hasQuestionToken: hasQuestionToken, + hasQuestionToken, docs: docs != null ? [{ description: docs }] : undefined }; @@ -113,7 +119,7 @@ export class GeneratedObjectTypeImpl isExported: true }; - maybeAddDocs(interfaceNode, this.getDocs(context)); + maybeAddDocsStructure(interfaceNode, this.getDocs(context)); const iExtends = []; for (const extension of this.shape.extends) { iExtends.push(getTextOfTsNode(context.type.getReferenceToNamedType(extension).getTypeNode())); @@ -135,7 +141,9 @@ export class GeneratedObjectTypeImpl this.shape.properties .map((property): [ObjectProperty, NamedType] | undefined => { const namedType = getNamedType(property.valueType); - if (namedType) return [property, namedType]; + if (namedType) { + return [property, namedType]; + } return undefined; }) .filter((x): x is [ObjectProperty, NamedType] => x !== undefined) @@ -348,6 +356,7 @@ function getNamedType(typeReference: TypeReference): NamedType | undefined { default: assertNever(typeReference.container); } + // fallthrough case "primitive": return undefined; case "unknown": diff --git a/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts b/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts index e846470d4d5..655d8e0dd3a 100644 --- a/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts +++ b/generators/typescript/model/type-generator/src/undiscriminated-union/GeneratedUndiscriminatedUnionTypeImpl.ts @@ -3,7 +3,12 @@ import { UndiscriminatedUnionMember, UndiscriminatedUnionTypeDeclaration } from "@fern-fern/ir-sdk/api"; -import { GetReferenceOpts, getWriterForMultiLineUnionType, maybeAddDocs } from "@fern-typescript/commons"; +import { + GetReferenceOpts, + getWriterForMultiLineUnionType, + maybeAddDocsNode, + maybeAddDocsStructure +} from "@fern-typescript/commons"; import { GeneratedUndiscriminatedUnionType, BaseContext } from "@fern-typescript/contexts"; import { ModuleDeclarationStructure, @@ -50,7 +55,7 @@ export class GeneratedUndiscriminatedUnionTypeImpl }) ) }; - maybeAddDocs(alias, this.getDocs(context)); + maybeAddDocsStructure(alias, this.getDocs(context)); return alias; } diff --git a/generators/typescript/model/type-reference-converters/src/AbstractTypeReferenceConverter.ts b/generators/typescript/model/type-reference-converters/src/AbstractTypeReferenceConverter.ts index 3fbf2e87bdb..40fbedae0e9 100644 --- a/generators/typescript/model/type-reference-converters/src/AbstractTypeReferenceConverter.ts +++ b/generators/typescript/model/type-reference-converters/src/AbstractTypeReferenceConverter.ts @@ -38,11 +38,11 @@ export namespace ConvertTypeReferenceParams { /** * Metadata for converting inline types */ - export type InlineType = { + export interface InlineType { parentTypeName: string; propertyName: string; genericIn?: InlineType.GenericIn; - }; + } export namespace InlineType { export const GenericIn = { diff --git a/generators/typescript/model/union-generator/src/GeneratedUnionImpl.ts b/generators/typescript/model/union-generator/src/GeneratedUnionImpl.ts index 5d6c43d7a69..5294240b8f1 100644 --- a/generators/typescript/model/union-generator/src/GeneratedUnionImpl.ts +++ b/generators/typescript/model/union-generator/src/GeneratedUnionImpl.ts @@ -3,7 +3,8 @@ import { FernWriters, getTextOfTsNode, getWriterForMultiLineUnionType, - maybeAddDocs, + maybeAddDocsNode, + maybeAddDocsStructure, ObjectWriter, Reference } from "@fern-typescript/commons"; @@ -279,9 +280,7 @@ export class GeneratedUnionImpl implements Generat ), isExported: true }; - if (this.getDocs != null) { - maybeAddDocs(typeAlias, this.getDocs(context)); - } + maybeAddDocsStructure(typeAlias, this.getDocs?.(context)); return typeAlias; } diff --git a/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts b/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts index 494bd0756db..d5586164fb3 100644 --- a/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts +++ b/generators/typescript/sdk/client-class-generator/src/GeneratedSdkClientClassImpl.ts @@ -19,7 +19,7 @@ import { getTextOfTsNode, ImportsManager, JavaScriptRuntime, - maybeAddDocs, + maybeAddDocsStructure, NpmPackage, PackageId } from "@fern-typescript/commons"; @@ -459,7 +459,7 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass { methods: [], getAccessors: [] }; - maybeAddDocs(serviceClass, this.package_.docs); + maybeAddDocsStructure(serviceClass, this.package_.docs); if (this.isRoot && context.generateOAuthClients) { serviceClass.properties.push({ @@ -608,7 +608,7 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass { ) ) ), - initializer: optionsInterface.properties!.every((property) => property.hasQuestionToken) + initializer: optionsInterface.properties?.every((property) => property.hasQuestionToken) ? "{}" : undefined } @@ -651,7 +651,7 @@ export class GeneratedSdkClientClassImpl implements GeneratedSdkClientClass { serviceClass.methods.push(method); if (overloads.length === 0) { - maybeAddDocs(method, docs); + maybeAddDocsStructure(method, docs); } } diff --git a/generators/typescript/sdk/request-wrapper-generator/src/GeneratedRequestWrapperImpl.ts b/generators/typescript/sdk/request-wrapper-generator/src/GeneratedRequestWrapperImpl.ts index 5c54a07e498..7529fe44cf6 100644 --- a/generators/typescript/sdk/request-wrapper-generator/src/GeneratedRequestWrapperImpl.ts +++ b/generators/typescript/sdk/request-wrapper-generator/src/GeneratedRequestWrapperImpl.ts @@ -20,7 +20,8 @@ import { import { getExampleEndpointCalls, getTextOfTsNode, - maybeAddDocs, + maybeAddDocsNode, + maybeAddDocsStructure, PackageId, TypeReferenceNode, visitJavaScriptRuntime @@ -108,7 +109,7 @@ export class GeneratedRequestWrapperImpl implements GeneratedRequestWrapper { ), hasQuestionToken: type.isOptional }); - maybeAddDocs(property, queryParameter.docs); + maybeAddDocsNode(property, queryParameter.docs); } for (const header of this.getAllNonLiteralHeaders(context)) { const type = context.type.getReferenceToType(header.valueType); @@ -117,7 +118,7 @@ export class GeneratedRequestWrapperImpl implements GeneratedRequestWrapper { type: getTextOfTsNode(type.typeNodeWithoutUndefined), hasQuestionToken: type.isOptional }); - maybeAddDocs(property, header.docs); + maybeAddDocsNode(property, header.docs); } if (this.endpoint.requestBody != null) { HttpRequestBody._visit(this.endpoint.requestBody, { @@ -145,7 +146,7 @@ export class GeneratedRequestWrapperImpl implements GeneratedRequestWrapper { type: getTextOfTsNode(type.typeNodeWithoutUndefined), hasQuestionToken: type.isOptional }); - maybeAddDocs(property, referenceToRequestBody.docs); + maybeAddDocsNode(property, referenceToRequestBody.docs); }, fileUpload: (fileUploadRequest) => { for (const property of fileUploadRequest.properties) { @@ -290,7 +291,9 @@ export class GeneratedRequestWrapperImpl implements GeneratedRequestWrapper { .filter((prop): prop is InlinedRequestBodyProperty => prop !== undefined) .map((property): [ObjectProperty, NamedType] | undefined => { const namedType = getNamedType(property?.valueType); - if (namedType) return [property, namedType]; + if (namedType) { + return [property, namedType]; + } return undefined; }) .filter((x): x is [ObjectProperty, TypeReference.Named] => x != null) @@ -601,7 +604,6 @@ export class GeneratedRequestWrapperImpl implements GeneratedRequestWrapper { return property.type === "fileArray" ? ts.factory.createArrayTypeNode(value) : value; } } - function getNamedType(typeReference: TypeReference): NamedType | undefined { switch (typeReference.type) { case "named": @@ -621,6 +623,7 @@ function getNamedType(typeReference: TypeReference): NamedType | undefined { default: assertNever(typeReference.container); } + // fallthrough case "primitive": return undefined; case "unknown": diff --git a/generators/typescript/utils/commons/src/codegen-utils/maybeAddDocs.ts b/generators/typescript/utils/commons/src/codegen-utils/maybeAddDocs.ts index 2c8940cb023..593d4f74296 100644 --- a/generators/typescript/utils/commons/src/codegen-utils/maybeAddDocs.ts +++ b/generators/typescript/utils/commons/src/codegen-utils/maybeAddDocs.ts @@ -1,14 +1,17 @@ import { JSDocableNode, JSDocableNodeStructure } from "ts-morph"; -export function maybeAddDocs(node: JSDocableNodeStructure | JSDocableNode, docs: string | null | undefined): void { +export function maybeAddDocsNode(node: JSDocableNode, docs: string | null | undefined): void { if (docs != null) { docs = "\n" + docs; - if ("docs" in node) { - // add newline so ts-morph makes it a multiline comment - node.docs = [docs]; - return; - } else if ("addJsDoc" in node) { - node.addJsDoc(docs); - } + node.addJsDoc(docs); + } +} + +export function maybeAddDocsStructure(node: JSDocableNodeStructure, docs: string | null | undefined): void { + if (docs != null) { + docs = "\n" + docs; + // add newline so ts-morph makes it a multiline comment + node.docs = [docs]; + return; } } diff --git a/generators/typescript/utils/commons/src/codegen-utils/writerToString.ts b/generators/typescript/utils/commons/src/codegen-utils/writerToString.ts index bbddbba385c..e471579f852 100644 --- a/generators/typescript/utils/commons/src/codegen-utils/writerToString.ts +++ b/generators/typescript/utils/commons/src/codegen-utils/writerToString.ts @@ -1,11 +1,12 @@ -import { CodeBlockWriter, ts, WriterFunction } from "ts-morph"; +import { CodeBlockWriter, WriterFunction } from "ts-morph"; export function writerToString(writer: WriterFunction | string): string { - if (typeof writer === "string") return writer; - let result = ""; + if (typeof writer === "string") { + return writer; + } // Create a minimal writer context that captures the output const writerContext = new CodeBlockWriter(); // Execute the writer with our context writer(writerContext); - return result; + return writerContext.toString(); } diff --git a/generators/typescript/utils/commons/src/index.ts b/generators/typescript/utils/commons/src/index.ts index 4edb08fe236..117da96caa1 100644 --- a/generators/typescript/utils/commons/src/index.ts +++ b/generators/typescript/utils/commons/src/index.ts @@ -3,7 +3,7 @@ export { getPropertyKey } from "./codegen-utils/getPropertyKey"; export { getSchemaOptions } from "./codegen-utils/getSchemaOptions"; export { getTextOfTsKeyword } from "./codegen-utils/getTextOfTsKeyword"; export { getTextOfTsNode } from "./codegen-utils/getTextOfTsNode"; -export { maybeAddDocs } from "./codegen-utils/maybeAddDocs"; +export { maybeAddDocsNode, maybeAddDocsStructure } from "./codegen-utils/maybeAddDocs"; export { writerToString } from "./codegen-utils/writerToString"; export * from "./core-utilities"; export { type Zurg } from "./core-utilities/zurg/Zurg"; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4898c4f38e4..0d1194e4e76 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4162,6 +4162,8 @@ importers: specifier: ^2.1.4 version: 2.1.4(@types/node@18.7.18)(jsdom@20.0.3)(sass@1.72.0)(terser@5.31.5) + packages/cli/cli/dist/local: {} + packages/cli/configuration: dependencies: '@fern-api/core-utils': @@ -7980,12 +7982,12 @@ packages: '@fern-fern/ir-sdk@53.18.0': resolution: {integrity: sha512-KXHiAn8wjL9VIjjR9z8fXso0O2oaCMUSy9BSYRiGjEOmbIBUhplxSXjM3wSEXQ19hiPpsRYJTCCjnaZVP0OVrw==} - '@fern-fern/ir-sdk@53.23.0': - resolution: {integrity: sha512-9U6uGs9WFDnVg57VyM7s6LKCkA30JOYDQwuLrNh50Meme0m8ce4GDZ/naVncfhrGjWfxt7PSjy1vlVLBi+PKZA==} - '@fern-fern/ir-sdk@53.22.0': resolution: {integrity: sha512-NAQ9t6nFGxRCDQqufJHnUicMetgCuSMwO3eXLJfsvFaVQt4cDx1BVp/1bsD3pz6qdJ10lX0kjf7qQDYT8QGG1A==} + '@fern-fern/ir-sdk@53.23.0': + resolution: {integrity: sha512-9U6uGs9WFDnVg57VyM7s6LKCkA30JOYDQwuLrNh50Meme0m8ce4GDZ/naVncfhrGjWfxt7PSjy1vlVLBi+PKZA==} + '@fern-fern/ir-sdk@53.7.0': resolution: {integrity: sha512-PoCj8yOep3kFeDZYORAzqPwVtCSNmbT2SfR/AoxKCcikeZ5i+4Um4ZXx1e6UaAy7dIYF5kWeRc6lptFBRoj7Gw==} @@ -15051,10 +15053,10 @@ snapshots: '@fern-fern/ir-sdk@53.18.0': {} - '@fern-fern/ir-sdk@53.23.0': {} - '@fern-fern/ir-sdk@53.22.0': {} + '@fern-fern/ir-sdk@53.23.0': {} + '@fern-fern/ir-sdk@53.7.0': {} '@fern-fern/ir-sdk@53.9.0': {}