vite-plugin-openapi-codegen 1.2.2 → 2.0.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.
- package/dist/cli.mjs +24 -7
- package/dist/index.d.mts +4 -0
- package/dist/index.mjs +24 -7
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -162,13 +162,29 @@ function createBodyRequestProperty(bodyChannel, bodyAssignment) {
|
|
|
162
162
|
return ts.factory.createSpreadAssignment(ts.factory.createParenthesizedExpression(ts.factory.createConditionalExpression(ts.factory.createBinaryExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("options"), "body"), ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.factory.createIdentifier("undefined")), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createObjectLiteralExpression([], false), ts.factory.createToken(ts.SyntaxKind.ColonToken), bodyAssignment)));
|
|
163
163
|
}
|
|
164
164
|
function createBuildSearchParamsFunction() {
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
165
|
+
const queryIdentifier = ts.factory.createIdentifier("query");
|
|
166
|
+
const searchParamsIdentifier = ts.factory.createIdentifier("searchParams");
|
|
167
|
+
const hasParamsIdentifier = ts.factory.createIdentifier("hasParams");
|
|
168
|
+
const keyIdentifier = ts.factory.createIdentifier("key");
|
|
169
|
+
const valueIdentifier = ts.factory.createIdentifier("value");
|
|
170
|
+
const itemIdentifier = ts.factory.createIdentifier("item");
|
|
171
|
+
const isNullishOrEmptyString = (identifier) => ts.factory.createBinaryExpression(ts.factory.createBinaryExpression(identifier, ts.factory.createToken(ts.SyntaxKind.EqualsEqualsToken), ts.factory.createNull()), ts.factory.createToken(ts.SyntaxKind.BarBarToken), ts.factory.createBinaryExpression(identifier, ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.factory.createStringLiteral("")));
|
|
172
|
+
const assignHasParamsTrue = () => ts.factory.createExpressionStatement(ts.factory.createAssignment(hasParamsIdentifier, ts.factory.createTrue()));
|
|
173
|
+
return ts.factory.createFunctionDeclaration(void 0, void 0, ts.factory.createIdentifier("buildSearchParams"), void 0, [ts.factory.createParameterDeclaration(void 0, void 0, queryIdentifier, void 0, createTypeNodeFromText("Record<string, unknown> | undefined"))], createTypeNodeFromText("URLSearchParams | undefined"), ts.factory.createBlock([
|
|
174
|
+
ts.factory.createIfStatement(ts.factory.createBinaryExpression(queryIdentifier, ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.factory.createIdentifier("undefined")), ts.factory.createReturnStatement(ts.factory.createIdentifier("undefined"))),
|
|
175
|
+
ts.factory.createVariableStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(searchParamsIdentifier, void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("URLSearchParams"), void 0, []))], ts.NodeFlags.Const)),
|
|
176
|
+
ts.factory.createVariableStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(hasParamsIdentifier, void 0, void 0, ts.factory.createFalse())], ts.NodeFlags.Let)),
|
|
177
|
+
ts.factory.createForOfStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(ts.factory.createArrayBindingPattern([ts.factory.createBindingElement(void 0, void 0, keyIdentifier), ts.factory.createBindingElement(void 0, void 0, valueIdentifier)]))], ts.NodeFlags.Const), parseExpression("Object.entries(query)"), ts.factory.createBlock([
|
|
178
|
+
ts.factory.createIfStatement(isNullishOrEmptyString(valueIdentifier), ts.factory.createContinueStatement()),
|
|
179
|
+
ts.factory.createIfStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("Array"), "isArray"), void 0, [valueIdentifier]), ts.factory.createBlock([ts.factory.createForOfStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(itemIdentifier)], ts.NodeFlags.Const), valueIdentifier, ts.factory.createBlock([
|
|
180
|
+
ts.factory.createIfStatement(isNullishOrEmptyString(itemIdentifier), ts.factory.createContinueStatement()),
|
|
181
|
+
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(searchParamsIdentifier, "append"), void 0, [keyIdentifier, ts.factory.createCallExpression(ts.factory.createIdentifier("String"), void 0, [itemIdentifier])])),
|
|
182
|
+
assignHasParamsTrue()
|
|
183
|
+
], true)), ts.factory.createContinueStatement()], true)),
|
|
184
|
+
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(searchParamsIdentifier, "set"), void 0, [keyIdentifier, ts.factory.createCallExpression(ts.factory.createIdentifier("String"), void 0, [valueIdentifier])])),
|
|
185
|
+
assignHasParamsTrue()
|
|
186
|
+
], true)),
|
|
187
|
+
ts.factory.createReturnStatement(ts.factory.createConditionalExpression(hasParamsIdentifier, ts.factory.createToken(ts.SyntaxKind.QuestionToken), searchParamsIdentifier, ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createIdentifier("undefined")))
|
|
172
188
|
], true));
|
|
173
189
|
}
|
|
174
190
|
function capitalize$1(value) {
|
|
@@ -486,6 +502,7 @@ function renderPrimitiveSchemaType(schema) {
|
|
|
486
502
|
const type = schema?.type;
|
|
487
503
|
if (!type) return "unknown";
|
|
488
504
|
if (Array.isArray(type)) return type.map((memberType) => mapPrimitiveType(memberType)).join(" | ");
|
|
505
|
+
if (type === "array") return `${renderPrimitiveSchemaType(schema.items)}[]`;
|
|
489
506
|
return mapPrimitiveType(type);
|
|
490
507
|
}
|
|
491
508
|
function allocateOperationTypeName(context, funcName, suffix) {
|
package/dist/index.d.mts
CHANGED
|
@@ -9,6 +9,9 @@ interface OpenAPIParameter {
|
|
|
9
9
|
name: string;
|
|
10
10
|
required?: boolean;
|
|
11
11
|
schema?: {
|
|
12
|
+
items?: {
|
|
13
|
+
type?: string | string[];
|
|
14
|
+
};
|
|
12
15
|
type?: string | string[];
|
|
13
16
|
};
|
|
14
17
|
}
|
|
@@ -32,6 +35,7 @@ interface OpenAPIOperation {
|
|
|
32
35
|
}
|
|
33
36
|
type OpenAPIPathItem = Partial<Record<HttpMethod, OpenAPIOperation>>;
|
|
34
37
|
interface OpenAPISchema {
|
|
38
|
+
items?: unknown;
|
|
35
39
|
properties?: Record<string, unknown>;
|
|
36
40
|
required?: string[];
|
|
37
41
|
type?: string;
|
package/dist/index.mjs
CHANGED
|
@@ -160,13 +160,29 @@ function createBodyRequestProperty(bodyChannel, bodyAssignment) {
|
|
|
160
160
|
return ts.factory.createSpreadAssignment(ts.factory.createParenthesizedExpression(ts.factory.createConditionalExpression(ts.factory.createBinaryExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("options"), "body"), ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.factory.createIdentifier("undefined")), ts.factory.createToken(ts.SyntaxKind.QuestionToken), ts.factory.createObjectLiteralExpression([], false), ts.factory.createToken(ts.SyntaxKind.ColonToken), bodyAssignment)));
|
|
161
161
|
}
|
|
162
162
|
function createBuildSearchParamsFunction() {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
163
|
+
const queryIdentifier = ts.factory.createIdentifier("query");
|
|
164
|
+
const searchParamsIdentifier = ts.factory.createIdentifier("searchParams");
|
|
165
|
+
const hasParamsIdentifier = ts.factory.createIdentifier("hasParams");
|
|
166
|
+
const keyIdentifier = ts.factory.createIdentifier("key");
|
|
167
|
+
const valueIdentifier = ts.factory.createIdentifier("value");
|
|
168
|
+
const itemIdentifier = ts.factory.createIdentifier("item");
|
|
169
|
+
const isNullishOrEmptyString = (identifier) => ts.factory.createBinaryExpression(ts.factory.createBinaryExpression(identifier, ts.factory.createToken(ts.SyntaxKind.EqualsEqualsToken), ts.factory.createNull()), ts.factory.createToken(ts.SyntaxKind.BarBarToken), ts.factory.createBinaryExpression(identifier, ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.factory.createStringLiteral("")));
|
|
170
|
+
const assignHasParamsTrue = () => ts.factory.createExpressionStatement(ts.factory.createAssignment(hasParamsIdentifier, ts.factory.createTrue()));
|
|
171
|
+
return ts.factory.createFunctionDeclaration(void 0, void 0, ts.factory.createIdentifier("buildSearchParams"), void 0, [ts.factory.createParameterDeclaration(void 0, void 0, queryIdentifier, void 0, createTypeNodeFromText("Record<string, unknown> | undefined"))], createTypeNodeFromText("URLSearchParams | undefined"), ts.factory.createBlock([
|
|
172
|
+
ts.factory.createIfStatement(ts.factory.createBinaryExpression(queryIdentifier, ts.factory.createToken(ts.SyntaxKind.EqualsEqualsEqualsToken), ts.factory.createIdentifier("undefined")), ts.factory.createReturnStatement(ts.factory.createIdentifier("undefined"))),
|
|
173
|
+
ts.factory.createVariableStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(searchParamsIdentifier, void 0, void 0, ts.factory.createNewExpression(ts.factory.createIdentifier("URLSearchParams"), void 0, []))], ts.NodeFlags.Const)),
|
|
174
|
+
ts.factory.createVariableStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(hasParamsIdentifier, void 0, void 0, ts.factory.createFalse())], ts.NodeFlags.Let)),
|
|
175
|
+
ts.factory.createForOfStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(ts.factory.createArrayBindingPattern([ts.factory.createBindingElement(void 0, void 0, keyIdentifier), ts.factory.createBindingElement(void 0, void 0, valueIdentifier)]))], ts.NodeFlags.Const), parseExpression("Object.entries(query)"), ts.factory.createBlock([
|
|
176
|
+
ts.factory.createIfStatement(isNullishOrEmptyString(valueIdentifier), ts.factory.createContinueStatement()),
|
|
177
|
+
ts.factory.createIfStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier("Array"), "isArray"), void 0, [valueIdentifier]), ts.factory.createBlock([ts.factory.createForOfStatement(void 0, ts.factory.createVariableDeclarationList([ts.factory.createVariableDeclaration(itemIdentifier)], ts.NodeFlags.Const), valueIdentifier, ts.factory.createBlock([
|
|
178
|
+
ts.factory.createIfStatement(isNullishOrEmptyString(itemIdentifier), ts.factory.createContinueStatement()),
|
|
179
|
+
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(searchParamsIdentifier, "append"), void 0, [keyIdentifier, ts.factory.createCallExpression(ts.factory.createIdentifier("String"), void 0, [itemIdentifier])])),
|
|
180
|
+
assignHasParamsTrue()
|
|
181
|
+
], true)), ts.factory.createContinueStatement()], true)),
|
|
182
|
+
ts.factory.createExpressionStatement(ts.factory.createCallExpression(ts.factory.createPropertyAccessExpression(searchParamsIdentifier, "set"), void 0, [keyIdentifier, ts.factory.createCallExpression(ts.factory.createIdentifier("String"), void 0, [valueIdentifier])])),
|
|
183
|
+
assignHasParamsTrue()
|
|
184
|
+
], true)),
|
|
185
|
+
ts.factory.createReturnStatement(ts.factory.createConditionalExpression(hasParamsIdentifier, ts.factory.createToken(ts.SyntaxKind.QuestionToken), searchParamsIdentifier, ts.factory.createToken(ts.SyntaxKind.ColonToken), ts.factory.createIdentifier("undefined")))
|
|
170
186
|
], true));
|
|
171
187
|
}
|
|
172
188
|
function capitalize$1(value) {
|
|
@@ -484,6 +500,7 @@ function renderPrimitiveSchemaType(schema) {
|
|
|
484
500
|
const type = schema?.type;
|
|
485
501
|
if (!type) return "unknown";
|
|
486
502
|
if (Array.isArray(type)) return type.map((memberType) => mapPrimitiveType(memberType)).join(" | ");
|
|
503
|
+
if (type === "array") return `${renderPrimitiveSchemaType(schema.items)}[]`;
|
|
487
504
|
return mapPrimitiveType(type);
|
|
488
505
|
}
|
|
489
506
|
function allocateOperationTypeName(context, funcName, suffix) {
|