Skip to content

Commit 9d47c92

Browse files
committed
WIP
1 parent 49a4fee commit 9d47c92

16 files changed

Lines changed: 482 additions & 406 deletions

package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
"license": "MIT",
4848
"author": "Daiki Urata (@7nohe)",
4949
"dependencies": {
50-
"@hey-api/client-fetch": "0.4.0",
51-
"@hey-api/openapi-ts": "0.53.8",
50+
"@hey-api/openapi-ts": "0.90.1",
5251
"cross-spawn": "^7.0.3"
5352
},
5453
"devDependencies": {
@@ -59,13 +58,13 @@
5958
"commander": "^12.0.0",
6059
"lefthook": "^1.6.10",
6160
"rimraf": "^5.0.5",
62-
"ts-morph": "^23.0.0",
63-
"typescript": "^5.5.4",
61+
"ts-morph": "^27.0.2",
62+
"typescript": "^5.9.3",
6463
"vitest": "^1.5.0"
6564
},
6665
"peerDependencies": {
6766
"commander": "12.x",
68-
"ts-morph": "23.x",
67+
"ts-morph": "27.x",
6968
"typescript": "5.x"
7069
},
7170
"packageManager": "pnpm@9.6.0",

pnpm-lock.yaml

Lines changed: 307 additions & 211 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export const getNameFromVariable = (variable: VariableDeclaration) => {
6363
export type FunctionDescription = {
6464
node: SourceFile;
6565
method: VariableDeclaration;
66-
methodBlock: ts.Block;
66+
methodBlock?: ts.Block;
6767
httpMethodName: string;
6868
jsDoc: string;
6969
isDeprecated: boolean;

src/constants.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const defaultOutputPath = "openapi";
22
export const queriesOutputPath = "queries";
33
export const requestsOutputPath = "requests";
44

5-
export const serviceFileName = "services.gen";
5+
export const serviceFileName = "sdk.gen";
66
export const modelsFileName = "types.gen";
77

88
export const OpenApiRqFiles = {

src/createExports.mts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { UserConfig } from "@hey-api/openapi-ts";
21
import type { Project } from "ts-morph";
32
import ts from "typescript";
3+
import type { LimitedUserConfig } from "./cli.mjs";
44
import { capitalizeFirstLetter } from "./common.mjs";
55
import { modelsFileName } from "./constants.mjs";
66
import { createPrefetchOrEnsure } from "./createPrefetchOrEnsure.mjs";
@@ -17,7 +17,7 @@ export const createExports = ({
1717
initialPageParam,
1818
}: {
1919
service: Service;
20-
client: UserConfig["client"];
20+
client: LimitedUserConfig["client"];
2121
project: Project;
2222
pageParam: string;
2323
nextPageParam: string;
@@ -52,13 +52,15 @@ export const createExports = ({
5252
m.kind === ts.SyntaxKind.PropertySignature &&
5353
m.name?.getText() === "query",
5454
);
55-
if (
56-
query &&
57-
((query as ts.PropertySignature).type as ts.TypeLiteralNode).members
58-
.map((m) => m.name?.getText())
59-
.includes(pageParam)
60-
) {
61-
paginatableMethods.push(methodDataNames[key]);
55+
if (query) {
56+
const queryType = (query as ts.PropertySignature).type;
57+
const members =
58+
queryType && ts.isTypeLiteralNode(queryType)
59+
? queryType.members
60+
: undefined;
61+
if (members?.map((m) => m.name?.getText()).includes(pageParam)) {
62+
paginatableMethods.push(methodDataNames[key]);
63+
}
6264
}
6365
}
6466
}

src/createImports.mts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { posix } from "node:path";
2-
import type { UserConfig } from "@hey-api/openapi-ts";
32
import type { Project } from "ts-morph";
43
import ts from "typescript";
4+
import type { LimitedUserConfig } from "./cli.mjs";
55
import { modelsFileName, serviceFileName } from "./constants.mjs";
66

77
const { join } = posix;
@@ -11,7 +11,7 @@ export const createImports = ({
1111
client,
1212
}: {
1313
project: Project;
14-
client: UserConfig["client"];
14+
client: LimitedUserConfig["client"];
1515
}) => {
1616
const modelsFile = project
1717
.getSourceFiles()
@@ -49,11 +49,7 @@ export const createImports = ({
4949
),
5050
]),
5151
),
52-
ts.factory.createStringLiteral(
53-
client === "@hey-api/client-axios"
54-
? "@hey-api/client-axios"
55-
: "@hey-api/client-fetch",
56-
),
52+
ts.factory.createStringLiteral(join("../requests", "client")),
5753
undefined,
5854
),
5955
ts.factory.createImportDeclaration(

src/createSource.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { join } from "node:path";
2-
import type { UserConfig } from "@hey-api/openapi-ts";
32
import { Project } from "ts-morph";
43
import ts from "typescript";
4+
import type { LimitedUserConfig } from "./cli.mjs";
55
import { OpenApiRqFiles } from "./constants.mjs";
66
import { createExports } from "./createExports.mjs";
77
import { createImports } from "./createImports.mjs";
@@ -15,7 +15,7 @@ const createSourceFile = async ({
1515
initialPageParam,
1616
}: {
1717
outputPath: string;
18-
client: UserConfig["client"];
18+
client: LimitedUserConfig["client"];
1919
pageParam: string;
2020
nextPageParam: string;
2121
initialPageParam: string;
@@ -136,7 +136,7 @@ export const createSource = async ({
136136
initialPageParam,
137137
}: {
138138
outputPath: string;
139-
client: UserConfig["client"];
139+
client: LimitedUserConfig["client"];
140140
version: string;
141141
pageParam: string;
142142
nextPageParam: string;

src/createUseMutation.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { UserConfig } from "@hey-api/openapi-ts";
21
import ts from "typescript";
2+
import type { LimitedUserConfig } from "./cli.mjs";
33
import {
44
BuildCommonTypeName,
55
EqualsOrGreaterThanToken,
@@ -47,7 +47,7 @@ export const createUseMutation = ({
4747
}: {
4848
functionDescription: FunctionDescription;
4949
modelNames: string[];
50-
client: UserConfig["client"];
50+
client: LimitedUserConfig["client"];
5151
}) => {
5252
const methodName = getNameFromVariable(method);
5353
const mutationKey = createQueryKeyFromMethod({ method });

src/createUseQuery.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { UserConfig } from "@hey-api/openapi-ts";
21
import type { VariableDeclaration } from "ts-morph";
32
import ts from "typescript";
3+
import type { LimitedUserConfig } from "./cli.mjs";
44
import {
55
BuildCommonTypeName,
66
EqualsOrGreaterThanToken,
@@ -24,7 +24,7 @@ const createApiResponseType = ({
2424
client,
2525
}: {
2626
methodName: string;
27-
client: UserConfig["client"];
27+
client: LimitedUserConfig["client"];
2828
}) => {
2929
/** Awaited<ReturnType<typeof myClass.myMethod>> */
3030
const awaitedResponseDataType = ts.factory.createIndexedAccessTypeNode(
@@ -481,7 +481,7 @@ export const createUseQuery = ({
481481
modelNames,
482482
}: {
483483
functionDescription: FunctionDescription;
484-
client: UserConfig["client"];
484+
client: LimitedUserConfig["client"];
485485
pageParam: string;
486486
nextPageParam: string;
487487
initialPageParam: string;

src/generate.mts

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,17 @@ export async function generate(options: LimitedUserConfig, version: string) {
1313
const openApiOutputPath = buildRequestsOutputPath(options.output);
1414
const formattedOptions = formatOptions(options);
1515

16+
// Map old client option to new plugins system
17+
const plugins: UserConfig["plugins"] = [
18+
"@hey-api/typescript",
19+
"@hey-api/sdk",
20+
];
21+
1622
const config: UserConfig = {
17-
client: formattedOptions.client,
18-
debug: formattedOptions.debug,
1923
dryRun: false,
20-
exportCore: true,
21-
output: {
22-
format: formattedOptions.format,
23-
lint: formattedOptions.lint,
24-
path: openApiOutputPath,
25-
},
2624
input: formattedOptions.input,
27-
schemas: {
28-
export: !formattedOptions.noSchemas,
29-
type: formattedOptions.schemaType,
30-
},
31-
services: {
32-
export: true,
33-
asClass: false,
34-
operationId: !formattedOptions.noOperationId,
35-
},
36-
types: {
37-
dates: formattedOptions.useDateType,
38-
export: true,
39-
enums: formattedOptions.enums,
40-
},
41-
useOptions: true,
25+
output: openApiOutputPath,
26+
plugins,
4227
};
4328
await createClient(config);
4429
const source = await createSource({

0 commit comments

Comments
 (0)