yapi-apifox-to-typescript 4.1.0 → 4.1.2

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.
@@ -142,7 +142,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
142
142
  ;
143
143
 
144
144
  _proto.getCats = function getCats(cats) {
145
- var categoryIds = (0, _utils.getFilteredCat)(cats, []); // 对cat进行有效性过滤
145
+ var categoryIds = (0, _utils.getFilteredCat)(cats, [], true); // 对cat进行有效性过滤
146
146
 
147
147
  return this.getValidCat(categoryIds);
148
148
  }
@@ -212,7 +212,7 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
212
212
  return child.type === 'apiDetail';
213
213
  }).map( /*#__PURE__*/function () {
214
214
  var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(child) {
215
- var _resultData$responses, _resultData$responses2, _resultData$responses3, _resultData$responses4, _resultData$responses5, _resultData$responses6, _resultData$responses7, _resultData$requestBo, _resultData$requestBo2, _resultData$parameter, _resultData$parameter2;
215
+ var _resultData$responses, _resultData$responses2, _resultData$responses3, _resultData$responses4, _resultData$responses5, _resultData$responses6, _resultData$responses7, _resultData$requestBo, _resultData$requestBo2, _resultData$parameter, _resultData$parameter2, _resultData$requestBo3;
216
216
 
217
217
  var result, resultData, resbodyIndex, respref, dataProperties, item, _dataProperties$item$, dataPropRef, reqref;
218
218
 
@@ -318,9 +318,17 @@ var ApifoxToYApiData = /*#__PURE__*/function () {
318
318
  type: item.type === 'string' ? _types.RequestQueryType.string : _types.RequestQueryType.number
319
319
  };
320
320
  })) || [],
321
- req_body_type: resultData.requestBody.jsonSchema ? _types.RequestBodyType.json : _types.RequestBodyType.raw,
321
+ req_body_type: resultData.requestBody.type === 'multipart/form-data' ? _types.RequestBodyType.form : resultData.requestBody.jsonSchema ? _types.RequestBodyType.json : _types.RequestBodyType.raw,
322
322
  req_body_is_json_schema: !!resultData.requestBody.jsonSchema,
323
- req_body_form: [],
323
+ req_body_form: ((_resultData$requestBo3 = resultData.requestBody.parameters) == null ? void 0 : _resultData$requestBo3.map(function (item) {
324
+ return {
325
+ name: item.name,
326
+ desc: item.description,
327
+ example: item.example,
328
+ required: item.required ? _types.Required.true : _types.Required.false,
329
+ type: item.type === 'string' ? _types.RequestFormItemType.text : _types.RequestFormItemType.file
330
+ };
331
+ })) || [],
324
332
  req_body_other: resultData.requestBody.jsonSchema ? JSON.stringify(resultData.requestBody.jsonSchema) : '',
325
333
  res_body_type: _types.ResponseBodyType.json,
326
334
  res_body_is_json_schema: true,
