api-farmer 0.0.5 → 0.0.7
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 +1 -0
- package/dist/{chunk-6T5EWOBD.js → chunk-GHW46C2M.js} +12 -8
- package/dist/{chunk-6N4OHGAC.js → chunk-OBPECFFY.js} +10 -7
- package/dist/cli.cjs +16 -11
- package/dist/cli.js +2 -2
- package/dist/{generate-544AKFJX.js → generate-QIKM4YKD.js} +2 -2
- package/dist/index.cjs +20 -13
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +6 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -51,6 +51,7 @@ npx af
|
|
|
51
51
|
|
|
52
52
|
> [!TIP]
|
|
53
53
|
> The generated content does not include the integration of the request client.
|
|
54
|
+
> If you allow ts code output, you will see a custom type called `Res`. This type needs to be defined in `global.d.ts` for use.
|
|
54
55
|
|
|
55
56
|
#### Some Examples
|
|
56
57
|
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CWD,
|
|
3
3
|
createStatusCodesByStrategy,
|
|
4
|
+
getResponseMime,
|
|
4
5
|
hasQueryParameter,
|
|
5
|
-
|
|
6
|
+
isRequiredRequestBody,
|
|
6
7
|
readSchema,
|
|
7
8
|
readTemplateFile
|
|
8
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-OBPECFFY.js";
|
|
9
10
|
import {
|
|
10
11
|
__export
|
|
11
12
|
} from "./chunk-6OIOYGN7.js";
|
|
@@ -22784,8 +22785,8 @@ function transformTypeQueryValue({ type: type2 }) {
|
|
|
22784
22785
|
function transformTypeRequestBody({ verb, entity }) {
|
|
22785
22786
|
return `Api${verb}${entity}RequestBody`;
|
|
22786
22787
|
}
|
|
22787
|
-
function transformTypeRequestBodyValue({ type: type2 }) {
|
|
22788
|
-
return `${type2}['requestBody']['content']['application/json']`;
|
|
22788
|
+
function transformTypeRequestBodyValue({ type: type2, required }) {
|
|
22789
|
+
return required ? `${type2}['requestBody']['content']['application/json']` : `NonNullable<${type2}['requestBody']>['content']['application/json'] | undefined`;
|
|
22789
22790
|
}
|
|
22790
22791
|
function transformTypeResponseBody({ verb, entity }) {
|
|
22791
22792
|
return `Api${verb}${entity}ResponseBody`;
|
|
@@ -22835,11 +22836,14 @@ function partitionApiModules(schema2, transformer, options8) {
|
|
|
22835
22836
|
const typeQuery = transformer.typeQuery({ verb, entity });
|
|
22836
22837
|
const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ type: type2 }) : "never";
|
|
22837
22838
|
const typeRequestBody = transformer.typeRequestBody({ verb, entity });
|
|
22838
|
-
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
22839
|
-
|
|
22839
|
+
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
22840
|
+
type: type2,
|
|
22841
|
+
required: isRequiredRequestBody(operation.requestBody)
|
|
22842
|
+
}) : "never";
|
|
22840
22843
|
const statusCode = statusCodes[method] ?? 200;
|
|
22841
|
-
const mime = operation
|
|
22842
|
-
const
|
|
22844
|
+
const mime = getResponseMime(operation, statusCode);
|
|
22845
|
+
const typeResponseBody = transformer.typeResponseBody({ verb, entity });
|
|
22846
|
+
const typeResponseBodyValue = mime ? transformer.typeResponseBodyValue({ type: type2, statusCode, mime }) : "never";
|
|
22843
22847
|
payloads3.push({
|
|
22844
22848
|
fn,
|
|
22845
22849
|
url: url2,
|
|
@@ -52,14 +52,16 @@ function readTemplateFile(preset = "axle") {
|
|
|
52
52
|
function hasQueryParameter(operation) {
|
|
53
53
|
return (operation.parameters ?? []).some((param) => "in" in param && param.in === "query");
|
|
54
54
|
}
|
|
55
|
-
function hasResponseBody(operation) {
|
|
56
|
-
return Object.values(operation.responses ?? {}).some(
|
|
57
|
-
(responseObject) => "content" in responseObject && responseObject.content
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
55
|
function getCliVersion() {
|
|
61
56
|
return fse.readJsonSync(CLI_PACKAGE_JSON).version;
|
|
62
57
|
}
|
|
58
|
+
function isRequiredRequestBody(value) {
|
|
59
|
+
return "required" in value && value.required === true;
|
|
60
|
+
}
|
|
61
|
+
function getResponseMime(operation, statusCode) {
|
|
62
|
+
const content = operation.responses?.[statusCode]?.content;
|
|
63
|
+
return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
|
|
64
|
+
}
|
|
63
65
|
|
|
64
66
|
export {
|
|
65
67
|
CWD,
|
|
@@ -67,6 +69,7 @@ export {
|
|
|
67
69
|
readSchema,
|
|
68
70
|
readTemplateFile,
|
|
69
71
|
hasQueryParameter,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
+
getCliVersion,
|
|
73
|
+
isRequiredRequestBody,
|
|
74
|
+
getResponseMime
|
|
72
75
|
};
|
package/dist/cli.cjs
CHANGED
|
@@ -93,14 +93,16 @@ function readTemplateFile(preset = "axle") {
|
|
|
93
93
|
function hasQueryParameter(operation) {
|
|
94
94
|
return (operation.parameters ?? []).some((param) => "in" in param && param.in === "query");
|
|
95
95
|
}
|
|
96
|
-
function hasResponseBody(operation) {
|
|
97
|
-
return Object.values(operation.responses ?? {}).some(
|
|
98
|
-
(responseObject) => "content" in responseObject && responseObject.content
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
96
|
function getCliVersion() {
|
|
102
97
|
return import_fs_extra.default.readJsonSync(CLI_PACKAGE_JSON).version;
|
|
103
98
|
}
|
|
99
|
+
function isRequiredRequestBody(value) {
|
|
100
|
+
return "required" in value && value.required === true;
|
|
101
|
+
}
|
|
102
|
+
function getResponseMime(operation, statusCode) {
|
|
103
|
+
const content = operation.responses?.[statusCode]?.content;
|
|
104
|
+
return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
|
|
105
|
+
}
|
|
104
106
|
var import_path2, import_fs_extra, import_swagger2openapi, import_yaml;
|
|
105
107
|
var init_utils = __esm({
|
|
106
108
|
"src/utils.ts"() {
|
|
@@ -102043,8 +102045,8 @@ function transformTypeQueryValue({ type: type2 }) {
|
|
|
102043
102045
|
function transformTypeRequestBody({ verb, entity }) {
|
|
102044
102046
|
return `Api${verb}${entity}RequestBody`;
|
|
102045
102047
|
}
|
|
102046
|
-
function transformTypeRequestBodyValue({ type: type2 }) {
|
|
102047
|
-
return `${type2}['requestBody']['content']['application/json']`;
|
|
102048
|
+
function transformTypeRequestBodyValue({ type: type2, required }) {
|
|
102049
|
+
return required ? `${type2}['requestBody']['content']['application/json']` : `NonNullable<${type2}['requestBody']>['content']['application/json'] | undefined`;
|
|
102048
102050
|
}
|
|
102049
102051
|
function transformTypeResponseBody({ verb, entity }) {
|
|
102050
102052
|
return `Api${verb}${entity}ResponseBody`;
|
|
@@ -102110,11 +102112,14 @@ function partitionApiModules(schema2, transformer, options8) {
|
|
|
102110
102112
|
const typeQuery = transformer.typeQuery({ verb, entity });
|
|
102111
102113
|
const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ type: type2 }) : "never";
|
|
102112
102114
|
const typeRequestBody = transformer.typeRequestBody({ verb, entity });
|
|
102113
|
-
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102114
|
-
|
|
102115
|
+
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102116
|
+
type: type2,
|
|
102117
|
+
required: isRequiredRequestBody(operation.requestBody)
|
|
102118
|
+
}) : "never";
|
|
102115
102119
|
const statusCode = statusCodes[method] ?? 200;
|
|
102116
|
-
const mime = operation
|
|
102117
|
-
const
|
|
102120
|
+
const mime = getResponseMime(operation, statusCode);
|
|
102121
|
+
const typeResponseBody = transformer.typeResponseBody({ verb, entity });
|
|
102122
|
+
const typeResponseBodyValue = mime ? transformer.typeResponseBodyValue({ type: type2, statusCode, mime }) : "never";
|
|
102118
102123
|
payloads3.push({
|
|
102119
102124
|
fn: fn8,
|
|
102120
102125
|
url: url2,
|
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
getCliVersion
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-OBPECFFY.js";
|
|
5
5
|
import "./chunk-6OIOYGN7.js";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
@@ -9,7 +9,7 @@ import { Command } from "commander";
|
|
|
9
9
|
var program = new Command();
|
|
10
10
|
program.version(getCliVersion());
|
|
11
11
|
program.action(async () => {
|
|
12
|
-
const { generate } = await import("./generate-
|
|
12
|
+
const { generate } = await import("./generate-QIKM4YKD.js");
|
|
13
13
|
return generate();
|
|
14
14
|
});
|
|
15
15
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -79232,8 +79232,9 @@ __export(index_exports, {
|
|
|
79232
79232
|
generateTypes: () => generateTypes,
|
|
79233
79233
|
getCliVersion: () => getCliVersion,
|
|
79234
79234
|
getConfig: () => getConfig,
|
|
79235
|
+
getResponseMime: () => getResponseMime,
|
|
79235
79236
|
hasQueryParameter: () => hasQueryParameter,
|
|
79236
|
-
|
|
79237
|
+
isRequiredRequestBody: () => isRequiredRequestBody,
|
|
79237
79238
|
partitionApiModules: () => partitionApiModules,
|
|
79238
79239
|
pluralize: () => import_pluralize2.default,
|
|
79239
79240
|
readSchema: () => readSchema,
|
|
@@ -79308,8 +79309,8 @@ function transformTypeQueryValue({ type: type2 }) {
|
|
|
79308
79309
|
function transformTypeRequestBody({ verb, entity }) {
|
|
79309
79310
|
return `Api${verb}${entity}RequestBody`;
|
|
79310
79311
|
}
|
|
79311
|
-
function transformTypeRequestBodyValue({ type: type2 }) {
|
|
79312
|
-
return `${type2}['requestBody']['content']['application/json']`;
|
|
79312
|
+
function transformTypeRequestBodyValue({ type: type2, required }) {
|
|
79313
|
+
return required ? `${type2}['requestBody']['content']['application/json']` : `NonNullable<${type2}['requestBody']>['content']['application/json'] | undefined`;
|
|
79313
79314
|
}
|
|
79314
79315
|
function transformTypeResponseBody({ verb, entity }) {
|
|
79315
79316
|
return `Api${verb}${entity}ResponseBody`;
|
|
@@ -102118,14 +102119,16 @@ function readTemplateFile(preset = "axle") {
|
|
|
102118
102119
|
function hasQueryParameter(operation) {
|
|
102119
102120
|
return (operation.parameters ?? []).some((param) => "in" in param && param.in === "query");
|
|
102120
102121
|
}
|
|
102121
|
-
function hasResponseBody(operation) {
|
|
102122
|
-
return Object.values(operation.responses ?? {}).some(
|
|
102123
|
-
(responseObject) => "content" in responseObject && responseObject.content
|
|
102124
|
-
);
|
|
102125
|
-
}
|
|
102126
102122
|
function getCliVersion() {
|
|
102127
102123
|
return import_fs_extra.default.readJsonSync(CLI_PACKAGE_JSON).version;
|
|
102128
102124
|
}
|
|
102125
|
+
function isRequiredRequestBody(value) {
|
|
102126
|
+
return "required" in value && value.required === true;
|
|
102127
|
+
}
|
|
102128
|
+
function getResponseMime(operation, statusCode) {
|
|
102129
|
+
const content = operation.responses?.[statusCode]?.content;
|
|
102130
|
+
return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
|
|
102131
|
+
}
|
|
102129
102132
|
|
|
102130
102133
|
// src/generate.ts
|
|
102131
102134
|
function partitionApiModules(schema2, transformer, options8) {
|
|
@@ -102147,11 +102150,14 @@ function partitionApiModules(schema2, transformer, options8) {
|
|
|
102147
102150
|
const typeQuery = transformer.typeQuery({ verb, entity });
|
|
102148
102151
|
const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ type: type2 }) : "never";
|
|
102149
102152
|
const typeRequestBody = transformer.typeRequestBody({ verb, entity });
|
|
102150
|
-
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102151
|
-
|
|
102153
|
+
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102154
|
+
type: type2,
|
|
102155
|
+
required: isRequiredRequestBody(operation.requestBody)
|
|
102156
|
+
}) : "never";
|
|
102152
102157
|
const statusCode = statusCodes[method] ?? 200;
|
|
102153
|
-
const mime = operation
|
|
102154
|
-
const
|
|
102158
|
+
const mime = getResponseMime(operation, statusCode);
|
|
102159
|
+
const typeResponseBody = transformer.typeResponseBody({ verb, entity });
|
|
102160
|
+
const typeResponseBodyValue = mime ? transformer.typeResponseBodyValue({ type: type2, statusCode, mime }) : "never";
|
|
102155
102161
|
payloads3.push({
|
|
102156
102162
|
fn: fn8,
|
|
102157
102163
|
url: url2,
|
|
@@ -102257,8 +102263,9 @@ var import_pluralize2 = __toESM(require("pluralize"), 1);
|
|
|
102257
102263
|
generateTypes,
|
|
102258
102264
|
getCliVersion,
|
|
102259
102265
|
getConfig,
|
|
102266
|
+
getResponseMime,
|
|
102260
102267
|
hasQueryParameter,
|
|
102261
|
-
|
|
102268
|
+
isRequiredRequestBody,
|
|
102262
102269
|
partitionApiModules,
|
|
102263
102270
|
pluralize,
|
|
102264
102271
|
readSchema,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAPI3, OperationObject } from 'openapi-typescript';
|
|
1
|
+
import { OpenAPI3, OperationObject, RequestBodyObject, ReferenceObject } from 'openapi-typescript';
|
|
2
2
|
export { default as pluralize } from 'pluralize';
|
|
3
3
|
|
|
4
4
|
declare function transformModuleName({ name }: {
|
|
@@ -39,8 +39,9 @@ declare function transformTypeRequestBody({ verb, entity }: {
|
|
|
39
39
|
verb: string;
|
|
40
40
|
entity: string;
|
|
41
41
|
}): string;
|
|
42
|
-
declare function transformTypeRequestBodyValue({ type }: {
|
|
42
|
+
declare function transformTypeRequestBodyValue({ type, required }: {
|
|
43
43
|
type: string;
|
|
44
|
+
required: boolean;
|
|
44
45
|
}): string;
|
|
45
46
|
declare function transformTypeResponseBody({ verb, entity }: {
|
|
46
47
|
verb: string;
|
|
@@ -99,8 +100,9 @@ declare function createStatusCodesByStrategy(strategy: StatusCodeStrategy): {
|
|
|
99
100
|
declare function readSchema(input: string): Promise<OpenAPI3>;
|
|
100
101
|
declare function readTemplateFile(preset?: Preset): string;
|
|
101
102
|
declare function hasQueryParameter(operation: OperationObject): boolean;
|
|
102
|
-
declare function hasResponseBody(operation: OperationObject): boolean;
|
|
103
103
|
declare function getCliVersion(): any;
|
|
104
|
+
declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
|
|
105
|
+
declare function getResponseMime(operation: OperationObject, statusCode: number): "application/json" | "*/*" | undefined;
|
|
104
106
|
|
|
105
107
|
interface ApiModuleTemplateData {
|
|
106
108
|
/**
|
|
@@ -249,4 +251,4 @@ type Config = GenerateOptions;
|
|
|
249
251
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
250
252
|
declare function getConfig(): Promise<Config>;
|
|
251
253
|
|
|
252
|
-
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, createStatusCodesByStrategy, createTransformer, defineConfig, generate, generateTypes, getCliVersion, getConfig, hasQueryParameter,
|
|
254
|
+
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, createStatusCodesByStrategy, createTransformer, defineConfig, generate, generateTypes, getCliVersion, getConfig, getResponseMime, hasQueryParameter, isRequiredRequestBody, partitionApiModules, readSchema, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAPI3, OperationObject } from 'openapi-typescript';
|
|
1
|
+
import { OpenAPI3, OperationObject, RequestBodyObject, ReferenceObject } from 'openapi-typescript';
|
|
2
2
|
export { default as pluralize } from 'pluralize';
|
|
3
3
|
|
|
4
4
|
declare function transformModuleName({ name }: {
|
|
@@ -39,8 +39,9 @@ declare function transformTypeRequestBody({ verb, entity }: {
|
|
|
39
39
|
verb: string;
|
|
40
40
|
entity: string;
|
|
41
41
|
}): string;
|
|
42
|
-
declare function transformTypeRequestBodyValue({ type }: {
|
|
42
|
+
declare function transformTypeRequestBodyValue({ type, required }: {
|
|
43
43
|
type: string;
|
|
44
|
+
required: boolean;
|
|
44
45
|
}): string;
|
|
45
46
|
declare function transformTypeResponseBody({ verb, entity }: {
|
|
46
47
|
verb: string;
|
|
@@ -99,8 +100,9 @@ declare function createStatusCodesByStrategy(strategy: StatusCodeStrategy): {
|
|
|
99
100
|
declare function readSchema(input: string): Promise<OpenAPI3>;
|
|
100
101
|
declare function readTemplateFile(preset?: Preset): string;
|
|
101
102
|
declare function hasQueryParameter(operation: OperationObject): boolean;
|
|
102
|
-
declare function hasResponseBody(operation: OperationObject): boolean;
|
|
103
103
|
declare function getCliVersion(): any;
|
|
104
|
+
declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
|
|
105
|
+
declare function getResponseMime(operation: OperationObject, statusCode: number): "application/json" | "*/*" | undefined;
|
|
104
106
|
|
|
105
107
|
interface ApiModuleTemplateData {
|
|
106
108
|
/**
|
|
@@ -249,4 +251,4 @@ type Config = GenerateOptions;
|
|
|
249
251
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
250
252
|
declare function getConfig(): Promise<Config>;
|
|
251
253
|
|
|
252
|
-
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, createStatusCodesByStrategy, createTransformer, defineConfig, generate, generateTypes, getCliVersion, getConfig, hasQueryParameter,
|
|
254
|
+
export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, createStatusCodesByStrategy, createTransformer, defineConfig, generate, generateTypes, getCliVersion, getConfig, getResponseMime, hasQueryParameter, isRequiredRequestBody, partitionApiModules, readSchema, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
package/dist/index.js
CHANGED
|
@@ -19,15 +19,16 @@ import {
|
|
|
19
19
|
transformTypeValue,
|
|
20
20
|
transformUrl,
|
|
21
21
|
transformVerb
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-GHW46C2M.js";
|
|
23
23
|
import {
|
|
24
24
|
createStatusCodesByStrategy,
|
|
25
25
|
getCliVersion,
|
|
26
|
+
getResponseMime,
|
|
26
27
|
hasQueryParameter,
|
|
27
|
-
|
|
28
|
+
isRequiredRequestBody,
|
|
28
29
|
readSchema,
|
|
29
30
|
readTemplateFile
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-OBPECFFY.js";
|
|
31
32
|
import "./chunk-6OIOYGN7.js";
|
|
32
33
|
|
|
33
34
|
// src/index.ts
|
|
@@ -40,8 +41,9 @@ export {
|
|
|
40
41
|
generateTypes,
|
|
41
42
|
getCliVersion,
|
|
42
43
|
getConfig,
|
|
44
|
+
getResponseMime,
|
|
43
45
|
hasQueryParameter,
|
|
44
|
-
|
|
46
|
+
isRequiredRequestBody,
|
|
45
47
|
partitionApiModules,
|
|
46
48
|
default2 as pluralize,
|
|
47
49
|
readSchema,
|