api-farmer 0.0.12 → 0.0.14

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
@@ -36,8 +36,8 @@ import { defineConfig } from 'api-farmer'
36
36
  export default defineConfig({
37
37
  // openapi or swagger schema path, defaults './schema.json'
38
38
  input: './schema.yaml',
39
- // generated codes output path, defaults './src/apis'
40
- output: './src/apis',
39
+ // generated codes output path, defaults './src/apis/generated'
40
+ output: './src/apis/generated',
41
41
  // 'axle' or 'axios', defaults 'axle'.
42
42
  preset: 'axios',
43
43
  })
@@ -242,8 +242,8 @@ export interface ApiModulePayload {
242
242
  */
243
243
  typeQuery: string
244
244
  /**
245
- * The value of the type of the query parameters of the API endpoint,
246
- * such as ApiGetUsersQuery['parameters']['query'], ApiCreatePostQuery['parameters']['query'],
245
+ * The value of the type of the query parameters of the API endpoint, such as
246
+ * ApiGetUsersQuery['parameters']['query'], ApiCreatePostQuery['parameters']['query'],
247
247
  * ApiUpdateCommentQuery['parameters']['query'], etc.
248
248
  */
249
249
  typeQueryValue: string
@@ -253,8 +253,8 @@ export interface ApiModulePayload {
253
253
  */
254
254
  typeRequestBody: string
255
255
  /**
256
- * The value of the type of the request body of the API endpoint,
257
- * such as ApiGetUsersRequestBody['requestBody']['content']['application/json'],
256
+ * The value of the type of the request body of the API endpoint, such as
257
+ * ApiGetUsersRequestBody['requestBody']['content']['application/json'],
258
258
  * ApiCreatePostRequestBody['requestBody']['content']['application/json'],
259
259
  * ApiUpdateCommentRequestBody['requestBody']['content']['application/json'], etc.
260
260
  */
@@ -7,7 +7,7 @@ import {
7
7
  isRequiredRequestBody,
8
8
  readSchema,
9
9
  readTemplateFile
10
- } from "./chunk-IYZKIOO6.js";
10
+ } from "./chunk-LYOTF4II.js";
11
11
  import {
12
12
  __export
13
13
  } from "./chunk-6OIOYGN7.js";
@@ -22838,7 +22838,7 @@ function transformPayloads(pathItems, options8) {
22838
22838
  const type2 = transformer.type({ ...args, verb, entity });
22839
22839
  const typeValue = transformer.typeValue({ ...args, verb, entity });
22840
22840
  const typeQuery = transformer.typeQuery({ ...args, type: type2, verb, entity });
22841
- const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ ...args, type: type2, verb, entity }) : "never";
22841
+ const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ ...args, type: type2, verb, entity }) : "undefined";
22842
22842
  const typeRequestBody = transformer.typeRequestBody({ ...args, type: type2, verb, entity });
22843
22843
  const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
22844
22844
  ...args,
@@ -22846,14 +22846,14 @@ function transformPayloads(pathItems, options8) {
22846
22846
  verb,
22847
22847
  entity,
22848
22848
  required: isRequiredRequestBody(operation.requestBody)
22849
- }) : "never";
22849
+ }) : "undefined";
22850
22850
  const { mime, statusCode } = doStatusCodeStrategy(
22851
22851
  operation,
22852
22852
  statusCodes[method] ?? 200,
22853
22853
  statusCodeStrategy
22854
22854
  );
22855
22855
  const typeResponseBody = transformer.typeResponseBody({ ...args, type: type2, verb, entity });