@@ -597,7 +597,7 @@ var Generator = /*#__PURE__*/function () {
597
597
 
598
598
  case 20:
599
599
  // 始终写入主文件
600
- rawOutputContent = (0, _vtils.dedent)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2.default)(["\n /* tslint:disable */\n /* eslint-disable */\n\n /* \u8BE5\u6587\u4EF6\u7531 yapi-apifox-to-typescript \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u76F4\u63A5\u4FEE\u6539\uFF01\uFF01\uFF01 */\n\n ", "\n "])), syntheticalConfig.typesOnly ? (0, _vtils.dedent)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2.default)(["\n // @ts-ignore\n type FileData = File\n\n ", "\n "])), content.join('\n\n').trim()) : (0, _vtils.dedent)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteralLoose2.default)(["\n // @ts-ignore\n // prettier-ignore\n import { QueryStringArrayFormat, Method, ", "FileData, prepare } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n // prettier-ignore\n import type { RequestConfig, RequestFunctionRestArgs } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n import request from ", "\n ", "\n\n type UserRequestRestArgs = RequestFunctionRestArgs<typeof request>\n\n // Request: \u76EE\u524D React Hooks \u529F\u80FD\u6709\u7528\u5230\n export type Request<TRequestData, TRequestConfig extends RequestConfig, TRequestResult> = (\n TRequestConfig['requestDataOptional'] extends true\n ? (requestData?: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n : (requestData: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n ) & {\n requestConfig: TRequestConfig\n }\n\n ", "\n "])), syntheticalConfig.ignoreUselessConfigVar ? "" : "RequestBodyType, ResponseBodyType, ", JSON.stringify((0, _utils.getNormalizedRelativePath)(outputFilePath, requestFunctionFilePath)), !syntheticalConfig.reactHooks || !syntheticalConfig.reactHooks.enabled ? '' : (0, _vtils.dedent)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteralLoose2.default)(["\n // @ts-ignore\n import makeRequestHook from ", "\n "])), JSON.stringify((0, _utils.getNormalizedRelativePath)(outputFilePath, requestHookMakerFilePath))), content.join('\n\n').trim())); // ref: https://prettier.io/docs/en/options.html
600
+ rawOutputContent = (0, _vtils.dedent)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2.default)(["\n /* tslint:disable */\n /* eslint-disable */\n\n /* \u8BE5\u6587\u4EF6\u7531 yapi-apifox-to-typescript \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u76F4\u63A5\u4FEE\u6539\uFF01\uFF01\uFF01 */\n\n ", "\n "])), syntheticalConfig.typesOnly ? (0, _vtils.dedent)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteralLoose2.default)(["\n // @ts-ignore\n type FileData = File\n\n ", "\n "])), content.join('\n\n').trim()) : (0, _vtils.dedent)(_templateObject5 || (_templateObject5 = (0, _taggedTemplateLiteralLoose2.default)(["\n // @ts-ignore\n // prettier-ignore\n import { QueryStringArrayFormat, Method, RequestBodyType, ", "FileData, prepare } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n // prettier-ignore\n import type { RequestConfig, RequestFunctionRestArgs } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n import request from ", "\n ", "\n\n type UserRequestRestArgs = RequestFunctionRestArgs<typeof request>\n\n // Request: \u76EE\u524D React Hooks \u529F\u80FD\u6709\u7528\u5230\n export type Request<TRequestData, TRequestConfig extends RequestConfig, TRequestResult> = (\n TRequestConfig['requestDataOptional'] extends true\n ? (requestData?: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n : (requestData: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n ) & {\n requestConfig: TRequestConfig\n }\n\n ", "\n "])), syntheticalConfig.ignoreUselessConfigVar ? "" : "ResponseBodyType, ", JSON.stringify((0, _utils.getNormalizedRelativePath)(outputFilePath, requestFunctionFilePath)), !syntheticalConfig.reactHooks || !syntheticalConfig.reactHooks.enabled ? '' : (0, _vtils.dedent)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteralLoose2.default)(["\n // @ts-ignore\n import makeRequestHook from ", "\n "])), JSON.stringify((0, _utils.getNormalizedRelativePath)(outputFilePath, requestHookMakerFilePath))), content.join('\n\n').trim())); // ref: https://prettier.io/docs/en/options.html
601
601
 
602
602
  _context11.next = 23;
603
603
  return (0, _utils.getPrettier)(_this4.options.cwd);
