react-query-lightbase-codegen 2.3.2 → 2.4.0
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.
|
@@ -60,35 +60,9 @@ function generateAxiosMethod(operation, spec) {
|
|
|
60
60
|
requestBody.content?.["application/octet-stream"]?.schema)
|
|
61
61
|
: undefined;
|
|
62
62
|
const requestBodySchema = content ? resolveSchema(content, spec) : undefined;
|
|
63
|
-
// Build data type parts
|
|
64
|
-
const dataProps = [];
|
|
65
|
-
// Add path and query parameters
|
|
66
|
-
urlParams.forEach((p) => {
|
|
67
|
-
const safeName = (0, utils_1.sanitizePropertyName)(p.name);
|
|
68
|
-
dataProps.push(`${safeName}: ${(0, utils_1.getTypeFromSchema)(p.schema)}`);
|
|
69
|
-
});
|
|
70
|
-
queryParams.forEach((p) => {
|
|
71
|
-
const safeName = (0, utils_1.sanitizePropertyName)(p.name);
|
|
72
|
-
dataProps.push(`${safeName}${p.required ? "" : "?"}: ${(0, utils_1.getTypeFromSchema)(p.schema)}`);
|
|
73
|
-
});
|
|
74
63
|
// Add request body type if it exists
|
|
75
64
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
76
|
-
let dataType = "undefined";
|
|
77
65
|
const namedType = (0, utils_1.pascalCase)(operationId);
|
|
78
|
-
if (hasData) {
|
|
79
|
-
if (requestBody && dataProps.length > 0) {
|
|
80
|
-
dataType = `T.${namedType}Request & { ${dataProps.join("; ")} }`;
|
|
81
|
-
}
|
|
82
|
-
else if (requestBody) {
|
|
83
|
-
dataType = `T.${namedType}Request`;
|
|
84
|
-
}
|
|
85
|
-
else if (dataProps.length > 0) {
|
|
86
|
-
dataType = `{ ${dataProps.join("; ")} }`;
|
|
87
|
-
}
|
|
88
|
-
else {
|
|
89
|
-
dataType = "Record<string, never>";
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
66
|
// Get response type from 2xx response
|
|
93
67
|
const responseType = responseDetails?.[0] && "content" in responseDetails[1]
|
|
94
68
|
? `T.${`${namedType}Response${responseDetails[0]}`}`
|
|
@@ -73,11 +73,23 @@ function generateTypeDefinitions(spec) {
|
|
|
73
73
|
// Add path and query parameters
|
|
74
74
|
urlParams.forEach((p) => {
|
|
75
75
|
const safeName = (0, utils_1.sanitizePropertyName)(p.name);
|
|
76
|
-
|
|
76
|
+
const isDeprecated = "deprecated" in p && p.deprecated;
|
|
77
|
+
const hasDescription = "description" in p && p.description;
|
|
78
|
+
const desc = hasDescription || isDeprecated
|
|
79
|
+
? `/**${hasDescription ? `\n* ${p.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
80
|
+
*/\n`
|
|
81
|
+
: "";
|
|
82
|
+
dataProps.push(`${desc}${safeName}: ${(0, utils_1.getTypeFromSchema)(p.schema)}`);
|
|
77
83
|
});
|
|
78
84
|
queryParams.forEach((p) => {
|
|
79
85
|
const safeName = (0, utils_1.sanitizePropertyName)(p.name);
|
|
80
|
-
|
|
86
|
+
const isDeprecated = "deprecated" in p && p.deprecated;
|
|
87
|
+
const hasDescription = "description" in p && p.description;
|
|
88
|
+
const desc = hasDescription || isDeprecated
|
|
89
|
+
? `\n/**${hasDescription ? `\n* ${p.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
90
|
+
*/\n`
|
|
91
|
+
: "";
|
|
92
|
+
dataProps.push(`${desc}${safeName}${p.required ? "" : "?"}: ${(0, utils_1.getTypeFromSchema)(p.schema)}`);
|
|
81
93
|
});
|
|
82
94
|
// Add request body type if it exists
|
|
83
95
|
const hasData = (parameters && parameters.length > 0) || requestBody;
|
package/dist/utils.js
CHANGED
|
@@ -117,7 +117,13 @@ function getTypeFromSchema(schema) {
|
|
|
117
117
|
const isRequired = schema.required?.includes(key);
|
|
118
118
|
const propertyType = getTypeFromSchema(prop);
|
|
119
119
|
const safeName = sanitizePropertyName(key);
|
|
120
|
-
|
|
120
|
+
const isDeprecated = "deprecated" in prop && prop.deprecated;
|
|
121
|
+
const hasDescription = "description" in prop && prop.description;
|
|
122
|
+
const desc = hasDescription || isDeprecated
|
|
123
|
+
? `/**${hasDescription ? `\n* ${prop.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
124
|
+
*/\n`
|
|
125
|
+
: "";
|
|
126
|
+
return `${desc}${safeName}${isRequired ? "" : "?"}: ${propertyType};`;
|
|
121
127
|
})
|
|
122
128
|
.join("\n");
|
|
123
129
|
return `{${properties}\n}${nullable}`;
|
package/package.json
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
-
import {
|
|
3
|
-
camelCase,
|
|
4
|
-
getTypeFromSchema,
|
|
5
|
-
pascalCase,
|
|
6
|
-
sanitizePropertyName,
|
|
7
|
-
sanitizeTypeName,
|
|
8
|
-
specTitle,
|
|
9
|
-
} from "../utils";
|
|
2
|
+
import { camelCase, pascalCase, sanitizeTypeName, specTitle } from "../utils";
|
|
10
3
|
|
|
11
4
|
export interface OperationInfo {
|
|
12
5
|
method: string;
|
|
@@ -93,35 +86,10 @@ function generateAxiosMethod(operation: OperationInfo, spec: OpenAPIV3.Document)
|
|
|
93
86
|
|
|
94
87
|
const requestBodySchema = content ? resolveSchema(content, spec) : undefined;
|
|
95
88
|
|
|
96
|
-
// Build data type parts
|
|
97
|
-
const dataProps: string[] = [];
|
|
98
|
-
|
|
99
|
-
// Add path and query parameters
|
|
100
|
-
urlParams.forEach((p) => {
|
|
101
|
-
const safeName = sanitizePropertyName(p.name);
|
|
102
|
-
dataProps.push(`${safeName}: ${getTypeFromSchema(p.schema)}`);
|
|
103
|
-
});
|
|
104
|
-
queryParams.forEach((p) => {
|
|
105
|
-
const safeName = sanitizePropertyName(p.name);
|
|
106
|
-
dataProps.push(`${safeName}${p.required ? "" : "?"}: ${getTypeFromSchema(p.schema)}`);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
89
|
// Add request body type if it exists
|
|
110
90
|
const hasData = (parameters && parameters.length > 0) || operation.requestBody;
|
|
111
91
|
|
|
112
|
-
let dataType = "undefined";
|
|
113
92
|
const namedType = pascalCase(operationId);
|
|
114
|
-
if (hasData) {
|
|
115
|
-
if (requestBody && dataProps.length > 0) {
|
|
116
|
-
dataType = `T.${namedType}Request & { ${dataProps.join("; ")} }`;
|
|
117
|
-
} else if (requestBody) {
|
|
118
|
-
dataType = `T.${namedType}Request`;
|
|
119
|
-
} else if (dataProps.length > 0) {
|
|
120
|
-
dataType = `{ ${dataProps.join("; ")} }`;
|
|
121
|
-
} else {
|
|
122
|
-
dataType = "Record<string, never>";
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
93
|
|
|
126
94
|
// Get response type from 2xx response
|
|
127
95
|
|
|
@@ -91,13 +91,27 @@ export function generateTypeDefinitions(spec: OpenAPIV3.Document): string {
|
|
|
91
91
|
// Add path and query parameters
|
|
92
92
|
urlParams.forEach((p) => {
|
|
93
93
|
const safeName = sanitizePropertyName(p.name);
|
|
94
|
-
|
|
94
|
+
const isDeprecated = "deprecated" in p && p.deprecated;
|
|
95
|
+
const hasDescription = "description" in p && p.description;
|
|
96
|
+
const desc =
|
|
97
|
+
hasDescription || isDeprecated
|
|
98
|
+
? `/**${hasDescription ? `\n* ${p.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
99
|
+
*/\n`
|
|
100
|
+
: "";
|
|
101
|
+
dataProps.push(`${desc}${safeName}: ${getTypeFromSchema(p.schema)}`);
|
|
95
102
|
});
|
|
103
|
+
|
|
96
104
|
queryParams.forEach((p) => {
|
|
97
105
|
const safeName = sanitizePropertyName(p.name);
|
|
98
|
-
|
|
106
|
+
const isDeprecated = "deprecated" in p && p.deprecated;
|
|
107
|
+
const hasDescription = "description" in p && p.description;
|
|
108
|
+
const desc =
|
|
109
|
+
hasDescription || isDeprecated
|
|
110
|
+
? `\n/**${hasDescription ? `\n* ${p.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
111
|
+
*/\n`
|
|
112
|
+
: "";
|
|
113
|
+
dataProps.push(`${desc}${safeName}${p.required ? "" : "?"}: ${getTypeFromSchema(p.schema)}`);
|
|
99
114
|
});
|
|
100
|
-
|
|
101
115
|
// Add request body type if it exists
|
|
102
116
|
const hasData = (parameters && parameters.length > 0) || requestBody;
|
|
103
117
|
|
package/src/utils.ts
CHANGED
|
@@ -126,7 +126,14 @@ export function getTypeFromSchema(
|
|
|
126
126
|
const isRequired = schema.required?.includes(key);
|
|
127
127
|
const propertyType = getTypeFromSchema(prop);
|
|
128
128
|
const safeName = sanitizePropertyName(key);
|
|
129
|
-
|
|
129
|
+
const isDeprecated = "deprecated" in prop && prop.deprecated;
|
|
130
|
+
const hasDescription = "description" in prop && prop.description;
|
|
131
|
+
const desc =
|
|
132
|
+
hasDescription || isDeprecated
|
|
133
|
+
? `/**${hasDescription ? `\n* ${prop.description}` : ""}${isDeprecated ? "\n* @deprecated" : ""}
|
|
134
|
+
*/\n`
|
|
135
|
+
: "";
|
|
136
|
+
return `${desc}${safeName}${isRequired ? "" : "?"}: ${propertyType};`;
|
|
130
137
|
})
|
|
131
138
|
.join("\n");
|
|
132
139
|
return `{${properties}\n}${nullable}`;
|