22856
- const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
22856
+ const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "undefined";
22857
22857
  payloads.push({
22858
22858
  fn,
22859
22859
  url: url2,
@@ -22938,8 +22938,8 @@ async function generate(userOptions = {}) {
22938
22938
  preset = "axle",
22939
22939
  statusCodeStrategy = "smart",
22940
22940
  input = "./schema.json",
22941
- output = "./src/apis",
22942
- typesFilename = "types.generated.ts",
22941
+ output = "./src/apis/generated",
22942
+ typesFilename = "_types.ts",
22943
22943
  transformer = {}
22944
22944
  } = options8;
22945
22945
  const statusCodes = {
@@ -71,7 +71,7 @@ function isRequiredRequestBody(value) {
71
71
  function doStatusCodeStrategy(operation, statusCode, strategy) {
72
72
  if (strategy === "smart") {
73
73
  const responses = operation.responses ?? {};
74
- const codeKey = Object.keys(responses).sort((a, b) => Number(a) - Number(b)).find((codeKey2) => Number(codeKey2) >= statusCode && Number(codeKey2) <= 299);
74
+ const codeKey = Object.keys(responses).sort((a, b) => Number(a) - Number(b)).find((codeKey2) => Number(codeKey2) >= 200 && Number(codeKey2) <= 299);
75
75
  if (!codeKey) {
76
76
  return {
77
77
  statusCode: void 0,
package/dist/cli.cjs CHANGED
@@ -112,7 +112,7 @@ function isRequiredRequestBody(value) {
112
112
  function doStatusCodeStrategy(operation, statusCode, strategy) {
113
113
  if (strategy === "smart") {
114
114
  const responses = operation.responses ?? {};
115
- const codeKey = Object.keys(responses).sort((a5, b8) => Number(a5) - Number(b8)).find((codeKey2) => Number(codeKey2) >= statusCode && Number(codeKey2) <= 299);
115
+ const codeKey = Object.keys(responses).sort((a5, b8) => Number(a5) - Number(b8)).find((codeKey2) => Number(codeKey2) >= 200 && Number(codeKey2) <= 299);
116
116
  if (!codeKey) {
117
117
  return {
118
118
  statusCode: void 0,
@@ -102139,7 +102139,7 @@ function transformPayloads(pathItems, options8) {
102139
102139
  const type2 = transformer.type({ ...args, verb, entity });
102140
102140
  const typeValue = transformer.typeValue({ ...args, verb, entity });
102141
102141
  const typeQuery = transformer.typeQuery({ ...args, type: type2, verb, entity });
102142
- const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ ...args, type: type2, verb, entity }) : "never";
102142
+ const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ ...args, type: type2, verb, entity }) : "undefined";
102143
102143
  const typeRequestBody = transformer.typeRequestBody({ ...args, type: type2, verb, entity });
102144
102144
  const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
102145
102145
  ...args,
@@ -102147,14 +102147,14 @@ function transformPayloads(pathItems, options8) {
102147
102147
  verb,
102148
102148
  entity,
102149
102149
  required: isRequiredRequestBody(operation.requestBody)
102150
- }) : "never";
102150
+ }) : "undefined";
102151
102151
  const { mime, statusCode } = doStatusCodeStrategy(
102152
102152
  operation,
102153
102153
  statusCodes[method] ?? 200,
102154
102154
  statusCodeStrategy
102155
102155
  );
102156
102156
  const typeResponseBody = transformer.typeResponseBody({ ...args, type: type2, verb, entity });
102157
- const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
102157
+ const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "undefined";
102158
102158
  payloads.push({
102159
102159
  fn: fn8,
102160
102160
  url: url2,
@@ -102239,8 +102239,8 @@ async function generate(userOptions = {}) {
102239
102239
  preset = "axle",
102240
102240
  statusCodeStrategy = "smart",
102241
102241
  input = "./schema.json",
102242
- output = "./src/apis",
102243
- typesFilename = "types.generated.ts",
102242
+ output = "./src/apis/generated",
102243
+ typesFilename = "_types.ts",
102244
102244
  transformer = {}
102245
102245
  } = options8;
102246
102246
  const statusCodes = {
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  getCliVersion
4
- } from "./chunk-IYZKIOO6.js";
4
+ } from "./chunk-LYOTF4II.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-T2F6BJAQ.js");
12
+ const { generate } = await import("./generate-2D36YQRL.js");
13
13
  return generate();
14
14
  });
15
15
  program.parse();
@@ -4,8 +4,8 @@ import {
4
4
  partitionApiModules,
5
5
  renderApiModules,
6
6
  transformPayloads
7
- } from "./chunk-DVS6RR7Q.js";
8
- import "./chunk-IYZKIOO6.js";
7
+ } from "./chunk-7HSWACLR.js";
8
+ import "./chunk-LYOTF4II.js";
9
9
  import "./chunk-6OIOYGN7.js";
10
10
  export {
11
11
  generate,
package/dist/index.cjs CHANGED
@@ -102148,7 +102148,7 @@ function isRequiredRequestBody(value) {
102148
102148
  function doStatusCodeStrategy(operation, statusCode, strategy) {
102149
102149
  if (strategy === "smart") {
102150
102150
  const responses = operation.responses ?? {};
102151
- const codeKey = Object.keys(responses).sort((a5, b8) => Number(a5) - Number(b8)).find((codeKey2) => Number(codeKey2) >= statusCode && Number(codeKey2) <= 299);
102151
+ const codeKey = Object.keys(responses).sort((a5, b8) => Number(a5) - Number(b8)).find((codeKey2) => Number(codeKey2) >= 200 && Number(codeKey2) <= 299);
102152
102152
  if (!codeKey) {
102153
102153
  return {
102154
102154
  statusCode: void 0,
@@ -102177,7 +102177,7 @@ function transformPayloads(pathItems, options8) {
102177
102177
  const type2 = transformer.type({ ...args, verb, entity });
102178
102178
  const typeValue = transformer.typeValue({ ...args, verb, entity });
102179
102179
  const typeQuery = transformer.typeQuery({ ...args, type: type2, verb, entity });
102180
- const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ ...args, type: type2, verb, entity }) : "never";
102180
+ const typeQueryValue = hasQueryParameter(operation) ? transformer.typeQueryValue({ ...args, type: type2, verb, entity }) : "undefined";
102181
102181
  const typeRequestBody = transformer.typeRequestBody({ ...args, type: type2, verb, entity });
102182
102182
  const typeRequestBodyValue = operation.requestBody ? transformer.typeRequestBodyValue({
102183
102183
  ...args,
@@ -102185,14 +102185,14 @@ function transformPayloads(pathItems, options8) {
102185
102185
  verb,
102186
102186
  entity,
102187
102187
  required: isRequiredRequestBody(operation.requestBody)
102188
- }) : "never";
102188
+ }) : "undefined";
102189
102189
  const { mime, statusCode } = doStatusCodeStrategy(
102190
102190
  operation,
102191
102191
  statusCodes[method] ?? 200,
102192
102192
  statusCodeStrategy
102193
102193
  );
102194
102194
  const typeResponseBody = transformer.typeResponseBody({ ...args, type: type2, verb, entity });
102195
- const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "never";
102195
+ const typeResponseBodyValue = mime && statusCode ? transformer.typeResponseBodyValue({ ...args, type: type2, verb, entity, statusCode, mime }) : "undefined";
102196
102196
  payloads.push({
102197
102197
  fn: fn8,
102198
102198
  url: url2,
@@ -102277,8 +102277,8 @@ async function generate(userOptions = {}) {
102277
102277
  preset = "axle",
102278
102278
  statusCodeStrategy = "smart",
102279
102279
  input = "./schema.json",
102280
- output = "./src/apis",
102281
- typesFilename = "types.generated.ts",
102280
+ output = "./src/apis/generated",
102281
+ typesFilename = "_types.ts",
102282
102282
  transformer = {}
102283
102283
  } = options8;
102284
102284
  const statusCodes = {
package/dist/index.js CHANGED
@@ -20,7 +20,7 @@ import {
20
20
  transformTypeValue,
21
21
  transformUrl,
22
22
  transformVerb
23
- } from "./chunk-DVS6RR7Q.js";
23
+ } from "./chunk-7HSWACLR.js";
24
24
  import {
25
25
  createStatusCodesByStrategy,
26
26
  doStatusCodeStrategy,
@@ -29,7 +29,7 @@ import {
29
29
  isRequiredRequestBody,
30
30
  readSchema,
31
31
  readTemplateFile
32
- } from "./chunk-IYZKIOO6.js";
32
+ } from "./chunk-LYOTF4II.js";
33
33
  import "./chunk-6OIOYGN7.js";
34
34
 
35
35
  // src/index.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "api-farmer",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "description": "API module generation tool based on Openapi3/Swagger2.",
5
5
  "keywords": [
6
6
  "cli",
@@ -89,6 +89,6 @@
89
89
  "dev": "tsup src/index.ts src/cli.ts --format esm,cjs --watch --dts --shims",
90
90
  "format": "prettier --write .",
91
91
  "lint": "eslint . --fix",
92
- "release": "vr release"
92
+ "release": "pnpm build && vr release"
93
93
  }
94
94
  }