@@ -1094,11 +1094,11 @@ var Generator = /*#__PURE__*/function () {
1094
1094
  return "\u63A5\u53E3 " + title + " \u7684 **\u8BF7\u6C42\u7C7B\u578B**";
1095
1095
  }), requestDataType.trim(), genComment(function (title) {
1096
1096
  return "\u63A5\u53E3 " + title + " \u7684 **\u8FD4\u56DE\u7C7B\u578B**";
1097
- }), responseDataType.trim(), syntheticalConfig.typesOnly ? '' : (0, _vtils.dedent)(_templateObject11 || (_templateObject11 = (0, _taggedTemplateLiteralLoose2.default)(["\n ", "\n ", "\n path: ", ",\n method: Method.", ",\n ", "", "", "", "", "\n }\n\n ", "\n export const ", " = ", " (\n requestData", ": ", ",\n ...args: UserRequestRestArgs\n ) => {\n return request<", ">(\n prepare(", ", requestData),\n ...args,\n )\n }\n\n ", ".requestConfig = ", "\n\n ", "\n "])), genComment(function (title) {
1097
+ }), responseDataType.trim(), syntheticalConfig.typesOnly ? '' : (0, _vtils.dedent)(_templateObject11 || (_templateObject11 = (0, _taggedTemplateLiteralLoose2.default)(["\n ", "\n ", "\n path: ", ",\n method: Method.", ",\n ", "", "", "", "requestBodyType: RequestBodyType.", ",\n ", "\n }\n\n ", "\n export const ", " = ", " (\n requestData", ": ", ",\n ...args: UserRequestRestArgs\n ) => {\n return request<", ">(\n prepare(", ", requestData),\n ...args,\n )\n }\n\n ", ".requestConfig = ", "\n\n ", "\n "])), genComment(function (title) {
1098
1098
  return "\u63A5\u53E3 " + title + " \u7684 **\u8BF7\u6C42\u914D\u7F6E**";
1099
- }), syntheticalConfig.withoutUrl !== true ? "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {\n mockUrl: mockUrl" + categoryUID + ",\n devUrl: devUrl" + categoryUID + ",\n prodUrl: prodUrl" + categoryUID + "," : "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {", JSON.stringify(extendedInterfaceInfo.path), extendedInterfaceInfo.method, paramNames.length === 0 ? '' : "paramNames: " + paramNamesLiteral + ",", queryNames.length === 0 ? '' : "queryNames: " + queryNamesLiteral + ",", syntheticalConfig.queryStringArrayFormat ? "queryStringArrayFormat: QueryStringArrayFormat." + syntheticalConfig.queryStringArrayFormat + "," : '', requestHeaders === '{}' ? '' : "requestHeaders: " + requestHeaders + ",", syntheticalConfig.ignoreUselessConfigVar ? "" : "requestBodyType: RequestBodyType." + (extendedInterfaceInfo.method === _types.Method.GET ? _types.RequestBodyType.query : extendedInterfaceInfo.req_body_type
1099
+ }), syntheticalConfig.withoutUrl !== true ? "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {\n mockUrl: mockUrl" + categoryUID + ",\n devUrl: devUrl" + categoryUID + ",\n prodUrl: prodUrl" + categoryUID + "," : "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {", JSON.stringify(extendedInterfaceInfo.path), extendedInterfaceInfo.method, paramNames.length === 0 ? '' : "paramNames: " + paramNamesLiteral + ",", queryNames.length === 0 ? '' : "queryNames: " + queryNamesLiteral + ",", syntheticalConfig.queryStringArrayFormat ? "queryStringArrayFormat: QueryStringArrayFormat." + syntheticalConfig.queryStringArrayFormat + "," : '', requestHeaders === '{}' ? '' : "requestHeaders: " + requestHeaders + ",", extendedInterfaceInfo.method === _types.Method.GET ? _types.RequestBodyType.query : extendedInterfaceInfo.req_body_type
1100
1100
  /* istanbul ignore next */
1101
- || _types.RequestBodyType.none) + ",\n responseBodyType: ResponseBodyType." + extendedInterfaceInfo.res_body_type + ",\n dataKey: dataKey" + categoryUID + ",\n requestDataOptional: " + JSON.stringify(isRequestDataOptional) + ",\n requestDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js.enabled && ((_syntheticalConfig$js2 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js2.requestData) !== false ? requestDataJsonSchema : {}) + ",\n responseDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js3 = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js3.enabled && ((_syntheticalConfig$js4 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js4.responseData) !== false ? responseDataJsonSchema : {}) + ",\n requestFunctionName: " + JSON.stringify(requestFunctionName) + ",\n extraInfo: " + JSON.stringify(requestFunctionExtraInfo), genComment(function (title) {
1101
+ || _types.RequestBodyType.none, syntheticalConfig.ignoreUselessConfigVar ? "" : "responseBodyType: ResponseBodyType." + extendedInterfaceInfo.res_body_type + ",\n dataKey: dataKey" + categoryUID + ",\n requestDataOptional: " + JSON.stringify(isRequestDataOptional) + ",\n requestDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js.enabled && ((_syntheticalConfig$js2 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js2.requestData) !== false ? requestDataJsonSchema : {}) + ",\n responseDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js3 = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js3.enabled && ((_syntheticalConfig$js4 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js4.responseData) !== false ? responseDataJsonSchema : {}) + ",\n requestFunctionName: " + JSON.stringify(requestFunctionName) + ",\n extraInfo: " + JSON.stringify(requestFunctionExtraInfo), genComment(function (title) {
1102
1102
  return "\u63A5\u53E3 " + title + " \u7684 **\u8BF7\u6C42\u51FD\u6570**";
1103
1103
  }), requestFunctionName, COMPRESSOR_TREE_SHAKING_ANNOTATION, isRequestDataOptional ? '?' : '', requestDataTypeName, responseDataTypeName, requestConfigName, requestFunctionName, requestConfigName, !syntheticalConfig.reactHooks || !syntheticalConfig.reactHooks.enabled ? '' : (0, _vtils.dedent)(_templateObject12 || (_templateObject12 = (0, _taggedTemplateLiteralLoose2.default)(["\n ", "\n export const ", " = ", " makeRequestHook<", ", ", ", ReturnType<typeof ", ">>(", ")\n "])), genComment(function (title) {
1104
1104
  return "\u63A5\u53E3 " + title + " \u7684 **React Hook**";
package/lib/cjs/utils.js CHANGED
@@ -769,7 +769,11 @@ function _httpGet() {
769
769
  return _httpGet.apply(this, arguments);
770
770
  }
771
771
 
772
- var getFilteredCat = function getFilteredCat(cat, cats) {
772
+ var getFilteredCat = function getFilteredCat(cat, cats, isApifox) {
773
+ if (isApifox === void 0) {
774
+ isApifox = false;
775
+ }
776
+
773
777
  // 分类处理
774
778
  // 数组化
775
779
  var categoryIds = (0, _vtils.castArray)(cat.id); // 全部分类
@@ -792,11 +796,14 @@ var getFilteredCat = function getFilteredCat(cat, cats) {
792
796
  return !excludedCategoryIds.includes(Math.abs(id));
793
797
  }); // 删除不存在的分类
794
798
 
795
- categoryIds = categoryIds.filter(function (id) {
796
- return !!cats.find(function (c) {
797
- return c._id === id;
799
+ if (!isApifox) {
800
+ categoryIds = categoryIds.filter(function (id) {
801
+ return !!cats.find(function (c) {
802
+ return c._id === id;
803
+ });
798
804
  });
799
- }); // 顺序化
805
+ } // 顺序化
806
+
800
807
 
801
808
  categoryIds = categoryIds.sort();
802
809
  return categoryIds;
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
4
  import axios from 'axios';
5
- import { RequestBodyType, RequestParamType, RequestQueryType, Required, ResponseBodyType } from './types';
5
+ import { RequestBodyType, RequestFormItemType, RequestParamType, RequestQueryType, Required, ResponseBodyType } from './types';
6
6
  import { getFilteredCat } from './utils';
7
7
  export var ApifoxToYApiData = /*#__PURE__*/function () {
8
8
  function ApifoxToYApiData(options) {
@@ -129,7 +129,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
129
129
  ;
130
130
 
131
131
  _proto.getCats = function getCats(cats) {
132
- var categoryIds = getFilteredCat(cats, []); // 对cat进行有效性过滤
132
+ var categoryIds = getFilteredCat(cats, [], true); // 对cat进行有效性过滤
133
133
 
134
134
  return this.getValidCat(categoryIds);
135
135
  }
@@ -199,7 +199,7 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
199
199
  return child.type === 'apiDetail';
200
200
  }).map( /*#__PURE__*/function () {
201
201
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(child) {
202
- var _resultData$responses, _resultData$responses2, _resultData$responses3, _resultData$responses4, _resultData$responses5, _resultData$responses6, _resultData$responses7, _resultData$requestBo, _resultData$requestBo2, _resultData$parameter, _resultData$parameter2;
202
+ var _resultData$responses, _resultData$responses2, _resultData$responses3, _resultData$responses4, _resultData$responses5, _resultData$responses6, _resultData$responses7, _resultData$requestBo, _resultData$requestBo2, _resultData$parameter, _resultData$parameter2, _resultData$requestBo3;
203
203
 
204
204
  var result, resultData, resbodyIndex, respref, dataProperties, item, _dataProperties$item$, dataPropRef, reqref;
205
205
 
@@ -305,9 +305,17 @@ export var ApifoxToYApiData = /*#__PURE__*/function () {
305
305
  type: item.type === 'string' ? RequestQueryType.string : RequestQueryType.number
306
306
  };
307
307
  })) || [],
308
- req_body_type: resultData.requestBody.jsonSchema ? RequestBodyType.json : RequestBodyType.raw,
308
+ req_body_type: resultData.requestBody.type === 'multipart/form-data' ? RequestBodyType.form : resultData.requestBody.jsonSchema ? RequestBodyType.json : RequestBodyType.raw,
309
309
  req_body_is_json_schema: !!resultData.requestBody.jsonSchema,
310
- req_body_form: [],
310
+ req_body_form: ((_resultData$requestBo3 = resultData.requestBody.parameters) == null ? void 0 : _resultData$requestBo3.map(function (item) {
311
+ return {
312
+ name: item.name,
313
+ desc: item.description,
314
+ example: item.example,
315
+ required: item.required ? Required.true : Required.false,
316
+ type: item.type === 'string' ? RequestFormItemType.text : RequestFormItemType.file
317
+ };
318
+ })) || [],
311
319
  req_body_other: resultData.requestBody.jsonSchema ? JSON.stringify(resultData.requestBody.jsonSchema) : '',
312
320
  res_body_type: ResponseBodyType.json,
313
321
  res_body_is_json_schema: true,
@@ -574,7 +574,7 @@ export var Generator = /*#__PURE__*/function () {
574
574
 
575
575
  case 20:
576
576
  // 始终写入主文件
577
- rawOutputContent = dedent(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n /* tslint:disable */\n /* eslint-disable */\n\n /* \u8BE5\u6587\u4EF6\u7531 yapi-apifox-to-typescript \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u76F4\u63A5\u4FEE\u6539\uFF01\uFF01\uFF01 */\n\n ", "\n "])), syntheticalConfig.typesOnly ? dedent(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n // @ts-ignore\n type FileData = File\n\n ", "\n "])), content.join('\n\n').trim()) : dedent(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n // @ts-ignore\n // prettier-ignore\n import { QueryStringArrayFormat, Method, ", "FileData, prepare } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n // prettier-ignore\n import type { RequestConfig, RequestFunctionRestArgs } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n import request from ", "\n ", "\n\n type UserRequestRestArgs = RequestFunctionRestArgs<typeof request>\n\n // Request: \u76EE\u524D React Hooks \u529F\u80FD\u6709\u7528\u5230\n export type Request<TRequestData, TRequestConfig extends RequestConfig, TRequestResult> = (\n TRequestConfig['requestDataOptional'] extends true\n ? (requestData?: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n : (requestData: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n ) & {\n requestConfig: TRequestConfig\n }\n\n ", "\n "])), syntheticalConfig.ignoreUselessConfigVar ? "" : "RequestBodyType, ResponseBodyType, ", JSON.stringify(getNormalizedRelativePath(outputFilePath, requestFunctionFilePath)), !syntheticalConfig.reactHooks || !syntheticalConfig.reactHooks.enabled ? '' : dedent(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n // @ts-ignore\n import makeRequestHook from ", "\n "])), JSON.stringify(getNormalizedRelativePath(outputFilePath, requestHookMakerFilePath))), content.join('\n\n').trim())); // ref: https://prettier.io/docs/en/options.html
577
+ rawOutputContent = dedent(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["\n /* tslint:disable */\n /* eslint-disable */\n\n /* \u8BE5\u6587\u4EF6\u7531 yapi-apifox-to-typescript \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u76F4\u63A5\u4FEE\u6539\uFF01\uFF01\uFF01 */\n\n ", "\n "])), syntheticalConfig.typesOnly ? dedent(_templateObject4 || (_templateObject4 = _taggedTemplateLiteralLoose(["\n // @ts-ignore\n type FileData = File\n\n ", "\n "])), content.join('\n\n').trim()) : dedent(_templateObject5 || (_templateObject5 = _taggedTemplateLiteralLoose(["\n // @ts-ignore\n // prettier-ignore\n import { QueryStringArrayFormat, Method, RequestBodyType, ", "FileData, prepare } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n // prettier-ignore\n import type { RequestConfig, RequestFunctionRestArgs } from 'yapi-apifox-to-typescript'\n // @ts-ignore\n import request from ", "\n ", "\n\n type UserRequestRestArgs = RequestFunctionRestArgs<typeof request>\n\n // Request: \u76EE\u524D React Hooks \u529F\u80FD\u6709\u7528\u5230\n export type Request<TRequestData, TRequestConfig extends RequestConfig, TRequestResult> = (\n TRequestConfig['requestDataOptional'] extends true\n ? (requestData?: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n : (requestData: TRequestData, ...args: RequestFunctionRestArgs<typeof request>) => TRequestResult\n ) & {\n requestConfig: TRequestConfig\n }\n\n ", "\n "])), syntheticalConfig.ignoreUselessConfigVar ? "" : "ResponseBodyType, ", JSON.stringify(getNormalizedRelativePath(outputFilePath, requestFunctionFilePath)), !syntheticalConfig.reactHooks || !syntheticalConfig.reactHooks.enabled ? '' : dedent(_templateObject6 || (_templateObject6 = _taggedTemplateLiteralLoose(["\n // @ts-ignore\n import makeRequestHook from ", "\n "])), JSON.stringify(getNormalizedRelativePath(outputFilePath, requestHookMakerFilePath))), content.join('\n\n').trim())); // ref: https://prettier.io/docs/en/options.html
578
578
 
579
579
  _context11.next = 23;
580
580
  return getPrettier(_this4.options.cwd);
@@ -1071,11 +1071,11 @@ export var Generator = /*#__PURE__*/function () {
1071
1071
  return "\u63A5\u53E3 " + title + " \u7684 **\u8BF7\u6C42\u7C7B\u578B**";
1072
1072
  }), requestDataType.trim(), genComment(function (title) {
1073
1073
  return "\u63A5\u53E3 " + title + " \u7684 **\u8FD4\u56DE\u7C7B\u578B**";
1074
- }), responseDataType.trim(), syntheticalConfig.typesOnly ? '' : dedent(_templateObject11 || (_templateObject11 = _taggedTemplateLiteralLoose(["\n ", "\n ", "\n path: ", ",\n method: Method.", ",\n ", "", "", "", "", "\n }\n\n ", "\n export const ", " = ", " (\n requestData", ": ", ",\n ...args: UserRequestRestArgs\n ) => {\n return request<", ">(\n prepare(", ", requestData),\n ...args,\n )\n }\n\n ", ".requestConfig = ", "\n\n ", "\n "])), genComment(function (title) {
1074
+ }), responseDataType.trim(), syntheticalConfig.typesOnly ? '' : dedent(_templateObject11 || (_templateObject11 = _taggedTemplateLiteralLoose(["\n ", "\n ", "\n path: ", ",\n method: Method.", ",\n ", "", "", "", "requestBodyType: RequestBodyType.", ",\n ", "\n }\n\n ", "\n export const ", " = ", " (\n requestData", ": ", ",\n ...args: UserRequestRestArgs\n ) => {\n return request<", ">(\n prepare(", ", requestData),\n ...args,\n )\n }\n\n ", ".requestConfig = ", "\n\n ", "\n "])), genComment(function (title) {
1075
1075
  return "\u63A5\u53E3 " + title + " \u7684 **\u8BF7\u6C42\u914D\u7F6E**";
1076
- }), syntheticalConfig.withoutUrl !== true ? "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {\n mockUrl: mockUrl" + categoryUID + ",\n devUrl: devUrl" + categoryUID + ",\n prodUrl: prodUrl" + categoryUID + "," : "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {", JSON.stringify(extendedInterfaceInfo.path), extendedInterfaceInfo.method, paramNames.length === 0 ? '' : "paramNames: " + paramNamesLiteral + ",", queryNames.length === 0 ? '' : "queryNames: " + queryNamesLiteral + ",", syntheticalConfig.queryStringArrayFormat ? "queryStringArrayFormat: QueryStringArrayFormat." + syntheticalConfig.queryStringArrayFormat + "," : '', requestHeaders === '{}' ? '' : "requestHeaders: " + requestHeaders + ",", syntheticalConfig.ignoreUselessConfigVar ? "" : "requestBodyType: RequestBodyType." + (extendedInterfaceInfo.method === Method.GET ? RequestBodyType.query : extendedInterfaceInfo.req_body_type
1076
+ }), syntheticalConfig.withoutUrl !== true ? "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {\n mockUrl: mockUrl" + categoryUID + ",\n devUrl: devUrl" + categoryUID + ",\n prodUrl: prodUrl" + categoryUID + "," : "const " + requestConfigName + ": " + requestConfigTypeName + " = " + COMPRESSOR_TREE_SHAKING_ANNOTATION + " {", JSON.stringify(extendedInterfaceInfo.path), extendedInterfaceInfo.method, paramNames.length === 0 ? '' : "paramNames: " + paramNamesLiteral + ",", queryNames.length === 0 ? '' : "queryNames: " + queryNamesLiteral + ",", syntheticalConfig.queryStringArrayFormat ? "queryStringArrayFormat: QueryStringArrayFormat." + syntheticalConfig.queryStringArrayFormat + "," : '', requestHeaders === '{}' ? '' : "requestHeaders: " + requestHeaders + ",", extendedInterfaceInfo.method === Method.GET ? RequestBodyType.query : extendedInterfaceInfo.req_body_type
1077
1077
  /* istanbul ignore next */
1078
- || RequestBodyType.none) + ",\n responseBodyType: ResponseBodyType." + extendedInterfaceInfo.res_body_type + ",\n dataKey: dataKey" + categoryUID + ",\n requestDataOptional: " + JSON.stringify(isRequestDataOptional) + ",\n requestDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js.enabled && ((_syntheticalConfig$js2 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js2.requestData) !== false ? requestDataJsonSchema : {}) + ",\n responseDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js3 = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js3.enabled && ((_syntheticalConfig$js4 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js4.responseData) !== false ? responseDataJsonSchema : {}) + ",\n requestFunctionName: " + JSON.stringify(requestFunctionName) + ",\n extraInfo: " + JSON.stringify(requestFunctionExtraInfo), genComment(function (title) {
1078
+ || RequestBodyType.none, syntheticalConfig.ignoreUselessConfigVar ? "" : "responseBodyType: ResponseBodyType." + extendedInterfaceInfo.res_body_type + ",\n dataKey: dataKey" + categoryUID + ",\n requestDataOptional: " + JSON.stringify(isRequestDataOptional) + ",\n requestDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js.enabled && ((_syntheticalConfig$js2 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js2.requestData) !== false ? requestDataJsonSchema : {}) + ",\n responseDataJsonSchema: " + JSON.stringify((_syntheticalConfig$js3 = syntheticalConfig.jsonSchema) != null && _syntheticalConfig$js3.enabled && ((_syntheticalConfig$js4 = syntheticalConfig.jsonSchema) == null ? void 0 : _syntheticalConfig$js4.responseData) !== false ? responseDataJsonSchema : {}) + ",\n requestFunctionName: " + JSON.stringify(requestFunctionName) + ",\n extraInfo: " + JSON.stringify(requestFunctionExtraInfo), genComment(function (title) {
1079
1079
  return "\u63A5\u53E3 " + title + " \u7684 **\u8BF7\u6C42\u51FD\u6570**";
1080
1080
  }), requestFunctionName, COMPRESSOR_TREE_SHAKING_ANNOTATION, isRequestDataOptional ? '?' : '', requestDataTypeName, responseDataTypeName, requestConfigName, requestFunctionName, requestConfigName, !syntheticalConfig.reactHooks || !syntheticalConfig.reactHooks.enabled ? '' : dedent(_templateObject12 || (_templateObject12 = _taggedTemplateLiteralLoose(["\n ", "\n export const ", " = ", " makeRequestHook<", ", ", ", ReturnType<typeof ", ">>(", ")\n "])), genComment(function (title) {
1081
1081
  return "\u63A5\u53E3 " + title + " \u7684 **React Hook**";
package/lib/esm/utils.js CHANGED
@@ -709,7 +709,11 @@ function _httpGet() {
709
709
  return _httpGet.apply(this, arguments);
710
710
  }
711
711
 
712
- export var getFilteredCat = function getFilteredCat(cat, cats) {
712
+ export var getFilteredCat = function getFilteredCat(cat, cats, isApifox) {
713
+ if (isApifox === void 0) {
714
+ isApifox = false;
715
+ }
716
+
713
717
  // 分类处理
714
718
  // 数组化
715
719
  var categoryIds = castArray(cat.id); // 全部分类
@@ -732,11 +736,14 @@ export var getFilteredCat = function getFilteredCat(cat, cats) {
732
736
  return !excludedCategoryIds.includes(Math.abs(id));
733
737
  }); // 删除不存在的分类
734
738
 
735
- categoryIds = categoryIds.filter(function (id) {
736
- return !!cats.find(function (c) {
737
- return c._id === id;
739
+ if (!isApifox) {
740
+ categoryIds = categoryIds.filter(function (id) {
741
+ return !!cats.find(function (c) {
742
+ return c._id === id;
743
+ });
738
744
  });
739
- }); // 顺序化
745
+ } // 顺序化
746
+
740
747
 
741
748
  categoryIds = categoryIds.sort();
742
749
  return categoryIds;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yapi-apifox-to-typescript",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "根据 YApi 或 Apifox 的接口定义生成 TypeScript/JavaScript 的接口类型及其请求函数代码。",
5
5
  "keywords": [
6
6
  "yapi",