api-farmer 0.0.19 → 0.0.21

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/index.d.cts CHANGED
@@ -38,15 +38,18 @@ declare function createStatusCodesByStrategy(strategy: StatusCodeStrategy): {
38
38
  head: number;
39
39
  };
40
40
  declare function readSchema(input: string): Promise<OpenAPI3>;
41
+ declare function readSchemaContent(input: string): Promise<string>;
42
+ declare function isRemoteSchema(path: string): boolean;
41
43
  declare function readTemplateFile(preset?: Preset): string;
42
44
  declare function hasQueryParameter(operation: OperationObject): boolean;
43
45
  declare function getCliVersion(): any;
44
46
  declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
47
+ declare function getRequestBodyContentType(value: RequestBodyObject | ReferenceObject): "" | "application/json" | "application/x-www-form-urlencoded" | undefined;
45
48
  type ResponseMetadataItem = {
46
49
  status: number;
47
- mime: string;
50
+ responseContentType: string;
48
51
  };
49
- declare function getValidResponseMetadataItems(operation: OperationObject, validateStatus: (status: number) => boolean): ResponseMetadataItem[];
52
+ declare function getResponseMetadataItems(operation: OperationObject, validateStatus: (status: number) => boolean): ResponseMetadataItem[];
50
53
 
