api-farmer 0.0.27 → 0.1.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/README.md +5 -0
- package/dist/{chunk-WD3VOWJP.js → chunk-XM4XA35S.js} +32 -11
- package/dist/cli.cjs +31 -11
- package/dist/cli.js +1 -1
- package/dist/{generate-LL4DHOHA.js → generate-BJMNBKQH.js} +1 -1
- package/dist/index.cjs +33 -11
- package/dist/index.d.cts +19 -5
- package/dist/index.d.ts +19 -5
- package/dist/index.js +3 -1
- package/package.json +8 -8
- package/templates/axios.ejs +1 -0
- package/templates/axle.ejs +1 -0
package/README.md
CHANGED
|
@@ -84,6 +84,7 @@ export default defineConfig({
|
|
|
84
84
|
url() {},
|
|
85
85
|
entity() {},
|
|
86
86
|
fn() {},
|
|
87
|
+
comment() {},
|
|
87
88
|
type() {},
|
|
88
89
|
typeValue() {},
|
|
89
90
|
typeQuery() {},
|
|
@@ -189,6 +190,10 @@ export interface ApiModule {
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
export interface ApiModulePayload {
|
|
193
|
+
/**
|
|
194
|
+
* The comment of the API endpoint, including summary, description, URL, and method.
|
|
195
|
+
*/
|
|
196
|
+
comment: string
|
|
192
197
|
/**
|
|
193
198
|
* The name of the API function/dispatcher,
|
|
194
199
|
* such as apiGetUsers, apiCreatePost, apiUpdateComment, etc.
|
|
@@ -39,8 +39,24 @@ import { camelize, pascalCase } from "rattail";
|
|
|
39
39
|
function transformModuleName({ name }) {
|
|
40
40
|
return camelize(name);
|
|
41
41
|
}
|
|
42
|
-
function transformUrl({ path
|
|
43
|
-
return
|
|
42
|
+
function transformUrl({ path }) {
|
|
43
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
44
|
+
}
|
|
45
|
+
function transformComment({
|
|
46
|
+
summary,
|
|
47
|
+
description,
|
|
48
|
+
path,
|
|
49
|
+
method
|
|
50
|
+
}) {
|
|
51
|
+
return `
|
|
52
|
+
/**${summary ? `
|
|
53
|
+
* ${summary}` : ""}${description && summary !== description ? `
|
|
54
|
+
* @description ${description}
|
|
55
|
+
*` : ""}
|
|
56
|
+
* @url ${path}
|
|
57
|
+
* @method ${method.toLocaleUpperCase()}
|
|
58
|
+
*/
|
|
59
|
+
`.trim();
|
|
44
60
|
}
|
|
45
61
|
function transformVerb({ method }) {
|
|
46
62
|
switch (method) {
|
|
@@ -52,8 +68,7 @@ function transformVerb({ method }) {
|
|
|
52
68
|
return pascalCase(method);
|
|
53
69
|
}
|
|
54
70
|
}
|
|
55
|
-
function transformEntity({ path, method,
|
|
56
|
-
path = base ? path.replace(base, "") : path;
|
|
71
|
+
function transformEntity({ path, method, uncountableNouns }) {
|
|
57
72
|
const words = path.split("/").filter(Boolean);
|
|
58
73
|
return words.reduce((entity, word, index) => {
|
|
59
74
|
if (word.includes("{")) {
|
|
@@ -75,8 +90,8 @@ function transformFn({ verb, entity }) {
|
|
|
75
90
|
function transformType({ verb, entity }) {
|
|
76
91
|
return `Api${verb}${entity}`;
|
|
77
92
|
}
|
|
78
|
-
function transformTypeValue({
|
|
79
|
-
return `paths['${
|
|
93
|
+
function transformTypeValue({ fullPath, method }) {
|
|
94
|
+
return `paths['${fullPath}']['${method}']`;
|
|
80
95
|
}
|
|
81
96
|
function transformTypeQuery({ type }) {
|
|
82
97
|
return `${type}Query`;
|
|
@@ -114,6 +129,7 @@ function createTransformer() {
|
|
|
114
129
|
moduleName: transformModuleName,
|
|
115
130
|
verb: transformVerb,
|
|
116
131
|
url: transformUrl,
|
|
132
|
+
comment: transformComment,
|
|
117
133
|
entity: transformEntity,
|
|
118
134
|
fn: transformFn,
|
|
119
135
|
type: transformType,
|
|
@@ -129,12 +145,13 @@ function createTransformer() {
|
|
|
129
145
|
|
|
130
146
|
// src/generate.ts
|
|
131
147
|
function transformPayloads(pathItems, options) {
|
|
132
|
-
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
148
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
133
149
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
134
|
-
const url = transformer.url({ path, base });
|
|
135
|
-
const args = { path, base, url, method, uncountableNouns, operation };
|
|
150
|
+
const url = transformer.url({ path, base, fullPath });
|
|
151
|
+
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
136
152
|
const entity = transformer.entity(args);
|
|
137
153
|
const verb = transformer.verb(args);
|
|
154
|
+
const comment = transformer.comment({ ...args, ...operation });
|
|
138
155
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
139
156
|
const responseMetadataItems = getResponseMetadataItems(operation, validateStatus);
|
|
140
157
|
const fn = transformer.fn({ ...args, verb, entity });
|
|
@@ -154,6 +171,7 @@ function transformPayloads(pathItems, options) {
|
|
|
154
171
|
const typeResponseBody = transformer.typeResponseBody({ ...args, type, verb, entity });
|
|
155
172
|
const typeResponseBodyValue = responseMetadataItems.length > 0 ? transformer.typeResponseBodyValue({ ...args, type, verb, entity, responseMetadataItems }) : "undefined";
|
|
156
173
|
payloads.push({
|
|
174
|
+
comment,
|
|
157
175
|
fn,
|
|
158
176
|
url,
|
|
159
177
|
method,
|
|
@@ -179,11 +197,13 @@ function partitionApiModules(schema, options) {
|
|
|
179
197
|
const keyToPaths = groupBy(schemaPathKeys, (key) => key.split("/")[1]);
|
|
180
198
|
const apiModules = Object.entries(keyToPaths).reduce((apiModules2, [name, paths]) => {
|
|
181
199
|
const payloads = paths.reduce((payloads2, path) => {
|
|
182
|
-
const
|
|
200
|
+
const fullPath = base ? base + path : path;
|
|
201
|
+
const pathItems = schemaPaths[fullPath];
|
|
183
202
|
payloads2.push(
|
|
184
203
|
...transformPayloads(pathItems, {
|
|
185
204
|
...options,
|
|
186
|
-
path
|
|
205
|
+
path,
|
|
206
|
+
fullPath,
|
|
187
207
|
transformer,
|
|
188
208
|
uncountableNouns,
|
|
189
209
|
validateStatus
|
|
@@ -276,6 +296,7 @@ export {
|
|
|
276
296
|
getConfig,
|
|
277
297
|
transformModuleName,
|
|
278
298
|
transformUrl,
|
|
299
|
+
transformComment,
|
|
279
300
|
transformVerb,
|
|
280
301
|
transformEntity,
|
|
281
302
|
transformFn,
|
package/dist/cli.cjs
CHANGED
|
@@ -150,8 +150,24 @@ var init_config = __esm({
|
|
|
150
150
|
function transformModuleName({ name }) {
|
|
151
151
|
return (0, import_rattail2.camelize)(name);
|
|
152
152
|
}
|
|
153
|
-
function transformUrl({ path
|
|
154
|
-
return
|
|
153
|
+
function transformUrl({ path }) {
|
|
154
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
155
|
+
}
|
|
156
|
+
function transformComment({
|
|
157
|
+
summary,
|
|
158
|
+
description,
|
|
159
|
+
path,
|
|
160
|
+
method
|
|
161
|
+
}) {
|
|
162
|
+
return `
|
|
163
|
+
/**${summary ? `
|
|
164
|
+
* ${summary}` : ""}${description && summary !== description ? `
|
|
165
|
+
* @description ${description}
|
|
166
|
+
*` : ""}
|
|
167
|
+
* @url ${path}
|
|
168
|
+
* @method ${method.toLocaleUpperCase()}
|
|
169
|
+
*/
|
|
170
|
+
`.trim();
|
|
155
171
|
}
|
|
156
172
|
function transformVerb({ method }) {
|
|
157
173
|
switch (method) {
|
|
@@ -163,8 +179,7 @@ function transformVerb({ method }) {
|
|
|
163
179
|
return (0, import_rattail2.pascalCase)(method);
|
|
164
180
|
}
|
|
165
181
|
}
|
|
166
|
-
function transformEntity({ path, method,
|
|
167
|
-
path = base ? path.replace(base, "") : path;
|
|
182
|
+
function transformEntity({ path, method, uncountableNouns }) {
|
|
168
183
|
const words = path.split("/").filter(Boolean);
|
|
169
184
|
return words.reduce((entity, word, index) => {
|
|
170
185
|
if (word.includes("{")) {
|
|
@@ -186,8 +201,8 @@ function transformFn({ verb, entity }) {
|
|
|
186
201
|
function transformType({ verb, entity }) {
|
|
187
202
|
return `Api${verb}${entity}`;
|
|
188
203
|
}
|
|
189
|
-
function transformTypeValue({
|
|
190
|
-
return `paths['${
|
|
204
|
+
function transformTypeValue({ fullPath, method }) {
|
|
205
|
+
return `paths['${fullPath}']['${method}']`;
|
|
191
206
|
}
|
|
192
207
|
function transformTypeQuery({ type }) {
|
|
193
208
|
return `${type}Query`;
|
|
@@ -225,6 +240,7 @@ function createTransformer() {
|
|
|
225
240
|
moduleName: transformModuleName,
|
|
226
241
|
verb: transformVerb,
|
|
227
242
|
url: transformUrl,
|
|
243
|
+
comment: transformComment,
|
|
228
244
|
entity: transformEntity,
|
|
229
245
|
fn: transformFn,
|
|
230
246
|
type: transformType,
|
|
@@ -257,12 +273,13 @@ __export(generate_exports, {
|
|
|
257
273
|
transformPayloads: () => transformPayloads
|
|
258
274
|
});
|
|
259
275
|
function transformPayloads(pathItems, options) {
|
|
260
|
-
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
276
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
261
277
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
262
|
-
const url = transformer.url({ path, base });
|
|
263
|
-
const args = { path, base, url, method, uncountableNouns, operation };
|
|
278
|
+
const url = transformer.url({ path, base, fullPath });
|
|
279
|
+
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
264
280
|
const entity = transformer.entity(args);
|
|
265
281
|
const verb = transformer.verb(args);
|
|
282
|
+
const comment = transformer.comment({ ...args, ...operation });
|
|
266
283
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
267
284
|
const responseMetadataItems = getResponseMetadataItems(operation, validateStatus);
|
|
268
285
|
const fn = transformer.fn({ ...args, verb, entity });
|
|
@@ -282,6 +299,7 @@ function transformPayloads(pathItems, options) {
|
|
|
282
299
|
const typeResponseBody = transformer.typeResponseBody({ ...args, type, verb, entity });
|
|
283
300
|
const typeResponseBodyValue = responseMetadataItems.length > 0 ? transformer.typeResponseBodyValue({ ...args, type, verb, entity, responseMetadataItems }) : "undefined";
|
|
284
301
|
payloads.push({
|
|
302
|
+
comment,
|
|
285
303
|
fn,
|
|
286
304
|
url,
|
|
287
305
|
method,
|
|
@@ -307,11 +325,13 @@ function partitionApiModules(schema, options) {
|
|
|
307
325
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
308
326
|
const apiModules = Object.entries(keyToPaths).reduce((apiModules2, [name, paths]) => {
|
|
309
327
|
const payloads = paths.reduce((payloads2, path) => {
|
|
310
|
-
const
|
|
328
|
+
const fullPath = base ? base + path : path;
|
|
329
|
+
const pathItems = schemaPaths[fullPath];
|
|
311
330
|
payloads2.push(
|
|
312
331
|
...transformPayloads(pathItems, {
|
|
313
332
|
...options,
|
|
314
|
-
path
|
|
333
|
+
path,
|
|
334
|
+
fullPath,
|
|
315
335
|
transformer,
|
|
316
336
|
uncountableNouns,
|
|
317
337
|
validateStatus
|
package/dist/cli.js
CHANGED
|
@@ -8,7 +8,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-BJMNBKQH.js");
|
|
12
12
|
return generate();
|
|
13
13
|
});
|
|
14
14
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -49,6 +49,7 @@ __export(index_exports, {
|
|
|
49
49
|
readSchemaContent: () => readSchemaContent,
|
|
50
50
|
readTemplateFile: () => readTemplateFile,
|
|
51
51
|
renderApiModules: () => renderApiModules,
|
|
52
|
+
transformComment: () => transformComment,
|
|
52
53
|
transformEntity: () => transformEntity,
|
|
53
54
|
transformFn: () => transformFn,
|
|
54
55
|
transformModuleName: () => transformModuleName,
|
|
@@ -72,8 +73,24 @@ var import_rattail = require("rattail");
|
|
|
72
73
|
function transformModuleName({ name }) {
|
|
73
74
|
return (0, import_rattail.camelize)(name);
|
|
74
75
|
}
|
|
75
|
-
function transformUrl({ path
|
|
76
|
-
return
|
|
76
|
+
function transformUrl({ path }) {
|
|
77
|
+
return path.replace(/{/g, ":").replace(/}/g, "");
|
|
78
|
+
}
|
|
79
|
+
function transformComment({
|
|
80
|
+
summary,
|
|
81
|
+
description,
|
|
82
|
+
path,
|
|
83
|
+
method
|
|
84
|
+
}) {
|
|
85
|
+
return `
|
|
86
|
+
/**${summary ? `
|
|
87
|
+
* ${summary}` : ""}${description && summary !== description ? `
|
|
88
|
+
* @description ${description}
|
|
89
|
+
*` : ""}
|
|
90
|
+
* @url ${path}
|
|
91
|
+
* @method ${method.toLocaleUpperCase()}
|
|
92
|
+
*/
|
|
93
|
+
`.trim();
|
|
77
94
|
}
|
|
78
95
|
function transformVerb({ method }) {
|
|
79
96
|
switch (method) {
|
|
@@ -85,8 +102,7 @@ function transformVerb({ method }) {
|
|
|
85
102
|
return (0, import_rattail.pascalCase)(method);
|
|
86
103
|
}
|
|
87
104
|
}
|
|
88
|
-
function transformEntity({ path, method,
|
|
89
|
-
path = base ? path.replace(base, "") : path;
|
|
105
|
+
function transformEntity({ path, method, uncountableNouns }) {
|
|
90
106
|
const words = path.split("/").filter(Boolean);
|
|
91
107
|
return words.reduce((entity, word, index) => {
|
|
92
108
|
if (word.includes("{")) {
|
|
@@ -108,8 +124,8 @@ function transformFn({ verb, entity }) {
|
|
|
108
124
|
function transformType({ verb, entity }) {
|
|
109
125
|
return `Api${verb}${entity}`;
|
|
110
126
|
}
|
|
111
|
-
function transformTypeValue({
|
|
112
|
-
return `paths['${
|
|
127
|
+
function transformTypeValue({ fullPath, method }) {
|
|
128
|
+
return `paths['${fullPath}']['${method}']`;
|
|
113
129
|
}
|
|
114
130
|
function transformTypeQuery({ type }) {
|
|
115
131
|
return `${type}Query`;
|
|
@@ -147,6 +163,7 @@ function createTransformer() {
|
|
|
147
163
|
moduleName: transformModuleName,
|
|
148
164
|
verb: transformVerb,
|
|
149
165
|
url: transformUrl,
|
|
166
|
+
comment: transformComment,
|
|
150
167
|
entity: transformEntity,
|
|
151
168
|
fn: transformFn,
|
|
152
169
|
type: transformType,
|
|
@@ -296,12 +313,13 @@ function getResponseMetadataItems(operation, validateStatus) {
|
|
|
296
313
|
|
|
297
314
|
// src/generate.ts
|
|
298
315
|
function transformPayloads(pathItems, options) {
|
|
299
|
-
const { transformer, path, base, uncountableNouns, validateStatus } = options;
|
|
316
|
+
const { transformer, path, fullPath, base, uncountableNouns, validateStatus } = options;
|
|
300
317
|
return Object.entries(pathItems).filter(([key]) => SUPPORTED_HTTP_METHODS.includes(key)).reduce((payloads, [method, operation]) => {
|
|
301
|
-
const url = transformer.url({ path, base });
|
|
302
|
-
const args = { path, base, url, method, uncountableNouns, operation };
|
|
318
|
+
const url = transformer.url({ path, base, fullPath });
|
|
319
|
+
const args = { path, base, fullPath, url, method, uncountableNouns, operation };
|
|
303
320
|
const entity = transformer.entity(args);
|
|
304
321
|
const verb = transformer.verb(args);
|
|
322
|
+
const comment = transformer.comment({ ...args, ...operation });
|
|
305
323
|
const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
|
|
306
324
|
const responseMetadataItems = getResponseMetadataItems(operation, validateStatus);
|
|
307
325
|
const fn = transformer.fn({ ...args, verb, entity });
|
|
@@ -321,6 +339,7 @@ function transformPayloads(pathItems, options) {
|
|
|
321
339
|
const typeResponseBody = transformer.typeResponseBody({ ...args, type, verb, entity });
|
|
322
340
|
const typeResponseBodyValue = responseMetadataItems.length > 0 ? transformer.typeResponseBodyValue({ ...args, type, verb, entity, responseMetadataItems }) : "undefined";
|
|
323
341
|
payloads.push({
|
|
342
|
+
comment,
|
|
324
343
|
fn,
|
|
325
344
|
url,
|
|
326
345
|
method,
|
|
@@ -346,11 +365,13 @@ function partitionApiModules(schema, options) {
|
|
|
346
365
|
const keyToPaths = (0, import_rattail3.groupBy)(schemaPathKeys, (key) => key.split("/")[1]);
|
|
347
366
|
const apiModules = Object.entries(keyToPaths).reduce((apiModules2, [name, paths]) => {
|
|
348
367
|
const payloads = paths.reduce((payloads2, path) => {
|
|
349
|
-
const
|
|
368
|
+
const fullPath = base ? base + path : path;
|
|
369
|
+
const pathItems = schemaPaths[fullPath];
|
|
350
370
|
payloads2.push(
|
|
351
371
|
...transformPayloads(pathItems, {
|
|
352
372
|
...options,
|
|
353
|
-
path
|
|
373
|
+
path,
|
|
374
|
+
fullPath,
|
|
354
375
|
transformer,
|
|
355
376
|
uncountableNouns,
|
|
356
377
|
validateStatus
|
|
@@ -461,6 +482,7 @@ var import_pluralize2 = __toESM(require("pluralize"), 1);
|
|
|
461
482
|
readSchemaContent,
|
|
462
483
|
readTemplateFile,
|
|
463
484
|
renderApiModules,
|
|
485
|
+
transformComment,
|
|
464
486
|
transformEntity,
|
|
465
487
|
transformFn,
|
|
466
488
|
transformModuleName,
|
package/dist/index.d.cts
CHANGED
|
@@ -54,6 +54,7 @@ declare function getResponseMetadataItems(operation: OperationObject, validateSt
|
|
|
54
54
|
|
|
55
55
|
type TransformerBaseArgs = {
|
|
56
56
|
path: string;
|
|
57
|
+
fullPath: string;
|
|
57
58
|
base: string | undefined;
|
|
58
59
|
url: string;
|
|
59
60
|
method: string;
|
|
@@ -63,14 +64,21 @@ type TransformerBaseArgs = {
|
|
|
63
64
|
declare function transformModuleName({ name }: {
|
|
64
65
|
name: string;
|
|
65
66
|
}): string;
|
|
66
|
-
declare function transformUrl({ path
|
|
67
|
+
declare function transformUrl({ path }: {
|
|
67
68
|
path: string;
|
|
69
|
+
fullPath: string;
|
|
68
70
|
base: string | undefined;
|
|
69
71
|
}): string;
|
|
72
|
+
declare function transformComment({ summary, description, path, method, }: {
|
|
73
|
+
summary?: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
path: string;
|
|
76
|
+
method: string;
|
|
77
|
+
} & TransformerBaseArgs): string;
|
|
70
78
|
declare function transformVerb({ method }: {
|
|
71
79
|
method: string;
|
|
72
80
|
}): string;
|
|
73
|
-
declare function transformEntity({ path, method,
|
|
81
|
+
declare function transformEntity({ path, method, uncountableNouns }: TransformerBaseArgs): string;
|
|
74
82
|
declare function transformFn({ verb, entity }: {
|
|
75
83
|
verb: string;
|
|
76
84
|
entity: string;
|
|
@@ -79,7 +87,7 @@ declare function transformType({ verb, entity }: {
|
|
|
79
87
|
verb: string;
|
|
80
88
|
entity: string;
|
|
81
89
|
} & TransformerBaseArgs): string;
|
|
82
|
-
declare function transformTypeValue({
|
|
90
|
+
declare function transformTypeValue({ fullPath, method }: {
|
|
83
91
|
verb: string;
|
|
84
92
|
entity: string;
|
|
85
93
|
} & TransformerBaseArgs): string;
|
|
@@ -120,6 +128,7 @@ interface Transformer {
|
|
|
120
128
|
moduleName: typeof transformModuleName;
|
|
121
129
|
verb: typeof transformVerb;
|
|
122
130
|
url: typeof transformUrl;
|
|
131
|
+
comment: typeof transformComment;
|
|
123
132
|
entity: typeof transformEntity;
|
|
124
133
|
fn: typeof transformFn;
|
|
125
134
|
type: typeof transformType;
|
|
@@ -162,6 +171,10 @@ interface ApiModule {
|
|
|
162
171
|
payloads: ApiModulePayload[];
|
|
163
172
|
}
|
|
164
173
|
interface ApiModulePayload {
|
|
174
|
+
/**
|
|
175
|
+
* The comment of the API endpoint, including summary, description, URL, and method.
|
|
176
|
+
*/
|
|
177
|
+
comment: string;
|
|
165
178
|
/**
|
|
166
179
|
* The name of the API function/dispatcher, such as apiGetUsers, apiCreatePost, apiUpdateComment, etc.
|
|
167
180
|
*/
|
|
@@ -275,8 +288,9 @@ interface GenerateOptions {
|
|
|
275
288
|
}
|
|
276
289
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
277
290
|
path: string;
|
|
278
|
-
|
|
291
|
+
fullPath: string;
|
|
279
292
|
base: string | undefined;
|
|
293
|
+
transformer: Transformer;
|
|
280
294
|
uncountableNouns: string[];
|
|
281
295
|
validateStatus: (status: number) => boolean;
|
|
282
296
|
}): ApiModulePayload[];
|
|
@@ -301,4 +315,4 @@ type Config = GenerateOptions;
|
|
|
301
315
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
302
316
|
declare function getConfig(): Promise<Config>;
|
|
303
317
|
|
|
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, getSchemaNode, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
|
318
|
+
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, getSchemaNode, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformComment, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
package/dist/index.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ declare function getResponseMetadataItems(operation: OperationObject, validateSt
|
|
|
54
54
|
|
|
55
55
|
type TransformerBaseArgs = {
|
|
56
56
|
path: string;
|
|
57
|
+
fullPath: string;
|
|
57
58
|
base: string | undefined;
|
|
58
59
|
url: string;
|
|
59
60
|
method: string;
|
|
@@ -63,14 +64,21 @@ type TransformerBaseArgs = {
|
|
|
63
64
|
declare function transformModuleName({ name }: {
|
|
64
65
|
name: string;
|
|
65
66
|
}): string;
|
|
66
|
-
declare function transformUrl({ path
|
|
67
|
+
declare function transformUrl({ path }: {
|
|
67
68
|
path: string;
|
|
69
|
+
fullPath: string;
|
|
68
70
|
base: string | undefined;
|
|
69
71
|
}): string;
|
|
72
|
+
declare function transformComment({ summary, description, path, method, }: {
|
|
73
|
+
summary?: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
path: string;
|
|
76
|
+
method: string;
|
|
77
|
+
} & TransformerBaseArgs): string;
|
|
70
78
|
declare function transformVerb({ method }: {
|
|
71
79
|
method: string;
|
|
72
80
|
}): string;
|
|
73
|
-
declare function transformEntity({ path, method,
|
|
81
|
+
declare function transformEntity({ path, method, uncountableNouns }: TransformerBaseArgs): string;
|
|
74
82
|
declare function transformFn({ verb, entity }: {
|
|
75
83
|
verb: string;
|
|
76
84
|
entity: string;
|
|
@@ -79,7 +87,7 @@ declare function transformType({ verb, entity }: {
|
|
|
79
87
|
verb: string;
|
|
80
88
|
entity: string;
|
|
81
89
|
} & TransformerBaseArgs): string;
|
|
82
|
-
declare function transformTypeValue({
|
|
90
|
+
declare function transformTypeValue({ fullPath, method }: {
|
|
83
91
|
verb: string;
|
|
84
92
|
entity: string;
|
|
85
93
|
} & TransformerBaseArgs): string;
|
|
@@ -120,6 +128,7 @@ interface Transformer {
|
|
|
120
128
|
moduleName: typeof transformModuleName;
|
|
121
129
|
verb: typeof transformVerb;
|
|
122
130
|
url: typeof transformUrl;
|
|
131
|
+
comment: typeof transformComment;
|
|
123
132
|
entity: typeof transformEntity;
|
|
124
133
|
fn: typeof transformFn;
|
|
125
134
|
type: typeof transformType;
|
|
@@ -162,6 +171,10 @@ interface ApiModule {
|
|
|
162
171
|
payloads: ApiModulePayload[];
|
|
163
172
|
}
|
|
164
173
|
interface ApiModulePayload {
|
|
174
|
+
/**
|
|
175
|
+
* The comment of the API endpoint, including summary, description, URL, and method.
|
|
176
|
+
*/
|
|
177
|
+
comment: string;
|
|
165
178
|
/**
|
|
166
179
|
* The name of the API function/dispatcher, such as apiGetUsers, apiCreatePost, apiUpdateComment, etc.
|
|
167
180
|
*/
|
|
@@ -275,8 +288,9 @@ interface GenerateOptions {
|
|
|
275
288
|
}
|
|
276
289
|
declare function transformPayloads(pathItems: Record<string, OperationObject>, options: {
|
|
277
290
|
path: string;
|
|
278
|
-
|
|
291
|
+
fullPath: string;
|
|
279
292
|
base: string | undefined;
|
|
293
|
+
transformer: Transformer;
|
|
280
294
|
uncountableNouns: string[];
|
|
281
295
|
validateStatus: (status: number) => boolean;
|
|
282
296
|
}): ApiModulePayload[];
|
|
@@ -301,4 +315,4 @@ type Config = GenerateOptions;
|
|
|
301
315
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
302
316
|
declare function getConfig(): Promise<Config>;
|
|
303
317
|
|
|
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, getSchemaNode, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
|
318
|
+
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, getSchemaNode, isRemoteSchema, isRequiredRequestBody, partitionApiModules, readSchema, readSchemaContent, readTemplateFile, renderApiModules, transformComment, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getConfig,
|
|
7
7
|
partitionApiModules,
|
|
8
8
|
renderApiModules,
|
|
9
|
+
transformComment,
|
|
9
10
|
transformEntity,
|
|
10
11
|
transformFn,
|
|
11
12
|
transformModuleName,
|
|
@@ -20,7 +21,7 @@ import {
|
|
|
20
21
|
transformTypeValue,
|
|
21
22
|
transformUrl,
|
|
22
23
|
transformVerb
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-XM4XA35S.js";
|
|
24
25
|
import {
|
|
25
26
|
createStatusCodesByStrategy,
|
|
26
27
|
findObjectKey,
|
|
@@ -57,6 +58,7 @@ export {
|
|
|
57
58
|
readSchemaContent,
|
|
58
59
|
readTemplateFile,
|
|
59
60
|
renderApiModules,
|
|
61
|
+
transformComment,
|
|
60
62
|
transformEntity,
|
|
61
63
|
transformFn,
|
|
62
64
|
transformModuleName,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "api-farmer",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "API module generation tool based on Openapi3/Swagger2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -55,21 +55,21 @@
|
|
|
55
55
|
"fs-extra": "^11.2.0",
|
|
56
56
|
"openapi-typescript": "^7.5.2",
|
|
57
57
|
"pluralize": "^8.0.0",
|
|
58
|
+
"prettier": "^3.4.2",
|
|
58
59
|
"rattail": "^1.0.19",
|
|
59
60
|
"rslog": "^1.2.3",
|
|
60
61
|
"swagger2openapi": "^7.0.8",
|
|
61
62
|
"unconfig": "^0.6.0",
|
|
62
|
-
"yaml": "^2.7.0"
|
|
63
|
-
"prettier": "^3.4.2"
|
|
63
|
+
"yaml": "^2.7.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@configurajs/eslint": "^0.1.
|
|
67
|
-
"@configurajs/prettier": "^0.1.
|
|
66
|
+
"@configurajs/eslint": "^0.1.2",
|
|
67
|
+
"@configurajs/prettier": "^0.1.4",
|
|
68
68
|
"@types/ejs": "^3.1.5",
|
|
69
69
|
"@types/fs-extra": "^11.0.4",
|
|
70
70
|
"@types/node": "^22.8.1",
|
|
71
71
|
"@types/swagger2openapi": "^7.0.4",
|
|
72
|
-
"@varlet/release": "^0.
|
|
72
|
+
"@varlet/release": "^0.4.1",
|
|
73
73
|
"eslint": "^9.17.0",
|
|
74
74
|
"nano-staged": "0.8.0",
|
|
75
75
|
"rimraf": "^6.0.1",
|
|
@@ -88,8 +88,8 @@
|
|
|
88
88
|
"clean": "rimraf node_modules dist",
|
|
89
89
|
"dev": "tsup src/index.ts src/cli.ts --format esm,cjs --watch --dts --shims",
|
|
90
90
|
"format": "prettier --write .",
|
|
91
|
+
"gen": "rimraf ./fixtures/axios/src/apis/generated ./fixtures/axle/src/apis/generated && pnpm --dir ./fixtures/axios gen & pnpm --dir ./fixtures/axle gen",
|
|
91
92
|
"lint": "eslint . --fix",
|
|
92
|
-
"release": "pnpm build && vr release"
|
|
93
|
-
"gen": "rimraf ./fixtures/axios/src/apis/generated ./fixtures/axle/src/apis/generated && pnpm --dir ./fixtures/axios gen & pnpm --dir ./fixtures/axle gen"
|
|
93
|
+
"release": "pnpm build && vr release"
|
|
94
94
|
}
|
|
95
95
|
}
|
package/templates/axios.ejs
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<%_ if (!typesOnly) { _%>
|
|
6
6
|
<% apiModule.payloads.forEach(payload => { %> %>
|
|
7
|
+
<%- payload.comment %>
|
|
7
8
|
export const <%- payload.fn %> =
|
|
8
9
|
(config<% if (ts) { %>: RequestConfig<<%- payload.typeQuery %>, <%- payload.typeRequestBody %>> <% } %> = {}) => request
|
|
9
10
|
<% if (ts) { %><<%- payload.typeResponseBody %>><% } %>({
|