react-query-lightbase-codegen 2.0.1 → 2.0.3
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.
|
@@ -34,7 +34,7 @@ function generateAxiosMethod(operation, spec) {
|
|
|
34
34
|
const responseObj = response;
|
|
35
35
|
const desc = "description" in responseObj ? responseObj.description : "";
|
|
36
36
|
const contentType = responseObj.content?.["application/json"]?.schema;
|
|
37
|
-
const typeName = `${operationId}Response${code}
|
|
37
|
+
const typeName = (0, utils_1.pascalCase)(`${operationId}Response${code}`);
|
|
38
38
|
if (contentType) {
|
|
39
39
|
if (desc) {
|
|
40
40
|
jsDocLines.push(` * @returns ${desc}`);
|
|
@@ -69,7 +69,7 @@ function generateAxiosMethod(operation, spec) {
|
|
|
69
69
|
// Add request body type if it exists
|
|
70
70
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
71
71
|
let dataType = "undefined";
|
|
72
|
-
const namedType = operationId;
|
|
72
|
+
const namedType = (0, utils_1.pascalCase)(operationId);
|
|
73
73
|
if (hasData) {
|
|
74
74
|
if (requestBody && dataProps.length > 0) {
|
|
75
75
|
dataType = `T.${namedType}Request & { ${dataProps.join("; ")} }`;
|
|
@@ -87,10 +87,10 @@ function generateAxiosMethod(operation, spec) {
|
|
|
87
87
|
// Get response type from 2xx response
|
|
88
88
|
const successResponse = Object.entries(responses).find(([code]) => code.startsWith("2"));
|
|
89
89
|
const responseType = successResponse ? `T.${`${namedType}Response${successResponse[0]}`}` : "any";
|
|
90
|
-
const urlWithParams = urlParams.length > 0 ? path.replace(/{(\w+)}/g, "${data.$1}") : path
|
|
90
|
+
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${data.$1}")}\`` : `"${path}"`;
|
|
91
91
|
const methodBody = [
|
|
92
92
|
"const apiClient = getApiClient();",
|
|
93
|
-
`const url =
|
|
93
|
+
`const url = ${urlWithParams};`,
|
|
94
94
|
queryParams.length > 0
|
|
95
95
|
? `const queryData = {
|
|
96
96
|
${queryParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
|
|
@@ -181,7 +181,7 @@ function generateApiClient(spec, config) {
|
|
|
181
181
|
operations.push({
|
|
182
182
|
method: method,
|
|
183
183
|
path,
|
|
184
|
-
operationId:
|
|
184
|
+
operationId: `${method}_${(0, utils_1.sanitizeTypeName)(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
|
|
185
185
|
summary: operation.summary,
|
|
186
186
|
description: operation.description,
|
|
187
187
|
parameters: resolveParameters([...(pathItem.parameters || []), ...(operation.parameters || [])]),
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateReactQuery = generateReactQuery;
|
|
4
4
|
const utils_1 = require("../utils");
|
|
5
5
|
function generateQueryOptions(operation, spec) {
|
|
6
|
-
const { operationId, parameters, requestBody } = operation;
|
|
6
|
+
const { operationId, parameters, requestBody, method } = operation;
|
|
7
7
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
8
8
|
// Helper to get required fields from a schema
|
|
9
9
|
const getRequiredFields = (schema, context) => {
|
|
@@ -28,9 +28,10 @@ function generateQueryOptions(operation, spec) {
|
|
|
28
28
|
})
|
|
29
29
|
: []),
|
|
30
30
|
];
|
|
31
|
-
const
|
|
31
|
+
const namedQueryOptions = (0, utils_1.camelCase)(`get_${operationId}_Query_Options`);
|
|
32
|
+
const namedQuery = (0, utils_1.camelCase)(`${method}_${operationId}`);
|
|
32
33
|
return `
|
|
33
|
-
export const ${
|
|
34
|
+
export const ${namedQueryOptions} = (
|
|
34
35
|
${hasData ? `params: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>` : `_: undefined, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>`}
|
|
35
36
|
) => {
|
|
36
37
|
const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
|
|
@@ -54,9 +55,9 @@ function generateReactQuery(spec) {
|
|
|
54
55
|
if (!operation)
|
|
55
56
|
return;
|
|
56
57
|
operations.push({
|
|
57
|
-
method: method
|
|
58
|
+
method: method,
|
|
58
59
|
path,
|
|
59
|
-
operationId:
|
|
60
|
+
operationId: `${(0, utils_1.sanitizeTypeName)(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
|
|
60
61
|
summary: operation.summary,
|
|
61
62
|
description: operation.description,
|
|
62
63
|
parameters: [
|
package/package.json
CHANGED
|
@@ -51,7 +51,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
51
51
|
const responseObj = response as OpenAPIV3.ResponseObject;
|
|
52
52
|
const desc = "description" in responseObj ? responseObj.description : "";
|
|
53
53
|
const contentType = responseObj.content?.["application/json"]?.schema;
|
|
54
|
-
const typeName = `${operationId}Response${code}
|
|
54
|
+
const typeName = pascalCase(`${operationId}Response${code}`);
|
|
55
55
|
|
|
56
56
|
if (contentType) {
|
|
57
57
|
if (desc) {
|
|
@@ -95,7 +95,7 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
95
95
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
96
96
|
|
|
97
97
|
let dataType = "undefined";
|
|
98
|
-
const namedType = operationId;
|
|
98
|
+
const namedType = pascalCase(operationId);
|
|
99
99
|
if (hasData) {
|
|
100
100
|
if (requestBody && dataProps.length > 0) {
|
|
101
101
|
dataType = `T.${namedType}Request & { ${dataProps.join("; ")} }`;
|
|
@@ -112,11 +112,11 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
112
112
|
const successResponse = Object.entries(responses).find(([code]) => code.startsWith("2"));
|
|
113
113
|
const responseType = successResponse ? `T.${`${namedType}Response${successResponse[0]}`}` : "any";
|
|
114
114
|
|
|
115
|
-
const urlWithParams = urlParams.length > 0 ? path.replace(/{(\w+)}/g, "${data.$1}") : path
|
|
115
|
+
const urlWithParams = urlParams.length > 0 ? `\`${path.replace(/{(\w+)}/g, "${data.$1}")}\`` : `"${path}"`;
|
|
116
116
|
|
|
117
117
|
const methodBody = [
|
|
118
118
|
"const apiClient = getApiClient();",
|
|
119
|
-
`const url =
|
|
119
|
+
`const url = ${urlWithParams};`,
|
|
120
120
|
queryParams.length > 0
|
|
121
121
|
? `const queryData = {
|
|
122
122
|
${queryParams.map((p) => `["${p.name}"]: data["${p.name}"]`).join(",\n ")}
|
|
@@ -214,9 +214,7 @@ export function generateApiClient(spec: OpenAPIV3.Document, config: OpenAPIConfi
|
|
|
214
214
|
operations.push({
|
|
215
215
|
method: method,
|
|
216
216
|
path,
|
|
217
|
-
operationId:
|
|
218
|
-
`${method}_${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`
|
|
219
|
-
),
|
|
217
|
+
operationId: `${method}_${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
|
|
220
218
|
summary: operation.summary,
|
|
221
219
|
description: operation.description,
|
|
222
220
|
parameters: resolveParameters([...(pathItem.parameters || []), ...(operation.parameters || [])]),
|
|
@@ -3,7 +3,7 @@ import { camelCase, pascalCase, sanitizeTypeName, specTitle } from "../utils";
|
|
|
3
3
|
import type { OperationInfo } from "./clientGenerator";
|
|
4
4
|
|
|
5
5
|
function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document): string {
|
|
6
|
-
const { operationId, parameters, requestBody } = operation;
|
|
6
|
+
const { operationId, parameters, requestBody, method } = operation;
|
|
7
7
|
|
|
8
8
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
9
9
|
|
|
@@ -35,10 +35,11 @@ function generateQueryOptions(operation: OperationInfo, spec: OpenAPIV3.Document
|
|
|
35
35
|
: []),
|
|
36
36
|
];
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const namedQueryOptions = camelCase(`get_${operationId}_Query_Options`);
|
|
39
|
+
const namedQuery = camelCase(`${method}_${operationId}`);
|
|
39
40
|
|
|
40
41
|
return `
|
|
41
|
-
export const ${
|
|
42
|
+
export const ${namedQueryOptions} = (
|
|
42
43
|
${hasData ? `params: Partial<Parameters<typeof apiClient.${namedQuery}>[0]>, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>` : `_: undefined, config?: Partial<Parameters<typeof apiClient.${namedQuery}>[1]>`}
|
|
43
44
|
) => {
|
|
44
45
|
const enabled = ${hasData ? `hasDefinedProps(params, ${requiredParams.join(", ")})` : "true"};
|
|
@@ -63,11 +64,9 @@ export function generateReactQuery(spec: OpenAPIV3.Document): string {
|
|
|
63
64
|
const operation = pathItem[method as keyof OpenAPIV3.PathItemObject] as OpenAPIV3.OperationObject;
|
|
64
65
|
if (!operation) return;
|
|
65
66
|
operations.push({
|
|
66
|
-
method: method
|
|
67
|
+
method: method,
|
|
67
68
|
path,
|
|
68
|
-
operationId:
|
|
69
|
-
`${method}_${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`
|
|
70
|
-
),
|
|
69
|
+
operationId: `${sanitizeTypeName(operation.operationId || `${path.replace(/\W+/g, "_")}`)}`,
|
|
71
70
|
summary: operation.summary,
|
|
72
71
|
description: operation.description,
|
|
73
72
|
parameters: [
|