51
54
  type TransformerBaseArgs = {
52
55
  path: string;
@@ -93,11 +96,12 @@ declare function transformTypeRequestBody({ type, }: {
93
96
  verb: string;
94
97
  entity: string;
95
98
  } & TransformerBaseArgs): string;
96
- declare function transformTypeRequestBodyValue({ type, required, }: {
99
+ declare function transformTypeRequestBodyValue({ type, required, requestContentType, }: {
97
100
  type: string;
98
101
  verb: string;
99
102
  entity: string;
100
103
  required: boolean;
104
+ requestContentType: string;
101
105
  } & TransformerBaseArgs): string;
102
106
  declare function transformTypeResponseBody({ type, }: {
103
107
  type: string;
@@ -176,6 +180,10 @@ interface ApiModulePayload {
176
180
  * The entity name of the API endpoint, such as User, Comment, Post, etc.
177
181
  */
178
182
  entity: string;
183
+ /**
184
+ * The request content type of the API endpoint, such as 'application/json', 'application/x-www-form-urlencoded'.
185
+ */
186
+ requestContentType?: string;
179
187
  /**
180
188
  * The type name of the API endpoint, such as ApiGetUsers, ApiCreatePost, ApiUpdateComment, etc.
181
189
  */
@@ -285,4 +293,4 @@ type Config = GenerateOptions;
285
293
  declare function defineConfig(config: Config): GenerateOptions;
286
294
  declare function getConfig(): Promise<Config>;
287
295
 
288
- 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, getValidResponseMetadataItems, hasQueryParameter, isRequiredRequestBody, partitionApiModules, readSchema, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
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 };
package/dist/index.d.ts CHANGED
@@ -38,15 +38,18 @@ declare function createStatusCodesByStrategy(strategy: StatusCodeStrategy): {
38
38
  head: number;
39
39
  };
40
40
  declare function readSchema(input: string): Promise<OpenAPI3>;
41
+ declare function readSchemaContent(input: string): Promise<string>;
42
+ declare function isRemoteSchema(path: string): boolean;
41
43
  declare function readTemplateFile(preset?: Preset): string;
42
44
  declare function hasQueryParameter(operation: OperationObject): boolean;
43
45
  declare function getCliVersion(): any;
44
46
  declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
47
+ declare function getRequestBodyContentType(value: RequestBodyObject | ReferenceObject): "" | "application/json" | "application/x-www-form-urlencoded" | undefined;
45
48
  type ResponseMetadataItem = {
46
49
  status: number;
47
- mime: string;
50
+ responseContentType: string;
48
51
  };
49
- declare function getValidResponseMetadataItems(operation: OperationObject, validateStatus: (status: number) => boolean): ResponseMetadataItem[];
52
+ declare function getResponseMetadataItems(operation: OperationObject, validateStatus: (status: number) => boolean): ResponseMetadataItem[];
50
53
 
51
54
  type TransformerBaseArgs = {
52
55
  path: string;
@@ -93,11 +96,12 @@ declare function transformTypeRequestBody({ type, }: {
93
96
  verb: string;
94
97
  entity: string;
95
98
  } & TransformerBaseArgs): string;
96
- declare function transformTypeRequestBodyValue({ type, required, }: {
99
+ declare function transformTypeRequestBodyValue({ type, required, requestContentType, }: {
97
100
  type: string;
98
101
  verb: string;
99
102
  entity: string;
100
103
  required: boolean;
104
+ requestContentType: string;
101
105
  } & TransformerBaseArgs): string;
102
106
  declare function transformTypeResponseBody({ type, }: {
103
107
  type: string;
@@ -176,6 +180,10 @@ interface ApiModulePayload {
176
180
  * The entity name of the API endpoint, such as User, Comment, Post, etc.
177
181
  */
178
182
  entity: string;
183
+ /**
184
+ * The request content type of the API endpoint, such as 'application/json', 'application/x-www-form-urlencoded'.
185
+ */
186
+ requestContentType?: string;
179
187
  /**
180
188
  * The type name of the API endpoint, such as ApiGetUsers, ApiCreatePost, ApiUpdateComment, etc.
181
189
  */
@@ -285,4 +293,4 @@ type Config = GenerateOptions;
285
293
  declare function defineConfig(config: Config): GenerateOptions;
286
294
  declare function getConfig(): Promise<Config>;
287
295
 
288
- 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, getValidResponseMetadataItems, hasQueryParameter, isRequiredRequestBody, partitionApiModules, readSchema, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformPayloads, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
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 };
package/dist/index.js CHANGED
@@ -20,17 +20,19 @@ import {
20
20
  transformTypeValue,
21
21
  transformUrl,
22
22
  transformVerb
23
- } from "./chunk-K46PCBCF.js";
23
+ } from "./chunk-GMB5TIVL.js";
24
24
  import {
25
25
  createStatusCodesByStrategy,
26
26
  getCliVersion,
27
- getValidResponseMetadataItems,
27
+ getRequestBodyContentType,
28
+ getResponseMetadataItems,
28
29
  hasQueryParameter,
30
+ isRemoteSchema,
29
31
  isRequiredRequestBody,
30
32
  readSchema,
33
+ readSchemaContent,
31
34
  readTemplateFile
32
- } from "./chunk-SKKHIIUE.js";
33
- import "./chunk-6OIOYGN7.js";
35
+ } from "./chunk-PTGO2Y5X.js";
34
36
 
35
37
  // src/index.ts
36
38
  import { default as default2 } from "pluralize";
@@ -42,12 +44,15 @@ export {
42
44
  generateTypes,
43
45
  getCliVersion,
44
46
  getConfig,
45
- getValidResponseMetadataItems,
47
+ getRequestBodyContentType,
48
+ getResponseMetadataItems,
46
49
  hasQueryParameter,
50
+ isRemoteSchema,
47
51
  isRequiredRequestBody,
48
52
  partitionApiModules,
49
53
  default2 as pluralize,
50
54
  readSchema,
55
+ readSchemaContent,
51
56
  readTemplateFile,
52
57
  renderApiModules,
53
58
  transformEntity,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-farmer",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "API module generation tool based on Openapi3/Swagger2.",
5
5
  "keywords": [
6
6
  "cli",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@types/pluralize": "^0.0.33",
52
- "@varlet/axle": "^0.10.1",
52
+ "@varlet/axle": "^0.10.3",
53
53
  "commander": "^13.0.0",
54
54
  "ejs": "^3.1.10",
55
55
  "fs-extra": "^11.2.0",
@@ -59,7 +59,8 @@
59
59
  "rslog": "^1.2.3",
60
60
  "swagger2openapi": "^7.0.8",
61
61
  "unconfig": "^0.6.0",
62
- "yaml": "^2.7.0"
62
+ "yaml": "^2.7.0",
63
+ "prettier": "^3.4.2"
63
64
  },
64
65
  "devDependencies": {
65
66
  "@configurajs/eslint": "^0.1.0",
@@ -71,7 +72,6 @@
71
72
  "@varlet/release": "^0.3.1",
72
73
  "eslint": "^9.17.0",
73
74
  "nano-staged": "0.8.0",
74
- "prettier": "^3.4.2",
75
75
  "rimraf": "^6.0.1",
76
76
  "simple-git-hooks": "^2.11.1",
77
77
  "tsup": "8.3.5",
@@ -4,11 +4,16 @@
4
4
 
5
5
  <% if (!typesOnly) { %>
6
6
  <% apiModule.payloads.forEach(payload => { %> -%>
7
- export const <%- payload.fn %> = (config<% if (ts) { %>: RequestConfig<<%- payload.typeRequestBody %>> <% } %> = {})
8
- => request<% if (ts) { %><any, <%- payload.typeResponseBody %>><% } %>({
7
+ export const <%- payload.fn %> = (config<% if (ts) { %>: RequestConfig<<%- payload.typeQuery %>, <%- payload.typeRequestBody %>> <% } %> = {})
8
+ => request<% if (ts) { %><<%- payload.typeResponseBody %>><% } %>({
9
9
  url: '<%- payload.url %>',
10
10
  method: '<%- payload.method %>',
11
- ...config
11
+ ...config,
12
+ <% if (payload.requestContentType === 'application/x-www-form-urlencoded') { %>headers: {
13
+ 'Content-Type': 'application/x-www-form-urlencoded',
14
+ ...config.headers,
15
+ },
16
+ <% } %>
12
17
  })
13
18
 
14
19
  <% }) %>
@@ -10,9 +10,11 @@ export const <%- payload.fn %> = api
10
10
  <%- payload.typeQuery %>
11
11
  <% } else { %>
12
12
  <%- payload.typeRequestBody %>
13
- <% } %>, <%- payload.typeRequestBody %>>
13
+ <% } %>,
14
+ <%- payload.typeRequestBody %>>
14
15
  <% } %>
15
- ('<%- payload.url %>', '<%- payload.method %>')
16
+ ('<%- payload.url %>',
17
+ <% if (payload.requestContentType === 'application/x-www-form-urlencoded' && payload.method === 'post') { %> 'postUrlEncode'<% } else { %> '<%- payload.method %>' <% } %>)
16
18
 
17
19
  <% }) %>
18
20
  <% } %>