api-farmer 0.0.5 → 0.0.6
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/{chunk-6T5EWOBD.js → chunk-BGSEKRRW.js} +12 -7
- package/dist/{chunk-6N4OHGAC.js → chunk-TOPFUKIL.js} +10 -1
- package/dist/cli.cjs +16 -6
- package/dist/cli.js +2 -2
- package/dist/{generate-544AKFJX.js → generate-45FVXFDO.js} +2 -2
- package/dist/index.cjs +20 -6
- package/dist/index.d.cts +6 -3
- package/dist/index.d.ts +6 -3
- package/dist/index.js +6 -2
- package/package.json +1 -1
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CWD,
|
|
3
3
|
createStatusCodesByStrategy,
|
|
4
|
+
getResponseMime,
|
|
4
5
|
hasQueryParameter,
|
|
5
6
|
hasResponseBody,
|
|
7
|
+
isRequiredRequestBody,
|
|
6
8
|
readSchema,
|
|
7
9
|
readTemplateFile
|
|
8
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TOPFUKIL.js";
|
|
9
11
|
import {
|
|
10
12
|
__export
|
|
11
13
|
} from "./chunk-6OIOYGN7.js";
|
|
@@ -22784,8 +22786,8 @@ function transformTypeQueryValue({ type: type2 }) {
|
|
|
22784
22786
|
function transformTypeRequestBody({ verb, entity }) {
|
|
22785
22787
|
return `Api${verb}${entity}RequestBody`;
|
|
22786
22788
|
}
|
|
22787
|
-
function transformTypeRequestBodyValue({ type: type2 }) {
|
|
22788
|
-
return `${type2}['requestBody']['content']['application/json']`;
|
|
22789
|
+
function transformTypeRequestBodyValue({ type: type2, required }) {
|
|
22790
|
+
return required ? `${type2}['requestBody']['content']['application/json']` : `NonNullable<${type2}['requestBody']>['content']['application/json'] | undefined`;
|
|
22789
22791
|
}
|
|
22790
22792
|
function transformTypeResponseBody({ verb, entity }) {
|
|
22791
22793
|
return `Api${verb}${entity}ResponseBody`;
|
|
@@ -22835,11 +22837,14 @@ function partitionApiModules(schema2, transformer, options8) {
|
|
|
22835
22837
|
const typeQuery = transformer.typeQuery({ verb, entity });
|
|
22836
22838
|
const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ type: type2 }) : "never";
|
|
22837
22839
|
const typeRequestBody = transformer.typeRequestBody({ verb, entity });
|
|
22838
|
-
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
22839
|
-
|
|
22840
|
+
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
22841
|
+
type: type2,
|
|
22842
|
+
required: isRequiredRequestBody(operation.requestBody)
|
|
22843
|
+
}) : "never";
|
|
22840
22844
|
const statusCode = statusCodes[method] ?? 200;
|
|
22841
|
-
const mime = operation
|
|
22842
|
-
const
|
|
22845
|
+
const mime = getResponseMime(operation, statusCode);
|
|
22846
|
+
const typeResponseBody = transformer.typeResponseBody({ verb, entity });
|
|
22847
|
+
const typeResponseBodyValue = hasResponseBody(operation) && mime ? transformer.typeResponseBodyValue({ type: type2, statusCode, mime }) : "never";
|
|
22843
22848
|
payloads3.push({
|
|
22844
22849
|
fn,
|
|
22845
22850
|
url: url2,
|
|
@@ -60,6 +60,13 @@ function hasResponseBody(operation) {
|
|
|
60
60
|
function getCliVersion() {
|
|
61
61
|
return fse.readJsonSync(CLI_PACKAGE_JSON).version;
|
|
62
62
|
}
|
|
63
|
+
function isRequiredRequestBody(value) {
|
|
64
|
+
return "required" in value && value.required === true;
|
|
65
|
+
}
|
|
66
|
+
function getResponseMime(operation, statusCode) {
|
|
67
|
+
const content = operation.responses?.[statusCode]?.content;
|
|
68
|
+
return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
|
|
69
|
+
}
|
|
63
70
|
|
|
64
71
|
export {
|
|
65
72
|
CWD,
|
|
@@ -68,5 +75,7 @@ export {
|
|
|
68
75
|
readTemplateFile,
|
|
69
76
|
hasQueryParameter,
|
|
70
77
|
hasResponseBody,
|
|
71
|
-
getCliVersion
|
|
78
|
+
getCliVersion,
|
|
79
|
+
isRequiredRequestBody,
|
|
80
|
+
getResponseMime
|
|
72
81
|
};
|
package/dist/cli.cjs
CHANGED
|
@@ -101,6 +101,13 @@ function hasResponseBody(operation) {
|
|
|
101
101
|
function getCliVersion() {
|
|
102
102
|
return import_fs_extra.default.readJsonSync(CLI_PACKAGE_JSON).version;
|
|
103
103
|
}
|
|
104
|
+
function isRequiredRequestBody(value) {
|
|
105
|
+
return "required" in value && value.required === true;
|
|
106
|
+
}
|
|
107
|
+
function getResponseMime(operation, statusCode) {
|
|
108
|
+
const content = operation.responses?.[statusCode]?.content;
|
|
109
|
+
return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
|
|
110
|
+
}
|
|
104
111
|
var import_path2, import_fs_extra, import_swagger2openapi, import_yaml;
|
|
105
112
|
var init_utils = __esm({
|
|
106
113
|
"src/utils.ts"() {
|
|
@@ -102043,8 +102050,8 @@ function transformTypeQueryValue({ type: type2 }) {
|
|
|
102043
102050
|
function transformTypeRequestBody({ verb, entity }) {
|
|
102044
102051
|
return `Api${verb}${entity}RequestBody`;
|
|
102045
102052
|
}
|
|
102046
|
-
function transformTypeRequestBodyValue({ type: type2 }) {
|
|
102047
|
-
return `${type2}['requestBody']['content']['application/json']`;
|
|
102053
|
+
function transformTypeRequestBodyValue({ type: type2, required }) {
|
|
102054
|
+
return required ? `${type2}['requestBody']['content']['application/json']` : `NonNullable<${type2}['requestBody']>['content']['application/json'] | undefined`;
|
|
102048
102055
|
}
|
|
102049
102056
|
function transformTypeResponseBody({ verb, entity }) {
|
|
102050
102057
|
return `Api${verb}${entity}ResponseBody`;
|
|
@@ -102110,11 +102117,14 @@ function partitionApiModules(schema2, transformer, options8) {
|
|
|
102110
102117
|
const typeQuery = transformer.typeQuery({ verb, entity });
|
|
102111
102118
|
const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ type: type2 }) : "never";
|
|
102112
102119
|
const typeRequestBody = transformer.typeRequestBody({ verb, entity });
|
|
102113
|
-
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102114
|
-
|
|
102120
|
+
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102121
|
+
type: type2,
|
|
102122
|
+
required: isRequiredRequestBody(operation.requestBody)
|
|
102123
|
+
}) : "never";
|
|
102115
102124
|
const statusCode = statusCodes[method] ?? 200;
|
|
102116
|
-
const mime = operation
|
|
102117
|
-
const
|
|
102125
|
+
const mime = getResponseMime(operation, statusCode);
|
|
102126
|
+
const typeResponseBody = transformer.typeResponseBody({ verb, entity });
|
|
102127
|
+
const typeResponseBodyValue = hasResponseBody(operation) && mime ? transformer.typeResponseBodyValue({ type: type2, statusCode, mime }) : "never";
|
|
102118
102128
|
payloads3.push({
|
|
102119
102129
|
fn: fn8,
|
|
102120
102130
|
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-TOPFUKIL.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-45FVXFDO.js");
|
|
13
13
|
return generate();
|
|
14
14
|
});
|
|
15
15
|
program.parse();
|
package/dist/index.cjs
CHANGED
|
@@ -79232,8 +79232,10 @@ __export(index_exports, {
|
|
|
79232
79232
|
generateTypes: () => generateTypes,
|
|
79233
79233
|
getCliVersion: () => getCliVersion,
|
|
79234
79234
|
getConfig: () => getConfig,
|
|
79235
|
+
getResponseMime: () => getResponseMime,
|
|
79235
79236
|
hasQueryParameter: () => hasQueryParameter,
|
|
79236
79237
|
hasResponseBody: () => hasResponseBody,
|
|
79238
|
+
isRequiredRequestBody: () => isRequiredRequestBody,
|
|
79237
79239
|
partitionApiModules: () => partitionApiModules,
|
|
79238
79240
|
pluralize: () => import_pluralize2.default,
|
|
79239
79241
|
readSchema: () => readSchema,
|
|
@@ -79308,8 +79310,8 @@ function transformTypeQueryValue({ type: type2 }) {
|
|
|
79308
79310
|
function transformTypeRequestBody({ verb, entity }) {
|
|
79309
79311
|
return `Api${verb}${entity}RequestBody`;
|
|
79310
79312
|
}
|
|
79311
|
-
function transformTypeRequestBodyValue({ type: type2 }) {
|
|
79312
|
-
return `${type2}['requestBody']['content']['application/json']`;
|
|
79313
|
+
function transformTypeRequestBodyValue({ type: type2, required }) {
|
|
79314
|
+
return required ? `${type2}['requestBody']['content']['application/json']` : `NonNullable<${type2}['requestBody']>['content']['application/json'] | undefined`;
|
|
79313
79315
|
}
|
|
79314
79316
|
function transformTypeResponseBody({ verb, entity }) {
|
|
79315
79317
|
return `Api${verb}${entity}ResponseBody`;
|
|
@@ -102126,6 +102128,13 @@ function hasResponseBody(operation) {
|
|
|
102126
102128
|
function getCliVersion() {
|
|
102127
102129
|
return import_fs_extra.default.readJsonSync(CLI_PACKAGE_JSON).version;
|
|
102128
102130
|
}
|
|
102131
|
+
function isRequiredRequestBody(value) {
|
|
102132
|
+
return "required" in value && value.required === true;
|
|
102133
|
+
}
|
|
102134
|
+
function getResponseMime(operation, statusCode) {
|
|
102135
|
+
const content = operation.responses?.[statusCode]?.content;
|
|
102136
|
+
return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
|
|
102137
|
+
}
|
|
102129
102138
|
|
|
102130
102139
|
// src/generate.ts
|
|
102131
102140
|
function partitionApiModules(schema2, transformer, options8) {
|
|
@@ -102147,11 +102156,14 @@ function partitionApiModules(schema2, transformer, options8) {
|
|
|
102147
102156
|
const typeQuery = transformer.typeQuery({ verb, entity });
|
|
102148
102157
|
const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ type: type2 }) : "never";
|
|
102149
102158
|
const typeRequestBody = transformer.typeRequestBody({ verb, entity });
|
|
102150
|
-
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102151
|
-
|
|
102159
|
+
const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
|
|
102160
|
+
type: type2,
|
|
102161
|
+
required: isRequiredRequestBody(operation.requestBody)
|
|
102162
|
+
}) : "never";
|
|
102152
102163
|
const statusCode = statusCodes[method] ?? 200;
|
|
102153
|
-
const mime = operation
|
|
102154
|
-
const
|
|
102164
|
+
const mime = getResponseMime(operation, statusCode);
|
|
102165
|
+
const typeResponseBody = transformer.typeResponseBody({ verb, entity });
|
|
102166
|
+
const typeResponseBodyValue = hasResponseBody(operation) && mime ? transformer.typeResponseBodyValue({ type: type2, statusCode, mime }) : "never";
|
|
102155
102167
|
payloads3.push({
|
|
102156
102168
|
fn: fn8,
|
|
102157
102169
|
url: url2,
|
|
@@ -102257,8 +102269,10 @@ var import_pluralize2 = __toESM(require("pluralize"), 1);
|
|
|
102257
102269
|
generateTypes,
|
|
102258
102270
|
getCliVersion,
|
|
102259
102271
|
getConfig,
|
|
102272
|
+
getResponseMime,
|
|
102260
102273
|
hasQueryParameter,
|
|
102261
102274
|
hasResponseBody,
|
|
102275
|
+
isRequiredRequestBody,
|
|
102262
102276
|
partitionApiModules,
|
|
102263
102277
|
pluralize,
|
|
102264
102278
|
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;
|
|
@@ -101,6 +102,8 @@ declare function readTemplateFile(preset?: Preset): string;
|
|
|
101
102
|
declare function hasQueryParameter(operation: OperationObject): boolean;
|
|
102
103
|
declare function hasResponseBody(operation: OperationObject): boolean;
|
|
103
104
|
declare function getCliVersion(): any;
|
|
105
|
+
declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
|
|
106
|
+
declare function getResponseMime(operation: OperationObject, statusCode: number): "application/json" | "*/*" | undefined;
|
|
104
107
|
|
|
105
108
|
interface ApiModuleTemplateData {
|
|
106
109
|
/**
|
|
@@ -249,4 +252,4 @@ type Config = GenerateOptions;
|
|
|
249
252
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
250
253
|
declare function getConfig(): Promise<Config>;
|
|
251
254
|
|
|
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, hasResponseBody, partitionApiModules, readSchema, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
|
255
|
+
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, hasResponseBody, 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;
|
|
@@ -101,6 +102,8 @@ declare function readTemplateFile(preset?: Preset): string;
|
|
|
101
102
|
declare function hasQueryParameter(operation: OperationObject): boolean;
|
|
102
103
|
declare function hasResponseBody(operation: OperationObject): boolean;
|
|
103
104
|
declare function getCliVersion(): any;
|
|
105
|
+
declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
|
|
106
|
+
declare function getResponseMime(operation: OperationObject, statusCode: number): "application/json" | "*/*" | undefined;
|
|
104
107
|
|
|
105
108
|
interface ApiModuleTemplateData {
|
|
106
109
|
/**
|
|
@@ -249,4 +252,4 @@ type Config = GenerateOptions;
|
|
|
249
252
|
declare function defineConfig(config: Config): GenerateOptions;
|
|
250
253
|
declare function getConfig(): Promise<Config>;
|
|
251
254
|
|
|
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, hasResponseBody, partitionApiModules, readSchema, readTemplateFile, renderApiModules, transformEntity, transformFn, transformModuleName, transformType, transformTypeQuery, transformTypeQueryValue, transformTypeRequestBody, transformTypeRequestBodyValue, transformTypeResponseBody, transformTypeResponseBodyValue, transformTypeValue, transformUrl, transformVerb };
|
|
255
|
+
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, hasResponseBody, 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,17 @@ import {
|
|
|
19
19
|
transformTypeValue,
|
|
20
20
|
transformUrl,
|
|
21
21
|
transformVerb
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-BGSEKRRW.js";
|
|
23
23
|
import {
|
|
24
24
|
createStatusCodesByStrategy,
|
|
25
25
|
getCliVersion,
|
|
26
|
+
getResponseMime,
|
|
26
27
|
hasQueryParameter,
|
|
27
28
|
hasResponseBody,
|
|
29
|
+
isRequiredRequestBody,
|
|
28
30
|
readSchema,
|
|
29
31
|
readTemplateFile
|
|
30
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-TOPFUKIL.js";
|
|
31
33
|
import "./chunk-6OIOYGN7.js";
|
|
32
34
|
|
|
33
35
|
// src/index.ts
|
|
@@ -40,8 +42,10 @@ export {
|
|
|
40
42
|
generateTypes,
|
|
41
43
|
getCliVersion,
|
|
42
44
|
getConfig,
|
|
45
|
+
getResponseMime,
|
|
43
46
|
hasQueryParameter,
|
|
44
47
|
hasResponseBody,
|
|
48
|
+
isRequiredRequestBody,
|
|
45
49
|
partitionApiModules,
|
|
46
50
|
default2 as pluralize,
|
|
47
51
|
readSchema,
|