api-farmer 0.0.22 → 0.0.24
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 +4 -0
- package/dist/{chunk-PTGO2Y5X.js → chunk-KEUG7T6E.js} +6 -5
- package/dist/{chunk-GMB5TIVL.js → chunk-MMYZTUXF.js} +17 -9
- package/dist/cli.cjs +21 -13
- package/dist/cli.js +2 -2
- package/dist/{generate-HKA2M6ER.js → generate-FIMT7H74.js} +2 -2
- package/dist/index.cjs +23 -13
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +4 -2
- package/package.json +1 -1
- package/templates/axios.ejs +42 -41
- package/templates/axle.ejs +51 -41
package/README.md
CHANGED
|
@@ -148,6 +148,10 @@ export interface Config {
|
|
|
148
148
|
* The transformer api options, used to override the default transformation rules.
|
|
149
149
|
*/
|
|
150
150
|
transformer?: Partial<Transformer>
|
|
151
|
+
/**
|
|
152
|
+
* Certain uncountable nouns that do not change from singular to plural
|
|
153
|
+
*/
|
|
154
|
+
uncountableNouns?: string[]
|
|
151
155
|
}
|
|
152
156
|
```
|
|
153
157
|
|
|
@@ -90,26 +90,26 @@ function getCliVersion() {
|
|
|
90
90
|
function isRequiredRequestBody(value) {
|
|
91
91
|
return "required" in value && value.required === true;
|
|
92
92
|
}
|
|
93
|
+
function findObjectKey(object, targetKeys) {
|
|
94
|
+
return Object.keys(object).find((key) => targetKeys.includes(key));
|
|
95
|
+
}
|
|
93
96
|
function getRequestBodyContentType(value) {
|
|
94
97
|
if (!("content" in value)) {
|
|
95
98
|
return "";
|
|
96
99
|
}
|
|
97
|
-
return value.content["application/json"
|
|
100
|
+
return findObjectKey(value.content, ["application/json", "application/x-www-form-urlencoded", "multipart/form-data"]);
|
|
98
101
|
}
|
|
99
102
|
function getResponseMetadataItems(operation, validateStatus) {
|
|
100
103
|
const responses = operation.responses ?? {};
|
|
101
104
|
const validStatusResults = Object.keys(responses).sort((a, b) => Number(a) - Number(b)).filter((key) => validateStatus(Number(key))).map(Number);
|
|
102
105
|
const metadataItems = validStatusResults.map((status) => {
|
|
103
106
|
const content = operation.responses?.[status]?.content ?? {};
|
|
104
|
-
const responseContentType =
|
|
107
|
+
const responseContentType = findObjectKey(content, ["application/json", "*/*"]);
|
|
105
108
|
return {
|
|
106
109
|
status,
|
|
107
110
|
responseContentType
|
|
108
111
|
};
|
|
109
112
|
}).filter((result) => result.responseContentType);
|
|
110
|
-
function findResponseContentType(content) {
|
|
111
|
-
return content["application/json"] ? "application/json" : content["*/*"] ? "*/*" : void 0;
|
|
112
|
-
}
|
|
113
113
|
return metadataItems;
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -124,6 +124,7 @@ export {
|
|
|
124
124
|
hasQueryParameter,
|
|
125
125
|
getCliVersion,
|
|
126
126
|
isRequiredRequestBody,
|
|
127
|
+
findObjectKey,
|
|
127
128
|
getRequestBodyContentType,
|
|
128
129
|
getResponseMetadataItems
|
|
129
130
|
};
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
isRequiredRequestBody,
|
|
8
8
|
readSchema,
|
|
9
9
|
readTemplateFile
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-KEUG7T6E.js";
|
|
11
11
|
|
|
12
12
|
// src/generate.ts
|
|
13
13
|
import { resolve } from "path";
|
|
@@ -53,7 +53,7 @@ function transformVerb({ method }) {
|
|
|
53
53
|
return pascalCase(method);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
-
function transformEntity({ path, method, base }) {
|
|
56
|
+
function transformEntity({ path, method, base, uncountableNouns }) {
|
|
57
57
|
path = base ? path.replace(base, "") : path;
|
|
58
58
|
const words = path.split("/").filter(Boolean);
|
|
59
59
|
return words.reduce((entity, word, index) => {
|
|
@@ -61,9 +61,9 @@ function transformEntity({ path, method, base }) {
|
|
|
61
61
|
return entity;
|
|
62
62
|
}
|
|
63
63
|
word = word.replace(/\.([a-z])/g, (_, p) => p.toUpperCase());
|
|
64
|
-
word = pluralize.singular(pascalCase(word));
|
|
64
|
+
word = uncountableNouns.includes(word) ? word : pluralize.singular(pascalCase(word));
|
|
65
65
|
if (method === "get" && index === words.length - 1) {
|
|
66
|
-
word = pluralize.plural(word);
|
|
66
|
+
word = uncountableNouns.includes(word) ? `${word}List` : pluralize.plural(word);
|
|
67
67
|
}
|
|
68
68
|
return `${entity}${word}`;
|
|
69
69
|
}, "");
|
|
@@ -128,10 +128,10 @@ function createTransformer() {
|
|
|
128
128
|
|
|
129
129
|
// src/generate.ts
|
|
130
130
|
function transformPayloads(pathItems, options) {
|
|
131
|
-
const { transformer, path, base, validateStatus } = options;
|
|
131
|
+
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
132
132
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
133
133
|
const url = transformer.url({ path, base });
|
|
134
|
-
const args = { path, base, url, method, operation };
|
|
134
|
+
const args = { path, base, url, method, uncountableNouns, operation };
|
|
135
135
|
const entity = transformer.entity(args);
|
|
136
136
|
const verb = transformer.verb(args);
|
|
137
137
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -172,7 +172,7 @@ function transformPayloads(pathItems, options) {
|
|
|
172
172
|
}, []);
|
|
173
173
|
}
|
|
174
174
|
function partitionApiModules(schema, options) {
|
|
175
|
-
const { base, transformer, validateStatus } = options;
|
|
175
|
+
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
176
176
|
const schemaPaths = schema.paths ?? {};
|
|
177
177
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
178
178
|
const keyToPaths = groupBy(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -180,7 +180,13 @@ function partitionApiModules(schema, options) {
|
|
|
180
180
|
const payloads = paths.reduce((payloads2, path) => {
|
|
181
181
|
const pathItems = schemaPaths[path];
|
|
182
182
|
payloads2.push(
|
|
183
|
-
...transformPayloads(pathItems, {
|
|
183
|
+
...transformPayloads(pathItems, {
|
|
184
|
+
...options,
|
|
185
|
+
path: base ? base + path : path,
|
|
186
|
+
transformer,
|
|
187
|
+
uncountableNouns,
|
|
188
|
+
validateStatus
|
|
189
|
+
})
|
|
184
190
|
);
|
|
185
191
|
return payloads2;
|
|
186
192
|
}, []);
|
|
@@ -243,7 +249,8 @@ async function generate(userOptions = {}) {
|
|
|
243
249
|
output = "./src/apis/generated",
|
|
244
250
|
typesFilename = "_types.ts",
|
|
245
251
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
246
|
-
transformer = {}
|
|
252
|
+
transformer = {},
|
|
253
|
+
uncountableNouns = []
|
|
247
254
|
} = options;
|
|
248
255
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
249
256
|
const schema = await readSchema(input);
|
|
@@ -253,6 +260,7 @@ async function generate(userOptions = {}) {
|
|
|
253
260
|
}
|
|
254
261
|
const apiModules = partitionApiModules(schema, {
|
|
255
262
|
base,
|
|
263
|
+
uncountableNouns,
|
|
256
264
|
transformer: mergedTransformer,
|
|
257
265
|
validateStatus
|
|
258
266
|
});
|
package/dist/cli.cjs
CHANGED
|
@@ -91,26 +91,26 @@ function getCliVersion() {
|
|
|
91
91
|
function isRequiredRequestBody(value) {
|
|
92
92
|
return "required" in value && value.required === true;
|
|
93
93
|
}
|
|
94
|
+
function findObjectKey(object, targetKeys) {
|
|
95
|
+
return Object.keys(object).find((key) => targetKeys.includes(key));
|
|
96
|
+
}
|
|
94
97
|
function getRequestBodyContentType(value) {
|
|
95
98
|
if (!("content" in value)) {
|
|
96
99
|
return "";
|
|
97
100
|
}
|
|
98
|
-
return value.content["application/json"
|
|
101
|
+
return findObjectKey(value.content, ["application/json", "application/x-www-form-urlencoded", "multipart/form-data"]);
|
|
99
102
|
}
|
|
100
103
|
function getResponseMetadataItems(operation, validateStatus) {
|
|
101
104
|
const responses = operation.responses ?? {};
|
|
102
105
|
const validStatusResults = Object.keys(responses).sort((a, b) => Number(a) - Number(b)).filter((key) => validateStatus(Number(key))).map(Number);
|
|
103
106
|
const metadataItems = validStatusResults.map((status) => {
|
|
104
107
|
const content = operation.responses?.[status]?.content ?? {};
|
|
105
|
-
const responseContentType =
|
|
108
|
+
const responseContentType = findObjectKey(content, ["application/json", "*/*"]);
|
|
106
109
|
return {
|
|
107
110
|
status,
|
|
108
111
|
responseContentType
|
|
109
112
|
};
|
|
110
113
|
}).filter((result) => result.responseContentType);
|
|
111
|
-
function findResponseContentType(content) {
|
|
112
|
-
return content["application/json"] ? "application/json" : content["*/*"] ? "*/*" : void 0;
|
|
113
|
-
}
|
|
114
114
|
return metadataItems;
|
|
115
115
|
}
|
|
116
116
|
var import_path2, import_axle, import_fs_extra, import_rattail, import_rslog, import_swagger2openapi, import_yaml;
|
|
@@ -166,7 +166,7 @@ function transformVerb({ method }) {
|
|
|
166
166
|
return (0, import_rattail2.pascalCase)(method);
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
|
-
function transformEntity({ path, method, base }) {
|
|
169
|
+
function transformEntity({ path, method, base, uncountableNouns }) {
|
|
170
170
|
path = base ? path.replace(base, "") : path;
|
|
171
171
|
const words = path.split("/").filter(Boolean);
|
|
172
172
|
return words.reduce((entity, word, index) => {
|
|
@@ -174,9 +174,9 @@ function transformEntity({ path, method, base }) {
|
|
|
174
174
|
return entity;
|
|
175
175
|
}
|
|
176
176
|
word = word.replace(/\.([a-z])/g, (_, p) => p.toUpperCase());
|
|
177
|
-
word = import_pluralize.default.singular((0, import_rattail2.pascalCase)(word));
|
|
177
|
+
word = uncountableNouns.includes(word) ? word : import_pluralize.default.singular((0, import_rattail2.pascalCase)(word));
|
|
178
178
|
if (method === "get" && index === words.length - 1) {
|
|
179
|
-
word = import_pluralize.default.plural(word);
|
|
179
|
+
word = uncountableNouns.includes(word) ? `${word}List` : import_pluralize.default.plural(word);
|
|
180
180
|
}
|
|
181
181
|
return `${entity}${word}`;
|
|
182
182
|
}, "");
|
|
@@ -258,10 +258,10 @@ __export(generate_exports, {
|
|
|
258
258
|
transformPayloads: () => transformPayloads
|
|
259
259
|
});
|
|
260
260
|
function transformPayloads(pathItems, options) {
|
|
261
|
-
const { transformer, path, base, validateStatus } = options;
|
|
261
|
+
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
262
262
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
263
263
|
const url = transformer.url({ path, base });
|
|
264
|
-
const args = { path, base, url, method, operation };
|
|
264
|
+
const args = { path, base, url, method, uncountableNouns, operation };
|
|
265
265
|
const entity = transformer.entity(args);
|
|
266
266
|
const verb = transformer.verb(args);
|
|
267
267
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -302,7 +302,7 @@ function transformPayloads(pathItems, options) {
|
|
|
302
302
|
}, []);
|
|
303
303
|
}
|
|
304
304
|
function partitionApiModules(schema, options) {
|
|
305
|
-
const { base, transformer, validateStatus } = options;
|
|
305
|
+
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
306
306
|
const schemaPaths = schema.paths ?? {};
|
|
307
307
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
308
308
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -310,7 +310,13 @@ function partitionApiModules(schema, options) {
|
|
|
310
310
|
const payloads = paths.reduce((payloads2, path) => {
|
|
311
311
|
const pathItems = schemaPaths[path];
|
|
312
312
|
payloads2.push(
|
|
313
|
-
...transformPayloads(pathItems, {
|
|
313
|
+
...transformPayloads(pathItems, {
|
|
314
|
+
...options,
|
|
315
|
+
path: base ? base + path : path,
|
|
316
|
+
transformer,
|
|
317
|
+
uncountableNouns,
|
|
318
|
+
validateStatus
|
|
319
|
+
})
|
|
314
320
|
);
|
|
315
321
|
return payloads2;
|
|
316
322
|
}, []);
|
|
@@ -373,7 +379,8 @@ async function generate(userOptions = {}) {
|
|
|
373
379
|
output = "./src/apis/generated",
|
|
374
380
|
typesFilename = "_types.ts",
|
|
375
381
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
376
|
-
transformer = {}
|
|
382
|
+
transformer = {},
|
|
383
|
+
uncountableNouns = []
|
|
377
384
|
} = options;
|
|
378
385
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
379
386
|
const schema = await readSchema(input);
|
|
@@ -383,6 +390,7 @@ async function generate(userOptions = {}) {
|
|
|
383
390
|
}
|
|
384
391
|
const apiModules = partitionApiModules(schema, {
|
|
385
392
|
base,
|
|
393
|
+
uncountableNouns,
|
|
386
394
|
transformer: mergedTransformer,
|
|
387
395
|
validateStatus
|
|
388
396
|
});
|
package/dist/cli.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
getCliVersion
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KEUG7T6E.js";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
7
|
import { Command } from "commander";
|
|
8
8
|
var program = new Command();
|
|
9
9
|
program.version(getCliVersion());
|
|
10
10
|
program.action(async () => {
|
|
11
|
-
const { generate } = await import("./generate-
|
|
11
|
+
const { generate } = await import("./generate-FIMT7H74.js");
|
|
12
12
|
return generate();
|
|
13
13
|
});
|
|
14
14
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -33,6 +33,7 @@ __export(index_exports, {
|
|
|
33
33
|
createStatusCodesByStrategy: () => createStatusCodesByStrategy,
|
|
34
34
|
createTransformer: () => createTransformer,
|
|
35
35
|
defineConfig: () => defineConfig,
|
|
36
|
+
findObjectKey: () => findObjectKey,
|
|
36
37
|
generate: () => generate,
|
|
37
38
|
generateTypes: () => generateTypes,
|
|
38
39
|
getCliVersion: () => getCliVersion,
|
|
@@ -84,7 +85,7 @@ function transformVerb({ method }) {
|
|
|
84
85
|
return (0, import_rattail.pascalCase)(method);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
|
-
function transformEntity({ path, method, base }) {
|
|
88
|
+
function transformEntity({ path, method, base, uncountableNouns }) {
|
|
88
89
|
path = base ? path.replace(base, "") : path;
|
|
89
90
|
const words = path.split("/").filter(Boolean);
|
|
90
91
|
return words.reduce((entity, word, index) => {
|
|
@@ -92,9 +93,9 @@ function transformEntity({ path, method, base }) {
|
|
|
92
93
|
return entity;
|
|
93
94
|
}
|
|
94
95
|
word = word.replace(/\.([a-z])/g, (_, p) => p.toUpperCase());
|
|
95
|
-
word = import_pluralize.default.singular((0, import_rattail.pascalCase)(word));
|
|
96
|
+
word = uncountableNouns.includes(word) ? word : import_pluralize.default.singular((0, import_rattail.pascalCase)(word));
|
|
96
97
|
if (method === "get" && index === words.length - 1) {
|
|
97
|
-
word = import_pluralize.default.plural(word);
|
|
98
|
+
word = uncountableNouns.includes(word) ? `${word}List` : import_pluralize.default.plural(word);
|
|
98
99
|
}
|
|
99
100
|
return `${entity}${word}`;
|
|
100
101
|
}, "");
|
|
@@ -267,35 +268,35 @@ function getCliVersion() {
|
|
|
267
268
|
function isRequiredRequestBody(value) {
|
|
268
269
|
return "required" in value && value.required === true;
|
|
269
270
|
}
|
|
271
|
+
function findObjectKey(object, targetKeys) {
|
|
272
|
+
return Object.keys(object).find((key) => targetKeys.includes(key));
|
|
273
|
+
}
|
|
270
274
|
function getRequestBodyContentType(value) {
|
|
271
275
|
if (!("content" in value)) {
|
|
272
276
|
return "";
|
|
273
277
|
}
|
|
274
|
-
return value.content["application/json"
|
|
278
|
+
return findObjectKey(value.content, ["application/json", "application/x-www-form-urlencoded", "multipart/form-data"]);
|
|
275
279
|
}
|
|
276
280
|
function getResponseMetadataItems(operation, validateStatus) {
|
|
277
281
|
const responses = operation.responses ?? {};
|
|
278
282
|
const validStatusResults = Object.keys(responses).sort((a, b) => Number(a) - Number(b)).filter((key) => validateStatus(Number(key))).map(Number);
|
|
279
283
|
const metadataItems = validStatusResults.map((status) => {
|
|
280
284
|
const content = operation.responses?.[status]?.content ?? {};
|
|
281
|
-
const responseContentType =
|
|
285
|
+
const responseContentType = findObjectKey(content, ["application/json", "*/*"]);
|
|
282
286
|
return {
|
|
283
287
|
status,
|
|
284
288
|
responseContentType
|
|
285
289
|
};
|
|
286
290
|
}).filter((result) => result.responseContentType);
|
|
287
|
-
function findResponseContentType(content) {
|
|
288
|
-
return content["application/json"] ? "application/json" : content["*/*"] ? "*/*" : void 0;
|
|
289
|
-
}
|
|
290
291
|
return metadataItems;
|
|
291
292
|
}
|
|
292
293
|
|
|
293
294
|
// src/generate.ts
|
|
294
295
|
function transformPayloads(pathItems, options) {
|
|
295
|
-
const { transformer, path, base, validateStatus } = options;
|
|
296
|
+
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
296
297
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
297
298
|
const url = transformer.url({ path, base });
|
|
298
|
-
const args = { path, base, url, method, operation };
|
|
299
|
+
const args = { path, base, url, method, uncountableNouns, operation };
|
|
299
300
|
const entity = transformer.entity(args);
|
|
300
301
|
const verb = transformer.verb(args);
|
|
301
302
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
@@ -336,7 +337,7 @@ function transformPayloads(pathItems, options) {
|
|
|
336
337
|
}, []);
|
|
337
338
|
}
|
|
338
339
|
function partitionApiModules(schema, options) {
|
|
339
|
-
const { base, transformer, validateStatus } = options;
|
|
340
|
+
const { base, transformer, uncountableNouns, validateStatus } = options;
|
|
340
341
|
const schemaPaths = schema.paths ?? {};
|
|
341
342
|
const schemaPathKeys = base ? Object.keys(schemaPaths).map((key) => key.replace(base, "")) : Object.keys(schemaPaths);
|
|
342
343
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
@@ -344,7 +345,13 @@ function partitionApiModules(schema, options) {
|
|
|
344
345
|
const payloads = paths.reduce((payloads2, path) => {
|
|
345
346
|
const pathItems = schemaPaths[path];
|
|
346
347
|
payloads2.push(
|
|
347
|
-
...transformPayloads(pathItems, {
|
|
348
|
+
...transformPayloads(pathItems, {
|
|
349
|
+
...options,
|
|
350
|
+
path: base ? base + path : path,
|
|
351
|
+
transformer,
|
|
352
|
+
uncountableNouns,
|
|
353
|
+
validateStatus
|
|
354
|
+
})
|
|
348
355
|
);
|
|
349
356
|
return payloads2;
|
|
350
357
|
}, []);
|
|
@@ -407,7 +414,8 @@ async function generate(userOptions = {}) {
|
|
|
407
414
|
output = "./src/apis/generated",
|
|
408
415
|
typesFilename = "_types.ts",
|
|
409
416
|
validateStatus = (status) => status >= 200 && status < 300,
|
|
410
|
-
transformer = {}
|
|
417
|
+
transformer = {},
|
|
418
|
+
uncountableNouns = []
|
|
411
419
|
} = options;
|
|
412
420
|
const mergedTransformer = { ...createTransformer(), ...transformer };
|
|
413
421
|
const schema = await readSchema(input);
|
|
@@ -417,6 +425,7 @@ async function generate(userOptions = {}) {
|
|
|
417
425
|
}
|
|
418
426
|
const apiModules = partitionApiModules(schema, {
|
|
419
427
|
base,
|
|
428
|
+
uncountableNouns,
|
|
420
429
|
transformer: mergedTransformer,
|
|
421
430
|
validateStatus
|
|
422
431
|
});
|
|
@@ -431,6 +440,7 @@ var import_pluralize2 = __toESM(require("pluralize"), 1);
|
|
|
431
440
|
createStatusCodesByStrategy,
|
|
432
441
|
createTransformer,
|
|
433
442
|
defineConfig,
|
|
443
|
+
findObjectKey,
|
|
434
444
|
generate,
|
|
435
445
|
generateTypes,
|
|
436
446
|
getCliVersion,
|
package/dist/index.d.cts
CHANGED
|
@@ -44,7 +44,8 @@ declare function readTemplateFile(preset?: Preset): string;
|
|
|
44
44
|
declare function hasQueryParameter(operation: OperationObject): boolean;
|
|
45
45
|
declare function getCliVersion(): any;
|
|
46
46
|
declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
|
|
47
|
-
declare function
|
|
47
|
+
declare function findObjectKey(object: Record<string, any>, targetKeys: string[]): string | undefined;
|
|
48
|
+
declare function getRequestBodyContentType(value: RequestBodyObject | ReferenceObject): string | undefined;
|
|
48
49
|
type ResponseMetadataItem = {
|
|
49
50
|
status: number;
|
|
50
51
|
responseContentType: string;
|
|
@@ -57,6 +58,7 @@ type TransformerBaseArgs = {
|
|
|
57
58
|
url: string;
|
|
58
59
|
method: string;
|
|
59
60
|
operation: OperationObject;
|
|
61
|
+
uncountableNouns: string[];
|
|
60
62
|
};
|
|
61
63
|
declare function transformModuleName({ name }: {
|
|
62
64
|
name: string;
|
|
@@ -68,7 +70,7 @@ declare function transformUrl({ path, base }: {
|
|
|
68
70
|
declare function transformVerb({ method }: {
|
|
69
71
|
method: string;
|
|
70
72
|
}): string;
|
|
71
|
-
declare function transformEntity({ path, method, base }: TransformerBaseArgs): string;
|
|
73
|
+
declare function transformEntity({ path, method, base, uncountableNouns }: TransformerBaseArgs): string;
|
|
72
74
|
declare function transformFn({ verb, entity }: {
|
|
73
75
|
verb: string;
|
|
74
76
|
entity: string;
|
|
@@ -266,16 +268,22 @@ interface GenerateOptions {
|
|
|
266
268
|
* The transformer api options, used to override the default transformation rules.
|
|
267
269
|
*/
|
|
268
270
|
transformer?: Partial<Transformer>;
|
|
271
|
+
/**
|
|
272
|
+
* Certain uncountable nouns that do not change from singular to plural
|
|
273
|
+
*/
|
|
274
|
+
uncountableNouns?: string[];
|
|
269
275
|
}
|
|
270
276
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
271
277
|
path: string;
|
|
272
278
|
transformer: Transformer;
|
|
273
279
|
base: string | undefined;
|
|
280
|
+
uncountableNouns: string[];
|
|
274
281
|
validateStatus: (status: number) => boolean;
|
|
275
282
|
}): ApiModulePayload[];
|
|
276
283
|
declare function partitionApiModules(schema: OpenAPI3, options: {
|
|
277
284
|
transformer: Transformer;
|
|
278
285
|
base: string | undefined;
|
|
286
|
+
uncountableNouns: string[];
|
|
279
287
|
validateStatus: (status: number) => boolean;
|
|
280
288
|
}): ApiModule[];
|
|
281
289
|
declare function renderApiModules(apiModules: ApiModule[], options: {
|
|
@@ -293,4 +301,4 @@ type Config = GenerateOptions;
|
|
|
293
301
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
294
302
|
declare function getConfig(): Promise<Config>;
|
|
295
303
|
|
|
296
|
-
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type ResponseMetadataItem, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, createStatusCodesByStrategy, createTransformer, defineConfig, generate, generateTypes, getCliVersion, getConfig, getRequestBodyContentType, getResponseMetadataItems, hasQueryParameter, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
|
304
|
+
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type ResponseMetadataItem, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, createStatusCodesByStrategy, createTransformer, defineConfig, findObjectKey, generate, generateTypes, getCliVersion, getConfig, getRequestBodyContentType, getResponseMetadataItems, hasQueryParameter, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
package/dist/index.d.ts
CHANGED
|
@@ -44,7 +44,8 @@ declare function readTemplateFile(preset?: Preset): string;
|
|
|
44
44
|
declare function hasQueryParameter(operation: OperationObject): boolean;
|
|
45
45
|
declare function getCliVersion(): any;
|
|
46
46
|
declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
|
|
47
|
-
declare function
|
|
47
|
+
declare function findObjectKey(object: Record<string, any>, targetKeys: string[]): string | undefined;
|
|
48
|
+
declare function getRequestBodyContentType(value: RequestBodyObject | ReferenceObject): string | undefined;
|
|
48
49
|
type ResponseMetadataItem = {
|
|
49
50
|
status: number;
|
|
50
51
|
responseContentType: string;
|
|
@@ -57,6 +58,7 @@ type TransformerBaseArgs = {
|
|
|
57
58
|
url: string;
|
|
58
59
|
method: string;
|
|
59
60
|
operation: OperationObject;
|
|
61
|
+
uncountableNouns: string[];
|
|
60
62
|
};
|
|
61
63
|
declare function transformModuleName({ name }: {
|
|
62
64
|
name: string;
|
|
@@ -68,7 +70,7 @@ declare function transformUrl({ path, base }: {
|
|
|
68
70
|
declare function transformVerb({ method }: {
|
|
69
71
|
method: string;
|
|
70
72
|
}): string;
|
|
71
|
-
declare function transformEntity({ path, method, base }: TransformerBaseArgs): string;
|
|
73
|
+
declare function transformEntity({ path, method, base, uncountableNouns }: TransformerBaseArgs): string;
|
|
72
74
|
declare function transformFn({ verb, entity }: {
|
|
73
75
|
verb: string;
|
|
74
76
|
entity: string;
|
|
@@ -266,16 +268,22 @@ interface GenerateOptions {
|
|
|
266
268
|
* The transformer api options, used to override the default transformation rules.
|
|
267
269
|
*/
|
|
268
270
|
transformer?: Partial<Transformer>;
|
|
271
|
+
/**
|
|
272
|
+
* Certain uncountable nouns that do not change from singular to plural
|
|
273
|
+
*/
|
|
274
|
+
uncountableNouns?: string[];
|
|
269
275
|
}
|
|
270
276
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
271
277
|
path: string;
|
|
272
278
|
transformer: Transformer;
|
|
273
279
|
base: string | undefined;
|
|
280
|
+
uncountableNouns: string[];
|
|
274
281
|
validateStatus: (status: number) => boolean;
|
|
275
282
|
}): ApiModulePayload[];
|
|
276
283
|
declare function partitionApiModules(schema: OpenAPI3, options: {
|
|
277
284
|
transformer: Transformer;
|
|
278
285
|
base: string | undefined;
|
|
286
|
+
uncountableNouns: string[];
|
|
279
287
|
validateStatus: (status: number) => boolean;
|
|
280
288
|
}): ApiModule[];
|
|
281
289
|
declare function renderApiModules(apiModules: ApiModule[], options: {
|
|
@@ -293,4 +301,4 @@ type Config = GenerateOptions;
|
|
|
293
301
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
294
302
|
declare function getConfig(): Promise<Config>;
|
|
295
303
|
|
|
296
|
-
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type ResponseMetadataItem, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, createStatusCodesByStrategy, createTransformer, defineConfig, generate, generateTypes, getCliVersion, getConfig, getRequestBodyContentType, getResponseMetadataItems, hasQueryParameter, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
|
304
|
+
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type ResponseMetadataItem, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, createStatusCodesByStrategy, createTransformer, defineConfig, findObjectKey, generate, generateTypes, getCliVersion, getConfig, getRequestBodyContentType, getResponseMetadataItems, hasQueryParameter, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,10 @@ import {
|
|
|
20
20
|
transformTypeValue,
|
|
21
21
|
transformUrl,
|
|
22
22
|
transformVerb
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-MMYZTUXF.js";
|
|
24
24
|
import {
|
|
25
25
|
createStatusCodesByStrategy,
|
|
26
|
+
findObjectKey,
|
|
26
27
|
getCliVersion,
|
|
27
28
|
getRequestBodyContentType,
|
|
28
29
|
getResponseMetadataItems,
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
readSchema,
|
|
33
34
|
readSchemaContent,
|
|
34
35
|
readTemplateFile
|
|
35
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-KEUG7T6E.js";
|
|
36
37
|
|
|
37
38
|
// src/index.ts
|
|
38
39
|
import { default as default2 } from "pluralize";
|
|
@@ -40,6 +41,7 @@ export {
|
|
|
40
41
|
createStatusCodesByStrategy,
|
|
41
42
|
createTransformer,
|
|
42
43
|
defineConfig,
|
|
44
|
+
findObjectKey,
|
|
43
45
|
generate,
|
|
44
46
|
generateTypes,
|
|
45
47
|
getCliVersion,
|
package/package.json
CHANGED
package/templates/axios.ejs
CHANGED
|
@@ -2,48 +2,49 @@
|
|
|
2
2
|
<% if (!typesOnly) { %> import { request } from '@/request' <% } %>
|
|
3
3
|
<% if (ts) { %> import { type paths } from './<%- typesFilename %>' <% } %>
|
|
4
4
|
|
|
5
|
-
<% if (!typesOnly) { %>
|
|
6
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
7
|
-
export const <%- payload.fn %> =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
<% } %>
|
|
5
|
+
<%_ if (!typesOnly) { _%>
|
|
6
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
7
|
+
export const <%- payload.fn %> =
|
|
8
|
+
(config<% if (ts) { %>: RequestConfig<<%- payload.typeQuery %>, <%- payload.typeRequestBody %>> <% } %> = {}) => request
|
|
9
|
+
<% if (ts) { %><<%- payload.typeResponseBody %>><% } %>({
|
|
10
|
+
url: '<%- payload.url %>',
|
|
11
|
+
method: '<%- payload.method %>',
|
|
12
|
+
...config,
|
|
13
|
+
<%_ if (payload.requestContentType && payload.requestContentType !== 'application/json') { _%>
|
|
14
|
+
headers: {
|
|
15
|
+
'Content-Type': '<%- payload.requestContentType %>',
|
|
16
|
+
...config.headers,
|
|
17
|
+
}
|
|
18
|
+
<% } %>
|
|
19
|
+
})
|
|
20
|
+
<% }) %>
|
|
21
|
+
<%_ } _%>
|
|
21
22
|
|
|
22
23
|
<% if (ts) { %>
|
|
23
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
24
|
-
export type <%- payload.type %> = <%- payload.typeValue %>
|
|
25
|
-
|
|
26
|
-
<% }) %>
|
|
27
|
-
|
|
28
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<% } %>
|
|
33
|
-
<% }) %>
|
|
34
|
-
|
|
35
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
36
|
-
<% if (payload.typeRequestBodyValue) { %>
|
|
37
|
-
export type <%- payload.typeRequestBody %> = <%- payload.typeRequestBodyValue %>
|
|
38
|
-
|
|
39
|
-
<% } %>
|
|
40
|
-
<% }) %>
|
|
41
|
-
|
|
42
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
43
|
-
<% if (payload.typeResponseBodyValue) { %>
|
|
44
|
-
export type <%- payload.typeResponseBody %> = <%- payload.typeResponseBodyValue %>
|
|
45
|
-
|
|
46
|
-
<% } %>
|
|
47
|
-
<% }) %>
|
|
24
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
25
|
+
export type <%- payload.type %> = <%- payload.typeValue %>
|
|
26
|
+
|
|
27
|
+
<% }) %>
|
|
28
|
+
|
|
29
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
30
|
+
<% if (payload.typeQueryValue) { %>
|
|
31
|
+
export type <%- payload.typeQuery %> = <%- payload.typeQueryValue %>
|
|
32
|
+
|
|
33
|
+
<% } %>
|
|
34
|
+
<% }) %>
|
|
35
|
+
|
|
36
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
37
|
+
<% if (payload.typeRequestBodyValue) { %>
|
|
38
|
+
export type <%- payload.typeRequestBody %> = <%- payload.typeRequestBodyValue %>
|
|
39
|
+
|
|
40
|
+
<% } %>
|
|
41
|
+
<% }) %>
|
|
42
|
+
|
|
43
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
44
|
+
<% if (payload.typeResponseBodyValue) { %>
|
|
45
|
+
export type <%- payload.typeResponseBody %> = <%- payload.typeResponseBodyValue %>
|
|
46
|
+
|
|
47
|
+
<% } %>
|
|
48
|
+
<% }) %>
|
|
48
49
|
<% } %>
|
|
49
50
|
|
package/templates/axle.ejs
CHANGED
|
@@ -1,49 +1,59 @@
|
|
|
1
1
|
<% if (!typesOnly) { %> import { api } from '@/request' <% } %>
|
|
2
|
-
<% if (ts) { %>
|
|
2
|
+
<% if (ts) { %> import { type paths } from './<%- typesFilename %>' <% } %>
|
|
3
3
|
|
|
4
4
|
<% if (!typesOnly) { %>
|
|
5
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
6
|
-
export const <%- payload.fn %> = api
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
<%
|
|
12
|
-
|
|
13
|
-
<% }
|
|
14
|
-
<%- payload.typeRequestBody
|
|
15
|
-
<% }
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
6
|
+
export const <%- payload.fn %> = api
|
|
7
|
+
|
|
8
|
+
<% if (ts) { %>
|
|
9
|
+
<
|
|
10
|
+
<%- payload.typeResponseBody %>,
|
|
11
|
+
<% if (['get', 'delete', 'head', 'options'].includes(payload.method)) { %>
|
|
12
|
+
<%- payload.typeQuery %>
|
|
13
|
+
<% } else { %>
|
|
14
|
+
<%- payload.typeRequestBody %>
|
|
15
|
+
<% } %>,
|
|
16
|
+
<%- payload.typeRequestBody %>
|
|
17
|
+
>
|
|
18
|
+
<% } %>
|
|
19
|
+
|
|
20
|
+
('<%- payload.url %>',
|
|
21
|
+
<%_ if (payload.requestContentType === 'application/x-www-form-urlencoded') { _%>
|
|
22
|
+
'<%- payload.method %>UrlEncode'
|
|
23
|
+
<%_ } else if (payload.requestContentType === 'multipart/form-data') { _%>
|
|
24
|
+
'<%- payload.method %>Multipart'
|
|
25
|
+
<%_ } else { _%>
|
|
26
|
+
'<%- payload.method %>'
|
|
27
|
+
<%_ } _%>)
|
|
28
|
+
|
|
29
|
+
<% }) %>
|
|
20
30
|
<% } %>
|
|
21
31
|
|
|
22
32
|
<% if (ts) { %>
|
|
23
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
24
|
-
export type <%- payload.type %> = <%- payload.typeValue %>
|
|
25
|
-
|
|
26
|
-
<% }) %>
|
|
27
|
-
|
|
28
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
<% } %>
|
|
33
|
-
<% }) %>
|
|
34
|
-
|
|
35
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
36
|
-
<% if (payload.typeRequestBodyValue) { %>
|
|
37
|
-
export type <%- payload.typeRequestBody %> = <%- payload.typeRequestBodyValue %>
|
|
38
|
-
|
|
39
|
-
<% } %>
|
|
40
|
-
<% }) %>
|
|
41
|
-
|
|
42
|
-
<% apiModule.payloads.forEach(payload => { %>
|
|
43
|
-
<% if (payload.typeResponseBodyValue) { %>
|
|
44
|
-
export type <%- payload.typeResponseBody %> = <%- payload.typeResponseBodyValue %>
|
|
45
|
-
|
|
46
|
-
<% } %>
|
|
47
|
-
<% }) %>
|
|
33
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
34
|
+
export type <%- payload.type %> = <%- payload.typeValue %>
|
|
35
|
+
|
|
36
|
+
<% }) %>
|
|
37
|
+
|
|
38
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
39
|
+
<% if (payload.typeQueryValue) { %>
|
|
40
|
+
export type <%- payload.typeQuery %> = <%- payload.typeQueryValue %>
|
|
41
|
+
|
|
42
|
+
<% } %>
|
|
43
|
+
<% }) %>
|
|
44
|
+
|
|
45
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
46
|
+
<% if (payload.typeRequestBodyValue) { %>
|
|
47
|
+
export type <%- payload.typeRequestBody %> = <%- payload.typeRequestBodyValue %>
|
|
48
|
+
|
|
49
|
+
<% } %>
|
|
50
|
+
<% }) %>
|
|
51
|
+
|
|
52
|
+
<% apiModule.payloads.forEach(payload => { %> %>
|
|
53
|
+
<% if (payload.typeResponseBodyValue) { %>
|
|
54
|
+
export type <%- payload.typeResponseBody %> = <%- payload.typeResponseBodyValue %>
|
|
55
|
+
|
|
56
|
+
<% } %>
|
|
57
|
+
<% }) %>
|
|
48
58
|
<% } %>
|
|
49
59
|
|