api-farmer 0.0.9 → 0.0.10

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
@@ -69,15 +69,17 @@ See the bottom of the document for template variable definitions.
69
69
 
70
70
  ### Status Code Strategy
71
71
 
72
- `Restful API` recommends using different successful http status codes for different methods, such as `get: 200`, `post: 201`, etc. If you don't need this strategy, you can set `statusCodeStrategy` to `loose`
72
+ `smart`: find a valid status code between [`200`, `299`] that is closest to `200` <br>
73
+ `loose`: all success status codes are `200` <br>
74
+ `strict`: `Restful API` recommends using different successful http status codes for different methods, such as `get: 200`, `post: 201`, etc. <br>
73
75
 
74
76
  ```ts
75
77
  // api-farmer.config.ts
76
78
  import { defineConfig } from 'api-farmer'
77
79
 
78
80
  export default defineConfig({
79
- // 'strict' or 'loose', defaults 'strict'
80
- statusCodeStrategy: 'loose',
81
+ // 'strict' or 'loose' or 'smart', defaults 'smart'
82
+ statusCodeStrategy: 'strict',
81
83
  })
82
84
  ```
83
85
 
@@ -149,7 +151,9 @@ export interface Config {
149
151
  preset?: Preset
150
152
  /**
151
153
  * The status code strategy to use.
152
- * loose: all success status codes are 200, strict: use the openapi recommended success status codes.
154
+ * loose: all success status codes are 200,
155
+ * strict: use the openapi recommended success status codes.
156
+ * smart: find a valid status code between [200, 299] that is closest to 200
153
157
  */
154
158
  statusCodeStrategy?: StatusCodeStrategy
155
159
  /**
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  CWD,
3
3
  createStatusCodesByStrategy,
4
- getResponseMime,
4
+ doStatusCodeStrategy,
5
5
  hasQueryParameter,
6
6
  isRequiredRequestBody,
7
7
  readSchema,
8
8
  readTemplateFile
9
- } from "./chunk-OBPECFFY.js";
9
+ } from "./chunk-THTMWQYI.js";
10
10
  import {
11
11
  __export
12
12
  } from "./chunk-6OIOYGN7.js";
@@ -22827,7 +22827,7 @@ function createTransformer() {
22827
22827
 
22828
22828
  // src/generate.ts
22829
22829
  function partitionApiModules(schema2, transformer, options8) {
22830
- const { statusCodes, base } = options8;
22830
+ const { statusCodes, statusCodeStrategy, base } = options8;
22831
22831
  const schemaPaths = schema2.paths ?? {};
22832
22832
  const schemaPathKeys = base ? Object.keys(schemaPaths).map((key2) => key2.replace(base, "")) : Object.keys(schemaPaths);
22833
22833
  const keyToPaths = groupBy(schemaPathKeys, (key2) => key2.split("/")[1]);
@@ -22853,10 +22853,13 @@ function partitionApiModules(schema2, transformer, options8) {
22853
22853
  entity,
22854
22854
  required: isRequiredRequestBody(operation.requestBody)
22855
22855
  }) : "never";
22856
- const statusCode = statusCodes[method] ?? 200;
22857
- const mime = getResponseMime(operation, statusCode);
22856
+ const { mime, statusCode } = doStatusCodeStrategy(
22857
+ operation,
22858
+ statusCodes[method] ?? 200,
22859
+ statusCodeStrategy
22860
+ );
22858
22861
  const typeResponseBody = transformer.typeResponseBody({ ...args, type: type2, verb, entity });
22859
- const typeResponseBodyValue = mime ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
22862
+ const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
22860
22863
  payloads3.push({
22861
22864
  fn,
22862
22865
  url: url2,
@@ -22930,7 +22933,7 @@ async function generate(userOptions = {}) {
22930
22933
  ts = true,
22931
22934
  overrides = true,
22932
22935
  preset = "axle",
22933
- statusCodeStrategy = "strict",
22936
+ statusCodeStrategy = "smart",
22934
22937
  input = "./schema.json",
22935
22938
  output = "./src/apis",
22936
22939
  typesFilename = "types.generated.ts",
@@ -22946,7 +22949,7 @@ async function generate(userOptions = {}) {
22946
22949
  if (ts) {
22947
22950
  await generateTypes(schema2, output, typesFilename);
22948
22951
  }
22949
- const apiModules = partitionApiModules(schema2, mergedTransformer, { statusCodes, ts, base });
22952
+ const apiModules = partitionApiModules(schema2, mergedTransformer, { statusCodes, statusCodeStrategy, ts, base });
22950
22953
  await renderApiModules(apiModules, { output, typesFilename, ts, overrides, preset });
22951
22954
  logger.success("Done");
22952
22955
  }
@@ -32,6 +32,15 @@ function createStatusCodesByStrategy(strategy) {
32
32
  patch: 200,
33
33
  options: 200,
34
34
  head: 200
35
+ },
36
+ smart: {
37
+ get: 200,
38
+ post: 200,
39
+ put: 200,
40
+ delete: 200,
41
+ patch: 200,
42
+ options: 200,
43
+ head: 200
35
44
  }
36
45
  }[strategy];
37
46
  }
@@ -58,9 +67,24 @@ function getCliVersion() {
58
67
  function isRequiredRequestBody(value) {
59
68
  return "required" in value && value.required === true;
60
69
  }
61
- function getResponseMime(operation, statusCode) {
70
+ function doStatusCodeStrategy(operation, statusCode, strategy) {
71
+ if (strategy === "smart") {
72
+ const responses = operation.responses ?? {};
73
+ const codeKey = Object.keys(responses).sort((a, b) => Number(a) - Number(b)).find((codeKey2) => Number(codeKey2) >= statusCode && Number(codeKey2) <= 299);
74
+ if (!codeKey) {
75
+ return {
76
+ statusCode: void 0,
77
+ mime: void 0
78
+ };
79
+ }
80
+ statusCode = Number(codeKey);
81
+ }
62
82
  const content = operation.responses?.[statusCode]?.content;
63
- return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
83
+ const mime = content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
84
+ return {
85
+ statusCode,
86
+ mime
87
+ };
64
88
  }
65
89
 
66
90
  export {
@@ -71,5 +95,5 @@ export {
71
95
  hasQueryParameter,
72
96
  getCliVersion,
73
97
  isRequiredRequestBody,
74
- getResponseMime
98
+ doStatusCodeStrategy
75
99
  };
package/dist/cli.cjs CHANGED
@@ -73,6 +73,15 @@ function createStatusCodesByStrategy(strategy) {
73
73
  patch: 200,
74
74
  options: 200,
75
75
  head: 200
76
+ },
77
+ smart: {
78
+ get: 200,
79
+ post: 200,
80
+ put: 200,
81
+ delete: 200,
82
+ patch: 200,
83
+ options: 200,
84
+ head: 200
76
85
  }
77
86
  }[strategy];
78
87
  }
@@ -99,9 +108,24 @@ function getCliVersion() {
99
108
  function isRequiredRequestBody(value) {
100
109
  return "required" in value && value.required === true;
101
110
  }
102
- function getResponseMime(operation, statusCode) {
111
+ function doStatusCodeStrategy(operation, statusCode, strategy) {
112
+ if (strategy === "smart") {
113
+ const responses = operation.responses ?? {};
114
+ const codeKey = Object.keys(responses).sort((a5, b8) => Number(a5) - Number(b8)).find((codeKey2) => Number(codeKey2) >= statusCode && Number(codeKey2) <= 299);
115
+ if (!codeKey) {
116
+ return {
117
+ statusCode: void 0,
118
+ mime: void 0
119
+ };
120
+ }
121
+ statusCode = Number(codeKey);
122
+ }
103
123
  const content = operation.responses?.[statusCode]?.content;
104
- return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
124
+ const mime = content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
125
+ return {
126
+ statusCode,
127
+ mime
128
+ };
105
129
  }
106
130
  var import_path2, import_fs_extra, import_swagger2openapi, import_yaml;
107
131
  var init_utils = __esm({
@@ -102103,7 +102127,7 @@ __export(generate_exports, {
102103
102127
  renderApiModules: () => renderApiModules
102104
102128
  });
102105
102129
  function partitionApiModules(schema2, transformer, options8) {
102106
- const { statusCodes, base } = options8;
102130
+ const { statusCodes, statusCodeStrategy, base } = options8;
102107
102131
  const schemaPaths = schema2.paths ?? {};
102108
102132
  const schemaPathKeys = base ? Object.keys(schemaPaths).map((key2) => key2.replace(base, "")) : Object.keys(schemaPaths);
102109
102133
  const keyToPaths = (0, import_rattail2.groupBy)(schemaPathKeys, (key2) => key2.split("/")[1]);
@@ -102129,10 +102153,13 @@ function partitionApiModules(schema2, transformer, options8) {
102129
102153
  entity,
102130
102154
  required: isRequiredRequestBody(operation.requestBody)
102131
102155
  }) : "never";
102132
- const statusCode = statusCodes[method] ?? 200;
102133
- const mime = getResponseMime(operation, statusCode);
102156
+ const { mime, statusCode } = doStatusCodeStrategy(
102157
+ operation,
102158
+ statusCodes[method] ?? 200,
102159
+ statusCodeStrategy
102160
+ );
102134
102161
  const typeResponseBody = transformer.typeResponseBody({ ...args, type: type2, verb, entity });
102135
- const typeResponseBodyValue = mime ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
102162
+ const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
102136
102163
  payloads3.push({
102137
102164
  fn: fn8,
102138
102165
  url: url2,
@@ -102206,7 +102233,7 @@ async function generate(userOptions = {}) {
102206
102233
  ts: ts9 = true,
102207
102234
  overrides = true,
102208
102235
  preset = "axle",
102209
- statusCodeStrategy = "strict",
102236
+ statusCodeStrategy = "smart",
102210
102237
  input = "./schema.json",
102211
102238
  output = "./src/apis",
102212
102239
  typesFilename = "types.generated.ts",
@@ -102222,7 +102249,7 @@ async function generate(userOptions = {}) {
102222
102249
  if (ts9) {
102223
102250
  await generateTypes(schema2, output, typesFilename);
102224
102251
  }
102225
- const apiModules = partitionApiModules(schema2, mergedTransformer, { statusCodes, ts: ts9, base });
102252
+ const apiModules = partitionApiModules(schema2, mergedTransformer, { statusCodes, statusCodeStrategy, ts: ts9, base });
102226
102253
  await renderApiModules(apiModules, { output, typesFilename, ts: ts9, overrides, preset });
102227
102254
  import_rslog.logger.success("Done");
102228
102255
  }
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  getCliVersion
4
- } from "./chunk-OBPECFFY.js";
4
+ } from "./chunk-THTMWQYI.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-KEVAHIZH.js");
12
+ const { generate } = await import("./generate-A4HBYHRZ.js");
13
13
  return generate();
14
14
  });
15
15
  program.parse();
@@ -3,8 +3,8 @@ import {
3
3
  generateTypes,
4
4
  partitionApiModules,
5
5
  renderApiModules
6
- } from "./chunk-ZOF4QGMP.js";
7
- import "./chunk-OBPECFFY.js";
6
+ } from "./chunk-I24WWW5F.js";
7
+ import "./chunk-THTMWQYI.js";
8
8
  import "./chunk-6OIOYGN7.js";
9
9
  export {
10
10
  generate,
package/dist/index.cjs CHANGED
@@ -79228,11 +79228,11 @@ __export(index_exports, {
79228
79228
  createStatusCodesByStrategy: () => createStatusCodesByStrategy,
79229
79229
  createTransformer: () => createTransformer,
79230
79230
  defineConfig: () => defineConfig,
79231
+ doStatusCodeStrategy: () => doStatusCodeStrategy,
79231
79232
  generate: () => generate,
79232
79233
  generateTypes: () => generateTypes,
79233
79234
  getCliVersion: () => getCliVersion,
79234
79235
  getConfig: () => getConfig,
79235
- getResponseMime: () => getResponseMime,
79236
79236
  hasQueryParameter: () => hasQueryParameter,
79237
79237
  isRequiredRequestBody: () => isRequiredRequestBody,
79238
79238
  partitionApiModules: () => partitionApiModules,
@@ -102108,6 +102108,15 @@ function createStatusCodesByStrategy(strategy) {
102108
102108
  patch: 200,
102109
102109
  options: 200,
102110
102110
  head: 200
102111
+ },
102112
+ smart: {
102113
+ get: 200,
102114
+ post: 200,
102115
+ put: 200,
102116
+ delete: 200,
102117
+ patch: 200,
102118
+ options: 200,
102119
+ head: 200
102111
102120
  }
102112
102121
  }[strategy];
102113
102122
  }
@@ -102134,14 +102143,29 @@ function getCliVersion() {
102134
102143
  function isRequiredRequestBody(value) {
102135
102144
  return "required" in value && value.required === true;
102136
102145
  }
102137
- function getResponseMime(operation, statusCode) {
102146
+ function doStatusCodeStrategy(operation, statusCode, strategy) {
102147
+ if (strategy === "smart") {
102148
+ const responses = operation.responses ?? {};
102149
+ const codeKey = Object.keys(responses).sort((a5, b8) => Number(a5) - Number(b8)).find((codeKey2) => Number(codeKey2) >= statusCode && Number(codeKey2) <= 299);
102150
+ if (!codeKey) {
102151
+ return {
102152
+ statusCode: void 0,
102153
+ mime: void 0
102154
+ };
102155
+ }
102156
+ statusCode = Number(codeKey);
102157
+ }
102138
102158
  const content = operation.responses?.[statusCode]?.content;
102139
- return content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
102159
+ const mime = content?.["application/json"] ? "application/json" : content?.["*/*"] ? "*/*" : void 0;
102160
+ return {
102161
+ statusCode,
102162
+ mime
102163
+ };
102140
102164
  }
102141
102165
 
102142
102166
  // src/generate.ts
102143
102167
  function partitionApiModules(schema2, transformer, options8) {
102144
- const { statusCodes, base } = options8;
102168
+ const { statusCodes, statusCodeStrategy, base } = options8;
102145
102169
  const schemaPaths = schema2.paths ?? {};
102146
102170
  const schemaPathKeys = base ? Object.keys(schemaPaths).map((key2) => key2.replace(base, "")) : Object.keys(schemaPaths);
102147
102171
  const keyToPaths = (0, import_rattail2.groupBy)(schemaPathKeys, (key2) => key2.split("/")[1]);
@@ -102167,10 +102191,13 @@ function partitionApiModules(schema2, transformer, options8) {
102167
102191
  entity,
102168
102192
  required: isRequiredRequestBody(operation.requestBody)
102169
102193
  }) : "never";
102170
- const statusCode = statusCodes[method] ?? 200;
102171
- const mime = getResponseMime(operation, statusCode);
102194
+ const { mime, statusCode } = doStatusCodeStrategy(
102195
+ operation,
102196
+ statusCodes[method] ?? 200,
102197
+ statusCodeStrategy
102198
+ );
102172
102199
  const typeResponseBody = transformer.typeResponseBody({ ...args, type: type2, verb, entity });
102173
- const typeResponseBodyValue = mime ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
102200
+ const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
102174
102201
  payloads3.push({
102175
102202
  fn: fn8,
102176
102203
  url: url2,
@@ -102244,7 +102271,7 @@ async function generate(userOptions = {}) {
102244
102271
  ts: ts9 = true,
102245
102272
  overrides = true,
102246
102273
  preset = "axle",
102247
- statusCodeStrategy = "strict",
102274
+ statusCodeStrategy = "smart",
102248
102275
  input = "./schema.json",
102249
102276
  output = "./src/apis",
102250
102277
  typesFilename = "types.generated.ts",
@@ -102260,7 +102287,7 @@ async function generate(userOptions = {}) {
102260
102287
  if (ts9) {
102261
102288
  await generateTypes(schema2, output, typesFilename);
102262
102289
  }
102263
- const apiModules = partitionApiModules(schema2, mergedTransformer, { statusCodes, ts: ts9, base });
102290
+ const apiModules = partitionApiModules(schema2, mergedTransformer, { statusCodes, statusCodeStrategy, ts: ts9, base });
102264
102291
  await renderApiModules(apiModules, { output, typesFilename, ts: ts9, overrides, preset });
102265
102292
  import_rslog.logger.success("Done");
102266
102293
  }
@@ -102272,11 +102299,11 @@ var import_pluralize2 = __toESM(require("pluralize"), 1);
102272
102299
  createStatusCodesByStrategy,
102273
102300
  createTransformer,
102274
102301
  defineConfig,
102302
+ doStatusCodeStrategy,
102275
102303
  generate,
102276
102304
  generateTypes,
102277
102305
  getCliVersion,
102278
102306
  getConfig,
102279
- getResponseMime,
102280
102307
  hasQueryParameter,
102281
102308
  isRequiredRequestBody,
102282
102309
  partitionApiModules,
package/dist/index.d.cts CHANGED
@@ -82,7 +82,7 @@ interface Transformer {
82
82
  declare function createTransformer(): Transformer;
83
83
 
84
84
  type Preset = 'axle' | 'axios';
85
- type StatusCodeStrategy = 'strict' | 'loose';
85
+ type StatusCodeStrategy = 'strict' | 'loose' | 'smart';
86
86
  interface StatusCodes {
87
87
  get?: number;
88
88
  post?: number;
@@ -108,13 +108,27 @@ declare function createStatusCodesByStrategy(strategy: StatusCodeStrategy): {
108
108
  patch: number;
109
109
  options: number;
110
110
  head: number;
111
+ } | {
112
+ get: number;
113
+ post: number;
114
+ put: number;
115
+ delete: number;
116
+ patch: number;
117
+ options: number;
118
+ head: number;
111
119
  };
112
120
  declare function readSchema(input: string): Promise<OpenAPI3>;
113
121
  declare function readTemplateFile(preset?: Preset): string;
114
122
  declare function hasQueryParameter(operation: OperationObject): boolean;
115
123
  declare function getCliVersion(): any;
116
124
  declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
117
- declare function getResponseMime(operation: OperationObject, statusCode: number): "application/json" | "*/*" | undefined;
125
+ declare function doStatusCodeStrategy(operation: OperationObject, statusCode: number, strategy: StatusCodeStrategy): {
126
+ statusCode: undefined;
127
+ mime: undefined;
128
+ } | {
129
+ statusCode: number;
130
+ mime: string | undefined;
131
+ };
118
132
 
119
133
  interface ApiModuleTemplateData {
120
134
  /**
@@ -228,7 +242,10 @@ interface GenerateOptions {
228
242
  */
229
243
  preset?: Preset;
230
244
  /**
231
- * The status code strategy to use. loose: all success status codes are 200, strict: use the openapi recommended success status codes.
245
+ * The status code strategy to use.
246
+ * loose: all success status codes are 200,
247
+ * strict: use the openapi recommended success status codes.
248
+ * smart: find a valid status code between [200, 299] that is closest to 200
232
249
  */
233
250
  statusCodeStrategy?: StatusCodeStrategy;
234
251
  /**
@@ -246,6 +263,7 @@ interface GenerateOptions {
246
263
  }
247
264
  declare function partitionApiModules(schema: OpenAPI3, transformer: Transformer, options: {
248
265
  ts: boolean;
266
+ statusCodeStrategy: StatusCodeStrategy;
249
267
  statusCodes: StatusCodes;
250
268
  base?: string;
251
269
  }): ApiModule[];
@@ -263,4 +281,4 @@ type Config = GenerateOptions;
263
281
  declare function defineConfig(config: Config): GenerateOptions;
264
282
  declare function getConfig(): Promise<Config>;
265
283
 
266
- export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, 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 };
284
+ export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, createStatusCodesByStrategy, createTransformer, defineConfig, doStatusCodeStrategy, generate, generateTypes, getCliVersion, getConfig, 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
@@ -82,7 +82,7 @@ interface Transformer {
82
82
  declare function createTransformer(): Transformer;
83
83
 
84
84
  type Preset = 'axle' | 'axios';
85
- type StatusCodeStrategy = 'strict' | 'loose';
85
+ type StatusCodeStrategy = 'strict' | 'loose' | 'smart';
86
86
  interface StatusCodes {
87
87
  get?: number;
88
88
  post?: number;
@@ -108,13 +108,27 @@ declare function createStatusCodesByStrategy(strategy: StatusCodeStrategy): {
108
108
  patch: number;
109
109
  options: number;
110
110
  head: number;
111
+ } | {
112
+ get: number;
113
+ post: number;
114
+ put: number;
115
+ delete: number;
116
+ patch: number;
117
+ options: number;
118
+ head: number;
111
119
  };
112
120
  declare function readSchema(input: string): Promise<OpenAPI3>;
113
121
  declare function readTemplateFile(preset?: Preset): string;
114
122
  declare function hasQueryParameter(operation: OperationObject): boolean;
115
123
  declare function getCliVersion(): any;
116
124
  declare function isRequiredRequestBody(value: RequestBodyObject | ReferenceObject): boolean;
117
- declare function getResponseMime(operation: OperationObject, statusCode: number): "application/json" | "*/*" | undefined;
125
+ declare function doStatusCodeStrategy(operation: OperationObject, statusCode: number, strategy: StatusCodeStrategy): {
126
+ statusCode: undefined;
127
+ mime: undefined;
128
+ } | {
129
+ statusCode: number;
130
+ mime: string | undefined;
131
+ };
118
132
 
119
133
  interface ApiModuleTemplateData {
120
134
  /**
@@ -228,7 +242,10 @@ interface GenerateOptions {
228
242
  */
229
243
  preset?: Preset;
230
244
  /**
231
- * The status code strategy to use. loose: all success status codes are 200, strict: use the openapi recommended success status codes.
245
+ * The status code strategy to use.
246
+ * loose: all success status codes are 200,
247
+ * strict: use the openapi recommended success status codes.
248
+ * smart: find a valid status code between [200, 299] that is closest to 200
232
249
  */
233
250
  statusCodeStrategy?: StatusCodeStrategy;
234
251
  /**
@@ -246,6 +263,7 @@ interface GenerateOptions {
246
263
  }
247
264
  declare function partitionApiModules(schema: OpenAPI3, transformer: Transformer, options: {
248
265
  ts: boolean;
266
+ statusCodeStrategy: StatusCodeStrategy;
249
267
  statusCodes: StatusCodes;
250
268
  base?: string;
251
269
  }): ApiModule[];
@@ -263,4 +281,4 @@ type Config = GenerateOptions;
263
281
  declare function defineConfig(config: Config): GenerateOptions;
264
282
  declare function getConfig(): Promise<Config>;
265
283
 
266
- export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, 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 };
284
+ export { type ApiModule, type ApiModulePayload, type ApiModuleTemplateData, type Config, type GenerateOptions, type Preset, type StatusCodeStrategy, type StatusCodes, type Transformer, type TransformerBaseArgs, createStatusCodesByStrategy, createTransformer, defineConfig, doStatusCodeStrategy, generate, generateTypes, getCliVersion, getConfig, 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,16 +19,16 @@ import {
19
19
  transformTypeValue,
20
20
  transformUrl,
21
21
  transformVerb
22
- } from "./chunk-ZOF4QGMP.js";
22
+ } from "./chunk-I24WWW5F.js";
23
23
  import {
24
24
  createStatusCodesByStrategy,
25
+ doStatusCodeStrategy,
25
26
  getCliVersion,
26
- getResponseMime,
27
27
  hasQueryParameter,
28
28
  isRequiredRequestBody,
29
29
  readSchema,
30
30
  readTemplateFile
31
- } from "./chunk-OBPECFFY.js";
31
+ } from "./chunk-THTMWQYI.js";
32
32
  import "./chunk-6OIOYGN7.js";
33
33
 
34
34
  // src/index.ts
@@ -37,11 +37,11 @@ export {
37
37
  createStatusCodesByStrategy,
38
38
  createTransformer,
39
39
  defineConfig,
40
+ doStatusCodeStrategy,
40
41
  generate,
41
42
  generateTypes,
42
43
  getCliVersion,
43
44
  getConfig,
44
- getResponseMime,
45
45
  hasQueryParameter,
46
46
  isRequiredRequestBody,
47
47
  partitionApiModules,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-farmer",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "API module generation tool based on Openapi3/Swagger2.",
5
5
  "keywords": [
6
6
  "cli",