api-farmer 0.0.28 → 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 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.
@@ -42,6 +42,22 @@ function transformModuleName({ name }) {
42
42
  function transformUrl({ path }) {
43
43
  return path.replace(/{/g, ":").replace(/}/g, "");
44
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();
60
+ }
45
61
  function transformVerb({ method }) {
46
62
  switch (method) {
47
63
  case "post":
@@ -113,6 +129,7 @@ function createTransformer() {
113
129
  moduleName: transformModuleName,
114
130
  verb: transformVerb,
115
131
  url: transformUrl,
132
+ comment: transformComment,
116
133
  entity: transformEntity,
117
134
  fn: transformFn,
118
135
  type: transformType,
@@ -134,6 +151,7 @@ function transformPayloads(pathItems, options) {
134
151
  const args = { path, base, fullPath, url, method, uncountableNouns, operation };
135
152
  const entity = transformer.entity(args);
136
153
  const verb = transformer.verb(args);
154
+ const comment = transformer.comment({ ...args, ...operation });
137
155
  const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
138
156
  const responseMetadataItems = getResponseMetadataItems(operation, validateStatus);
139
157
  const fn = transformer.fn({ ...args, verb, entity });
@@ -153,6 +171,7 @@ function transformPayloads(pathItems, options) {
153
171
  const typeResponseBody = transformer.typeResponseBody({ ...args, type, verb, entity });
154
172
  const typeResponseBodyValue = responseMetadataItems.length > 0 ? transformer.typeResponseBodyValue({ ...args, type, verb, entity, responseMetadataItems }) : "undefined";
155
173
  payloads.push({
174
+ comment,
156
175
  fn,
157
176
  url,
158
177
  method,
@@ -277,6 +296,7 @@ export {
277
296
  getConfig,
278
297
  transformModuleName,
279
298
  transformUrl,
299
+ transformComment,
280
300
  transformVerb,
281
301
  transformEntity,
282
302
  transformFn,
package/dist/cli.cjs CHANGED
@@ -153,6 +153,22 @@ function transformModuleName({ name }) {
153
153
  function transformUrl({ path }) {
154
154
  return path.replace(/{/g, ":").replace(/}/g, "");
155
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();
171
+ }
156
172
  function transformVerb({ method }) {
157
173
  switch (method) {
158
174
  case "post":
@@ -224,6 +240,7 @@ function createTransformer() {
224
240
  moduleName: transformModuleName,
225
241
  verb: transformVerb,
226
242
  url: transformUrl,
243
+ comment: transformComment,
227
244
  entity: transformEntity,
228
245
  fn: transformFn,
229
246
  type: transformType,
@@ -262,6 +279,7 @@ function transformPayloads(pathItems, options) {
262
279
  const args = { path, base, fullPath, url, method, uncountableNouns, operation };
263
280
  const entity = transformer.entity(args);
264
281
  const verb = transformer.verb(args);
282
+ const comment = transformer.comment({ ...args, ...operation });
265
283
  const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
266
284
  const responseMetadataItems = getResponseMetadataItems(operation, validateStatus);
267
285
  const fn = transformer.fn({ ...args, verb, entity });
@@ -281,6 +299,7 @@ function transformPayloads(pathItems, options) {
281
299
  const typeResponseBody = transformer.typeResponseBody({ ...args, type, verb, entity });
282
300
  const typeResponseBodyValue = responseMetadataItems.length > 0 ? transformer.typeResponseBodyValue({ ...args, type, verb, entity, responseMetadataItems }) : "undefined";
283
301
  payloads.push({
302
+ comment,
284
303
  fn,
285
304
  url,
286
305
  method,
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-NRJ4NQ4O.js");
11
+ const { generate } = await import("./generate-BJMNBKQH.js");
12
12
  return generate();
13
13
  });
14
14
  program.parse();
@@ -4,7 +4,7 @@ import {
4
4
  partitionApiModules,
5
5
  renderApiModules,
6
6
  transformPayloads
7
- } from "./chunk-XM2F7GOE.js";
7
+ } from "./chunk-XM4XA35S.js";
8
8
  import "./chunk-56NOW5DM.js";
9
9
  export {
10
10
  generate,
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,
@@ -75,6 +76,22 @@ function transformModuleName({ name }) {
75
76
  function transformUrl({ path }) {
76
77
  return path.replace(/{/g, ":").replace(/}/g, "");
77
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();
94
+ }
78
95
  function transformVerb({ method }) {
79
96
  switch (method) {
80
97
  case "post":
@@ -146,6 +163,7 @@ function createTransformer() {
146
163
  moduleName: transformModuleName,
147
164
  verb: transformVerb,
148
165
  url: transformUrl,
166
+ comment: transformComment,
149
167
  entity: transformEntity,
150
168
  fn: transformFn,
151
169
  type: transformType,
@@ -301,6 +319,7 @@ function transformPayloads(pathItems, options) {
301
319
  const args = { path, base, fullPath, url, method, uncountableNouns, operation };
302
320
  const entity = transformer.entity(args);
303
321
  const verb = transformer.verb(args);
322
+ const comment = transformer.comment({ ...args, ...operation });
304
323
  const requestContentType = operation.requestBody ? getRequestBodyContentType(operation.requestBody) : void 0;
305
324
  const responseMetadataItems = getResponseMetadataItems(operation, validateStatus);
306
325
  const fn = transformer.fn({ ...args, verb, entity });
@@ -320,6 +339,7 @@ function transformPayloads(pathItems, options) {
320
339
  const typeResponseBody = transformer.typeResponseBody({ ...args, type, verb, entity });
321
340
  const typeResponseBodyValue = responseMetadataItems.length > 0 ? transformer.typeResponseBodyValue({ ...args, type, verb, entity, responseMetadataItems }) : "undefined";
322
341
  payloads.push({
342
+ comment,
323
343
  fn,
324
344
  url,
325
345
  method,
@@ -462,6 +482,7 @@ var import_pluralize2 = __toESM(require("pluralize"), 1);
462
482
  readSchemaContent,
463
483
  readTemplateFile,
464
484
  renderApiModules,
485
+ transformComment,
465
486
  transformEntity,
466
487
  transformFn,
467
488
  transformModuleName,
package/dist/index.d.cts CHANGED
@@ -69,6 +69,12 @@ declare function transformUrl({ path }: {
69
69
  fullPath: string;
70
70
  base: string | undefined;
71
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;
72
78
  declare function transformVerb({ method }: {
73
79
  method: string;
74
80
  }): string;
@@ -122,6 +128,7 @@ interface Transformer {
122
128
  moduleName: typeof transformModuleName;
123
129
  verb: typeof transformVerb;
124
130
  url: typeof transformUrl;
131
+ comment: typeof transformComment;
125
132
  entity: typeof transformEntity;
126
133
  fn: typeof transformFn;
127
134
  type: typeof transformType;
@@ -164,6 +171,10 @@ interface ApiModule {
164
171
  payloads: ApiModulePayload[];
165
172
  }
166
173
  interface ApiModulePayload {
174
+ /**
175
+ * The comment of the API endpoint, including summary, description, URL, and method.
176
+ */
177
+ comment: string;
167
178
  /**
168
179
  * The name of the API function/dispatcher, such as apiGetUsers, apiCreatePost, apiUpdateComment, etc.
169
180
  */
@@ -304,4 +315,4 @@ type Config = GenerateOptions;
304
315
  declare function defineConfig(config: Config): GenerateOptions;
305
316
  declare function getConfig(): Promise<Config>;
306
317
 
307
- 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
@@ -69,6 +69,12 @@ declare function transformUrl({ path }: {
69
69
  fullPath: string;
70
70
  base: string | undefined;
71
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;
72
78
  declare function transformVerb({ method }: {
73
79
  method: string;
74
80
  }): string;
@@ -122,6 +128,7 @@ interface Transformer {
122
128
  moduleName: typeof transformModuleName;
123
129
  verb: typeof transformVerb;
124
130
  url: typeof transformUrl;
131
+ comment: typeof transformComment;
125
132
  entity: typeof transformEntity;
126
133
  fn: typeof transformFn;
127
134
  type: typeof transformType;
@@ -164,6 +171,10 @@ interface ApiModule {
164
171
  payloads: ApiModulePayload[];
165
172
  }
166
173
  interface ApiModulePayload {
174
+ /**
175
+ * The comment of the API endpoint, including summary, description, URL, and method.
176
+ */
177
+ comment: string;
167
178
  /**
168
179
  * The name of the API function/dispatcher, such as apiGetUsers, apiCreatePost, apiUpdateComment, etc.
169
180
  */
@@ -304,4 +315,4 @@ type Config = GenerateOptions;
304
315
  declare function defineConfig(config: Config): GenerateOptions;
305
316
  declare function getConfig(): Promise<Config>;
306
317
 
307
- 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-XM2F7GOE.js";
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.28",
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.0",
67
- "@configurajs/prettier": "^0.1.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.3.1",
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
  }
@@ -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 %>><% } %>({
@@ -3,6 +3,7 @@
3
3
 
4
4
  <% if (!typesOnly) { %>
5
5
  <% apiModule.payloads.forEach(payload => { %> %>
6
+ <%- payload.comment %>
6
7
  export const <%- payload.fn %> = api
7
8
 
8
9
  <% if (ts) { %>