@7nohe/openapi-react-query-codegen 0.5.3 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -22
- package/dist/cli.mjs +35 -0
- package/dist/common.mjs +64 -0
- package/dist/constants.mjs +3 -0
- package/dist/createExports.mjs +40 -0
- package/dist/createImports.mjs +47 -0
- package/dist/createSource.mjs +74 -0
- package/dist/createUseMutation.mjs +98 -0
- package/dist/createUseQuery.mjs +187 -0
- package/dist/generate.mjs +43 -0
- package/dist/print.mjs +23 -0
- package/dist/service.mjs +94 -0
- package/dist/{src/util.js → util.mjs} +3 -10
- package/package.json +17 -6
- package/dist/node_modules/.bin/glob +0 -17
- package/dist/node_modules/.bin/openapi +0 -17
- package/dist/node_modules/.bin/tsc +0 -17
- package/dist/node_modules/.bin/tsserver +0 -17
- package/dist/package.json +0 -47
- package/dist/src/cli.js +0 -27
- package/dist/src/common.js +0 -11
- package/dist/src/constants.js +0 -6
- package/dist/src/createExports.js +0 -61
- package/dist/src/createImports.js +0 -37
- package/dist/src/createSource.js +0 -25
- package/dist/src/createUseMutation.js +0 -66
- package/dist/src/createUseQuery.js +0 -90
- package/dist/src/generate.js +0 -22
- package/dist/src/print.js +0 -24
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { BuildCommonTypeName, capitalizeFirstLetter, extractPropertiesFromObjectParam, getNameFromMethod, queryKeyConstraint, queryKeyGenericType, TData, TError, } from "./common.mjs";
|
|
3
|
+
import { addJSDocToNode } from "./util.mjs";
|
|
4
|
+
export const createApiResponseType = ({ className, methodName, }) => {
|
|
5
|
+
/** Awaited<ReturnType<typeof myClass.myMethod>> */
|
|
6
|
+
const awaitedResponseDataType = ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Awaited"), [
|
|
7
|
+
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("ReturnType"), [
|
|
8
|
+
ts.factory.createTypeQueryNode(ts.factory.createQualifiedName(ts.factory.createIdentifier(className), ts.factory.createIdentifier(methodName)), undefined),
|
|
9
|
+
]),
|
|
10
|
+
]);
|
|
11
|
+
/** DefaultResponseDataType
|
|
12
|
+
* export type MyClassMethodDefaultResponse = Awaited<ReturnType<typeof myClass.myMethod>>
|
|
13
|
+
*/
|
|
14
|
+
const apiResponse = ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier(`${capitalizeFirstLetter(className)}${capitalizeFirstLetter(methodName)}DefaultResponse`), undefined, awaitedResponseDataType);
|
|
15
|
+
const responseDataType = ts.factory.createTypeParameterDeclaration(undefined, TData.text, undefined, ts.factory.createTypeReferenceNode(BuildCommonTypeName(apiResponse.name)));
|
|
16
|
+
return {
|
|
17
|
+
/** DefaultResponseDataType
|
|
18
|
+
* export type MyClassMethodDefaultResponse = Awaited<ReturnType<typeof myClass.myMethod>>
|
|
19
|
+
*/
|
|
20
|
+
apiResponse,
|
|
21
|
+
/**
|
|
22
|
+
* will be the name of the type of the response type of the method
|
|
23
|
+
* MyClassMethodDefaultResponse
|
|
24
|
+
*/
|
|
25
|
+
responseDataType,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export function getRequestParamFromMethod(method) {
|
|
29
|
+
if (!method.getParameters().length) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
// we need to get the properties of the object
|
|
33
|
+
return ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createObjectBindingPattern(method
|
|
34
|
+
.getParameters()
|
|
35
|
+
.map((param) => {
|
|
36
|
+
const paramNodes = extractPropertiesFromObjectParam(param);
|
|
37
|
+
return paramNodes.map((refParam) => ts.factory.createBindingElement(undefined, undefined, ts.factory.createIdentifier(refParam.name), undefined));
|
|
38
|
+
})
|
|
39
|
+
.flat()), undefined, ts.factory.createTypeLiteralNode(method
|
|
40
|
+
.getParameters()
|
|
41
|
+
.map((param) => {
|
|
42
|
+
const paramNodes = extractPropertiesFromObjectParam(param);
|
|
43
|
+
return paramNodes.map((refParam) => {
|
|
44
|
+
return ts.factory.createPropertySignature(undefined, ts.factory.createIdentifier(refParam.name), refParam.optional
|
|
45
|
+
? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
46
|
+
: undefined,
|
|
47
|
+
// param.hasQuestionToken() ?? param.getInitializer()?.compilerNode
|
|
48
|
+
// ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
|
|
49
|
+
// : param.getQuestionTokenNode()?.compilerNode,
|
|
50
|
+
ts.factory.createTypeReferenceNode(refParam.type.getText()));
|
|
51
|
+
});
|
|
52
|
+
})
|
|
53
|
+
.flat()));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Return Type
|
|
57
|
+
* export const classNameMethodNameQueryResult<TData = MyClassMethodDefaultResponse, TError = unknown> = UseQueryResult<TData, TError>;
|
|
58
|
+
*/
|
|
59
|
+
export function createReturnTypeExport({ className, methodName, defaultApiResponse, }) {
|
|
60
|
+
return ts.factory.createTypeAliasDeclaration([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createIdentifier(`${capitalizeFirstLetter(className)}${capitalizeFirstLetter(methodName)}QueryResult`), [
|
|
61
|
+
ts.factory.createTypeParameterDeclaration(undefined, TData, undefined, ts.factory.createTypeReferenceNode(defaultApiResponse.name)),
|
|
62
|
+
ts.factory.createTypeParameterDeclaration(undefined, TError, undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)),
|
|
63
|
+
], ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("UseQueryResult"), [
|
|
64
|
+
ts.factory.createTypeReferenceNode(TData),
|
|
65
|
+
ts.factory.createTypeReferenceNode(TError),
|
|
66
|
+
]));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* QueryKey
|
|
70
|
+
*/
|
|
71
|
+
export function createQueryKeyExport({ className, methodName, queryKey, }) {
|
|
72
|
+
return ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
73
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(queryKey), undefined, undefined, ts.factory.createStringLiteral(`${className}${capitalizeFirstLetter(methodName)}`)),
|
|
74
|
+
], ts.NodeFlags.Const));
|
|
75
|
+
}
|
|
76
|
+
function hookNameFromMethod({ method, className, }) {
|
|
77
|
+
const methodName = getNameFromMethod(method);
|
|
78
|
+
return `use${className}${capitalizeFirstLetter(methodName)}`;
|
|
79
|
+
}
|
|
80
|
+
function createQueryKeyFromMethod({ method, className, }) {
|
|
81
|
+
const customHookName = hookNameFromMethod({ method, className });
|
|
82
|
+
const queryKey = `${customHookName}Key`;
|
|
83
|
+
return queryKey;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates a custom hook for a query
|
|
87
|
+
* @param queryString The type of query to use from react-query
|
|
88
|
+
* @param suffix The suffix to append to the hook name
|
|
89
|
+
*/
|
|
90
|
+
function createQueryHook({ queryString, suffix, responseDataType, requestParams, method, className, }) {
|
|
91
|
+
const methodName = getNameFromMethod(method);
|
|
92
|
+
const customHookName = hookNameFromMethod({ method, className });
|
|
93
|
+
const queryKey = createQueryKeyFromMethod({ method, className });
|
|
94
|
+
const hookExport = ts.factory.createVariableStatement([ts.factory.createModifier(ts.SyntaxKind.ExportKeyword)], ts.factory.createVariableDeclarationList([
|
|
95
|
+
ts.factory.createVariableDeclaration(ts.factory.createIdentifier(`${customHookName}${suffix}`), undefined, undefined, ts.factory.createArrowFunction(undefined, ts.factory.createNodeArray([
|
|
96
|
+
responseDataType,
|
|
97
|
+
ts.factory.createTypeParameterDeclaration(undefined, TError, undefined, ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword)),
|
|
98
|
+
ts.factory.createTypeParameterDeclaration(undefined, "TQueryKey", queryKeyConstraint, ts.factory.createArrayTypeNode(ts.factory.createKeywordTypeNode(ts.SyntaxKind.UnknownKeyword))),
|
|
99
|
+
]), [
|
|
100
|
+
...requestParams,
|
|
101
|
+
ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier("queryKey"), ts.factory.createToken(ts.SyntaxKind.QuestionToken), queryKeyGenericType),
|
|
102
|
+
ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createIdentifier("options"), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("Omit"), [
|
|
103
|
+
ts.factory.createTypeReferenceNode(ts.factory.createIdentifier("UseQueryOptions"), [
|
|
104
|
+
ts.factory.createTypeReferenceNode(TData),
|
|
105
|
+
ts.factory.createTypeReferenceNode(TError),
|
|
106
|
+
]),
|
|
107
|
+
ts.factory.createUnionTypeNode([
|
|
108
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("queryKey")),
|
|
109
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("queryFn")),
|
|
110
|
+
ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral("initialData")),
|
|
111
|
+
]),
|
|
112
|
+
])),
|
|
113
|
+
], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createCallExpression(ts.factory.createIdentifier(queryString), [
|
|
114
|
+
ts.factory.createTypeReferenceNode(TData),
|
|
115
|
+
ts.factory.createTypeReferenceNode(TError),
|
|
116
|
+
], [
|
|
117
|
+
ts.factory.createObjectLiteralExpression([
|
|
118
|
+
ts.factory.createPropertyAssignment(ts.factory.createIdentifier("queryKey"), ts.factory.createArrayLiteralExpression([
|
|
119
|
+
BuildCommonTypeName(queryKey),
|
|
120
|
+
ts.factory.createSpreadElement(ts.factory.createParenthesizedExpression(ts.factory.createBinaryExpression(ts.factory.createIdentifier("queryKey"), ts.factory.createToken(ts.SyntaxKind.QuestionQuestionToken), method.getParameters().length
|
|
121
|
+
? ts.factory.createArrayLiteralExpression([
|
|
122
|
+
ts.factory.createObjectLiteralExpression(method
|
|
123
|
+
.getParameters()
|
|
124
|
+
.map((param) => extractPropertiesFromObjectParam(param).map((p) => ts.factory.createShorthandPropertyAssignment(ts.factory.createIdentifier(p.name))))
|
|
125
|
+
.flat()),
|
|
126
|
+
])
|
|
127
|
+
: ts.factory.createArrayLiteralExpression([])))),
|
|
128
|
+
], false)),
|
|
129
|
+
ts.factory.createPropertyAssignment(ts.factory.createIdentifier("queryFn"), ts.factory.createArrowFunction(undefined, undefined, [], undefined, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), ts.factory.createAsExpression(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(className), ts.factory.createIdentifier(methodName)), undefined, method.getParameters().length
|
|
130
|
+
? [
|
|
131
|
+
ts.factory.createObjectLiteralExpression(method
|
|
132
|
+
.getParameters()
|
|
133
|
+
.map((param) => extractPropertiesFromObjectParam(param).map((p) => ts.factory.createShorthandPropertyAssignment(ts.factory.createIdentifier(p.name))))
|
|
134
|
+
.flat()),
|
|
135
|
+
]
|
|
136
|
+
: undefined), ts.factory.createTypeReferenceNode(TData)))),
|
|
137
|
+
ts.factory.createSpreadAssignment(ts.factory.createIdentifier("options")),
|
|
138
|
+
]),
|
|
139
|
+
]))),
|
|
140
|
+
], ts.NodeFlags.Const));
|
|
141
|
+
return hookExport;
|
|
142
|
+
}
|
|
143
|
+
export const createUseQuery = ({ node, className, method, jsDoc = [], isDeprecated: deprecated = false, }) => {
|
|
144
|
+
const methodName = getNameFromMethod(method);
|
|
145
|
+
const queryKey = createQueryKeyFromMethod({ method, className });
|
|
146
|
+
const { apiResponse: defaultApiResponse, responseDataType } = createApiResponseType({
|
|
147
|
+
className,
|
|
148
|
+
methodName,
|
|
149
|
+
});
|
|
150
|
+
const requestParam = getRequestParamFromMethod(method);
|
|
151
|
+
const requestParams = requestParam ? [requestParam] : [];
|
|
152
|
+
const queryHook = createQueryHook({
|
|
153
|
+
queryString: "useQuery",
|
|
154
|
+
suffix: "",
|
|
155
|
+
responseDataType,
|
|
156
|
+
requestParams,
|
|
157
|
+
method,
|
|
158
|
+
className,
|
|
159
|
+
});
|
|
160
|
+
const suspenseQueryHook = createQueryHook({
|
|
161
|
+
queryString: "useSuspenseQuery",
|
|
162
|
+
suffix: "Suspense",
|
|
163
|
+
responseDataType,
|
|
164
|
+
requestParams,
|
|
165
|
+
method,
|
|
166
|
+
className,
|
|
167
|
+
});
|
|
168
|
+
const hookWithJsDoc = addJSDocToNode(queryHook, node, deprecated, jsDoc);
|
|
169
|
+
const suspenseHookWithJsDoc = addJSDocToNode(suspenseQueryHook, node, deprecated, jsDoc);
|
|
170
|
+
const returnTypeExport = createReturnTypeExport({
|
|
171
|
+
className,
|
|
172
|
+
methodName,
|
|
173
|
+
defaultApiResponse,
|
|
174
|
+
});
|
|
175
|
+
const queryKeyExport = createQueryKeyExport({
|
|
176
|
+
className,
|
|
177
|
+
methodName,
|
|
178
|
+
queryKey,
|
|
179
|
+
});
|
|
180
|
+
return {
|
|
181
|
+
apiResponse: defaultApiResponse,
|
|
182
|
+
returnType: returnTypeExport,
|
|
183
|
+
key: queryKeyExport,
|
|
184
|
+
queryHook: hookWithJsDoc,
|
|
185
|
+
suspenseQueryHook: suspenseHookWithJsDoc,
|
|
186
|
+
};
|
|
187
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createClient } from "@hey-api/openapi-ts";
|
|
2
|
+
import { print } from "./print.mjs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import { createSource } from "./createSource.mjs";
|
|
5
|
+
import { defaultOutputPath, requestsOutputPath } from "./constants.mjs";
|
|
6
|
+
import { safeParseNumber } from "./common.mjs";
|
|
7
|
+
export async function generate(options, version) {
|
|
8
|
+
const openApiOutputPath = path.join(options.output ?? defaultOutputPath, requestsOutputPath);
|
|
9
|
+
// loop through properties on the options object
|
|
10
|
+
// if the property is a string of number then convert it to a number
|
|
11
|
+
// if the property is a string of boolean then convert it to a boolean
|
|
12
|
+
const formattedOptions = Object.entries(options).reduce((acc, [key, value]) => {
|
|
13
|
+
const typedKey = key;
|
|
14
|
+
const typedValue = value;
|
|
15
|
+
const parsedNumber = safeParseNumber(typedValue);
|
|
16
|
+
if (!isNaN(parsedNumber)) {
|
|
17
|
+
acc[typedKey] = parsedNumber;
|
|
18
|
+
}
|
|
19
|
+
else if (value === "true") {
|
|
20
|
+
acc[typedKey] = true;
|
|
21
|
+
}
|
|
22
|
+
else if (value === "false") {
|
|
23
|
+
acc[typedKey] = false;
|
|
24
|
+
}
|
|
25
|
+
return acc;
|
|
26
|
+
}, options);
|
|
27
|
+
const config = {
|
|
28
|
+
...formattedOptions,
|
|
29
|
+
output: openApiOutputPath,
|
|
30
|
+
useOptions: true,
|
|
31
|
+
exportCore: true,
|
|
32
|
+
exportModels: true,
|
|
33
|
+
exportServices: true,
|
|
34
|
+
write: true,
|
|
35
|
+
};
|
|
36
|
+
await createClient(config);
|
|
37
|
+
const source = await createSource({
|
|
38
|
+
outputPath: openApiOutputPath,
|
|
39
|
+
version,
|
|
40
|
+
serviceEndName: "Service", // we are hard coding this because changing the service end name was depreciated in @hey-api/openapi-ts
|
|
41
|
+
});
|
|
42
|
+
await print(source, formattedOptions);
|
|
43
|
+
}
|
package/dist/print.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { defaultOutputPath, queriesOutputPath } from "./constants.mjs";
|
|
4
|
+
import { exists } from "./common.mjs";
|
|
5
|
+
async function printGeneratedTS(result, options) {
|
|
6
|
+
const dir = path.join(options.output ?? defaultOutputPath, queriesOutputPath);
|
|
7
|
+
const dirExists = await exists(dir);
|
|
8
|
+
if (!dirExists) {
|
|
9
|
+
await mkdir(dir, { recursive: true });
|
|
10
|
+
}
|
|
11
|
+
await writeFile(path.join(dir, result.name), result.content);
|
|
12
|
+
}
|
|
13
|
+
export async function print(results, options) {
|
|
14
|
+
const outputPath = options.output ?? defaultOutputPath;
|
|
15
|
+
const dirExists = await exists(outputPath);
|
|
16
|
+
if (!dirExists) {
|
|
17
|
+
await mkdir(outputPath);
|
|
18
|
+
}
|
|
19
|
+
const promises = results.map(async (result) => {
|
|
20
|
+
await printGeneratedTS(result, options);
|
|
21
|
+
});
|
|
22
|
+
await Promise.all(promises);
|
|
23
|
+
}
|
package/dist/service.mjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export async function getServices(project) {
|
|
3
|
+
const node = project
|
|
4
|
+
.getSourceFiles()
|
|
5
|
+
.find((sourceFile) => sourceFile.getFilePath().includes("services.ts"));
|
|
6
|
+
if (!node) {
|
|
7
|
+
throw new Error("No service node found");
|
|
8
|
+
}
|
|
9
|
+
const klasses = getClassesFromService(node);
|
|
10
|
+
return {
|
|
11
|
+
klasses: klasses.map(({ klass, className }) => ({
|
|
12
|
+
className,
|
|
13
|
+
klass,
|
|
14
|
+
methods: getMethodsFromService(node, klass),
|
|
15
|
+
})),
|
|
16
|
+
node,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function getClassesFromService(node) {
|
|
20
|
+
const klasses = node.getClasses();
|
|
21
|
+
if (!klasses.length) {
|
|
22
|
+
throw new Error("No classes found");
|
|
23
|
+
}
|
|
24
|
+
return klasses.map((klass) => {
|
|
25
|
+
const className = klass.getName();
|
|
26
|
+
if (!className) {
|
|
27
|
+
throw new Error("Class name not found");
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
className,
|
|
31
|
+
klass,
|
|
32
|
+
};
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function getClassNameFromClassNode(klass) {
|
|
36
|
+
const className = klass.getName();
|
|
37
|
+
if (!className) {
|
|
38
|
+
throw new Error("Class name not found");
|
|
39
|
+
}
|
|
40
|
+
return className;
|
|
41
|
+
}
|
|
42
|
+
function getMethodsFromService(node, klass) {
|
|
43
|
+
const methods = klass.getMethods();
|
|
44
|
+
if (!methods.length) {
|
|
45
|
+
throw new Error("No methods found");
|
|
46
|
+
}
|
|
47
|
+
return methods.map((method) => {
|
|
48
|
+
const methodBlockNode = method.compilerNode
|
|
49
|
+
.getChildren(node.compilerNode)
|
|
50
|
+
.find((child) => child.kind === ts.SyntaxKind.Block);
|
|
51
|
+
if (!methodBlockNode) {
|
|
52
|
+
throw new Error("Method block not found");
|
|
53
|
+
}
|
|
54
|
+
const methodBlock = methodBlockNode;
|
|
55
|
+
const foundReturnStatement = methodBlock.statements.find((s) => s.kind === ts.SyntaxKind.ReturnStatement);
|
|
56
|
+
if (!foundReturnStatement) {
|
|
57
|
+
throw new Error("Return statement not found");
|
|
58
|
+
}
|
|
59
|
+
const returnStatement = foundReturnStatement;
|
|
60
|
+
const foundCallExpression = returnStatement.expression;
|
|
61
|
+
if (!foundCallExpression) {
|
|
62
|
+
throw new Error("Call expression not found");
|
|
63
|
+
}
|
|
64
|
+
const callExpression = foundCallExpression;
|
|
65
|
+
const properties = callExpression.arguments[1].properties;
|
|
66
|
+
const httpMethodName = properties
|
|
67
|
+
.find((p) => p.name?.getText(node.compilerNode) === "method")
|
|
68
|
+
?.initializer?.getText(node.compilerNode);
|
|
69
|
+
if (!httpMethodName) {
|
|
70
|
+
throw new Error("httpMethodName not found");
|
|
71
|
+
}
|
|
72
|
+
const getAllChildren = (tsNode) => {
|
|
73
|
+
const childItems = tsNode.getChildren(node.compilerNode);
|
|
74
|
+
if (childItems.length) {
|
|
75
|
+
const allChildren = childItems.map(getAllChildren);
|
|
76
|
+
return [tsNode].concat(allChildren.flat());
|
|
77
|
+
}
|
|
78
|
+
return [tsNode];
|
|
79
|
+
};
|
|
80
|
+
const children = getAllChildren(method.compilerNode);
|
|
81
|
+
const jsDoc = method.getJsDocs().map((jsDoc) => jsDoc);
|
|
82
|
+
const isDeprecated = children.some((c) => c.kind === ts.SyntaxKind.JSDocDeprecatedTag);
|
|
83
|
+
const className = getClassNameFromClassNode(klass);
|
|
84
|
+
return {
|
|
85
|
+
className,
|
|
86
|
+
node,
|
|
87
|
+
method,
|
|
88
|
+
methodBlock,
|
|
89
|
+
httpMethodName,
|
|
90
|
+
jsDoc,
|
|
91
|
+
isDeprecated,
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.addJSDocToNode = void 0;
|
|
7
|
-
const typescript_1 = __importDefault(require("typescript"));
|
|
8
|
-
function addJSDocToNode(node, sourceFile, deprecated, jsDoc = []) {
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
export function addJSDocToNode(node, sourceFile, deprecated, jsDoc = []) {
|
|
9
3
|
const deprecatedString = deprecated ? "@deprecated" : "";
|
|
10
4
|
const jsDocString = [deprecatedString]
|
|
11
5
|
.concat(jsDoc.map((comment) => {
|
|
@@ -28,8 +22,7 @@ function addJSDocToNode(node, sourceFile, deprecated, jsDoc = []) {
|
|
|
28
22
|
// replace new lines with \n *
|
|
29
23
|
.replace(/\n/g, "\n * ");
|
|
30
24
|
const nodeWithJSDoc = jsDocString
|
|
31
|
-
?
|
|
25
|
+
? ts.addSyntheticLeadingComment(node, ts.SyntaxKind.MultiLineCommentTrivia, `*\n ${jsDocString}\n `, true)
|
|
32
26
|
: node;
|
|
33
27
|
return nodeWithJSDoc;
|
|
34
28
|
}
|
|
35
|
-
exports.addJSDocToNode = addJSDocToNode;
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@7nohe/openapi-react-query-codegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "OpenAPI React Query Codegen",
|
|
5
5
|
"bin": {
|
|
6
|
-
"openapi-rq": "dist/
|
|
6
|
+
"openapi-rq": "dist/cli.mjs"
|
|
7
7
|
},
|
|
8
|
+
"type": "module",
|
|
9
|
+
"workspaces": [
|
|
10
|
+
"examples/*"
|
|
11
|
+
],
|
|
8
12
|
"repository": {
|
|
9
13
|
"type": "git",
|
|
10
14
|
"url": "git+https://github.com/7nohe/openapi-react-query-codegen.git"
|
|
@@ -21,25 +25,32 @@
|
|
|
21
25
|
"openapi",
|
|
22
26
|
"swagger",
|
|
23
27
|
"typescript",
|
|
24
|
-
"openapi-typescript-codegen"
|
|
28
|
+
"openapi-typescript-codegen",
|
|
29
|
+
"@hey-api/openapi-ts"
|
|
25
30
|
],
|
|
26
31
|
"author": "Daiki Urata (@7nohe)",
|
|
27
32
|
"license": "MIT",
|
|
28
33
|
"devDependencies": {
|
|
34
|
+
"@hey-api/openapi-ts": "0.36.0",
|
|
29
35
|
"@types/node": "^20.10.6",
|
|
30
36
|
"commander": "^12.0.0",
|
|
31
37
|
"glob": "^10.3.10",
|
|
32
|
-
"
|
|
38
|
+
"rimraf": "^5.0.5",
|
|
39
|
+
"ts-morph": "^22.0.0",
|
|
33
40
|
"typescript": "^5.3.3"
|
|
34
41
|
},
|
|
35
42
|
"peerDependencies": {
|
|
43
|
+
"@hey-api/openapi-ts": "0.36.0",
|
|
36
44
|
"commander": ">= 11 < 13",
|
|
37
45
|
"glob": ">= 10",
|
|
38
|
-
"
|
|
46
|
+
"ts-morph": ">= 22 < 23",
|
|
39
47
|
"typescript": ">= 4.8.3"
|
|
40
48
|
},
|
|
49
|
+
"engines": {
|
|
50
|
+
"node": ">=14"
|
|
51
|
+
},
|
|
41
52
|
"scripts": {
|
|
42
|
-
"build": "tsc -p tsconfig.json",
|
|
53
|
+
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
43
54
|
"preview": "npm run build && npm -C examples/react-app run generate:api",
|
|
44
55
|
"release": "npx git-ensure -a && npx bumpp --commit --tag --push"
|
|
45
56
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/esm/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules/glob/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/esm/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules/glob/dist/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules/glob/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/glob@10.3.10/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../glob/dist/esm/bin.mjs" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../glob/dist/esm/bin.mjs" "$@"
|
|
17
|
-
fi
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/openapi-typescript-codegen@0.25.0/node_modules/openapi-typescript-codegen/bin/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/openapi-typescript-codegen@0.25.0/node_modules/openapi-typescript-codegen/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/openapi-typescript-codegen@0.25.0/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/openapi-typescript-codegen@0.25.0/node_modules/openapi-typescript-codegen/bin/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/openapi-typescript-codegen@0.25.0/node_modules/openapi-typescript-codegen/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/openapi-typescript-codegen@0.25.0/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../openapi-typescript-codegen/bin/index.js" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../openapi-typescript-codegen/bin/index.js" "$@"
|
|
17
|
-
fi
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/bin/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/bin/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../typescript/bin/tsc" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../typescript/bin/tsc" "$@"
|
|
17
|
-
fi
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
|
|
3
|
-
|
|
4
|
-
case `uname` in
|
|
5
|
-
*CYGWIN*) basedir=`cygpath -w "$basedir"`;;
|
|
6
|
-
esac
|
|
7
|
-
|
|
8
|
-
if [ -z "$NODE_PATH" ]; then
|
|
9
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/bin/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules"
|
|
10
|
-
else
|
|
11
|
-
export NODE_PATH="/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/bin/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules/typescript/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/typescript@5.3.3/node_modules:/Users/daiki/Development/openapi-react-query-codegen/node_modules/.pnpm/node_modules:$NODE_PATH"
|
|
12
|
-
fi
|
|
13
|
-
if [ -x "$basedir/node" ]; then
|
|
14
|
-
exec "$basedir/node" "$basedir/../typescript/bin/tsserver" "$@"
|
|
15
|
-
else
|
|
16
|
-
exec node "$basedir/../typescript/bin/tsserver" "$@"
|
|
17
|
-
fi
|
package/dist/package.json
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@7nohe/openapi-react-query-codegen",
|
|
3
|
-
"version": "0.5.3",
|
|
4
|
-
"description": "OpenAPI React Query Codegen",
|
|
5
|
-
"bin": {
|
|
6
|
-
"openapi-rq": "dist/src/cli.js"
|
|
7
|
-
},
|
|
8
|
-
"scripts": {
|
|
9
|
-
"build": "tsc -p tsconfig.json",
|
|
10
|
-
"preview": "npm run build && npm -C examples/react-app run generate:api",
|
|
11
|
-
"prepublishOnly": "npm run build",
|
|
12
|
-
"release": "npx git-ensure -a && npx bumpp --commit --tag --push"
|
|
13
|
-
},
|
|
14
|
-
"repository": {
|
|
15
|
-
"type": "git",
|
|
16
|
-
"url": "git+https://github.com/7nohe/openapi-react-query-codegen.git"
|
|
17
|
-
},
|
|
18
|
-
"homepage": "https://github.com/7nohe/openapi-react-query-codegen",
|
|
19
|
-
"bugs": "https://github.com/7nohe/openapi-react-query-codegen/issues",
|
|
20
|
-
"files": [
|
|
21
|
-
"dist"
|
|
22
|
-
],
|
|
23
|
-
"keywords": [
|
|
24
|
-
"codegen",
|
|
25
|
-
"react-query",
|
|
26
|
-
"react",
|
|
27
|
-
"openapi",
|
|
28
|
-
"swagger",
|
|
29
|
-
"typescript",
|
|
30
|
-
"openapi-typescript-codegen"
|
|
31
|
-
],
|
|
32
|
-
"author": "Daiki Urata (@7nohe)",
|
|
33
|
-
"license": "MIT",
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"@types/node": "^20.10.6",
|
|
36
|
-
"commander": "^12.0.0",
|
|
37
|
-
"glob": "^10.3.10",
|
|
38
|
-
"openapi-typescript-codegen": "0.25.0",
|
|
39
|
-
"typescript": "^5.3.3"
|
|
40
|
-
},
|
|
41
|
-
"peerDependencies": {
|
|
42
|
-
"commander": ">= 11 < 13",
|
|
43
|
-
"glob": ">= 10",
|
|
44
|
-
"openapi-typescript-codegen": "^0.24.0",
|
|
45
|
-
"typescript": ">= 4.8.3"
|
|
46
|
-
}
|
|
47
|
-
}
|
package/dist/src/cli.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const generate_1 = require("./generate");
|
|
8
|
-
const commander_1 = require("commander");
|
|
9
|
-
const package_json_1 = __importDefault(require("../package.json"));
|
|
10
|
-
const program = new commander_1.Command();
|
|
11
|
-
program
|
|
12
|
-
.name("openapi-rq")
|
|
13
|
-
.version(package_json_1.default.version)
|
|
14
|
-
.description("Generate React Query code based on OpenAPI")
|
|
15
|
-
.requiredOption("-i, --input <value>", "OpenAPI specification, can be a path, url or string content (required)")
|
|
16
|
-
.option("-o, --output <value>", "Output directory", "openapi")
|
|
17
|
-
.option("-c, --client <value>", "HTTP client to generate [fetch, xhr, node, axios, angular]", "fetch")
|
|
18
|
-
.option("--useUnionTypes", "Use union types", false)
|
|
19
|
-
.option("--exportSchemas <value>", "Write schemas to disk", false)
|
|
20
|
-
.option("--indent <value>", "Indentation options [4, 2, tabs]", "4")
|
|
21
|
-
.option("--postfixServices <value>", "Service name postfix", "Service")
|
|
22
|
-
.option("--postfixModels <value>", "Modal name postfix")
|
|
23
|
-
.option("--request <value>", "Path to custom request file")
|
|
24
|
-
.parse();
|
|
25
|
-
const options = program.opts();
|
|
26
|
-
console.log(`Generating React Query code using OpenApi file ${options.output}`);
|
|
27
|
-
(0, generate_1.generate)(options);
|
package/dist/src/common.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.lowercaseFirstLetter = exports.capitalizeFirstLetter = void 0;
|
|
4
|
-
const capitalizeFirstLetter = (str) => {
|
|
5
|
-
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
6
|
-
};
|
|
7
|
-
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
8
|
-
const lowercaseFirstLetter = (str) => {
|
|
9
|
-
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
10
|
-
};
|
|
11
|
-
exports.lowercaseFirstLetter = lowercaseFirstLetter;
|
package/dist/src/constants.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.requestsOutputPath = exports.queriesOutputPath = exports.defaultOutputPath = void 0;
|
|
4
|
-
exports.defaultOutputPath = "openapi";
|
|
5
|
-
exports.queriesOutputPath = "queries";
|
|
6
|
-
exports.requestsOutputPath = "requests";
|