openapi-ts-request 1.7.3 → 1.8.0

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
@@ -194,6 +194,7 @@ $ openapi --help
194
194
  -f, --full <boolean> full replacement (default: true)
195
195
  --enableLogging <boolean> open the log (default: false)
196
196
  --priorityRule <string> priority rule, include/exclude/both (default: "include")
197
+ --filterCaseInsensitive <boolean> whether to perform a case-insensitive match with includeTags, includePaths, excludeTags, excludePaths filters
197
198
  --includeTags <(string|RegExp)[]> generate code from include tags
198
199
  --includePaths <(string|RegExp)[]> generate code from include paths
199
200
  --excludeTags <(string|RegExp)[]> generate code from exclude tags
@@ -232,6 +233,7 @@ openapi --i ./spec.json --o ./apis
232
233
  | full | 否 | boolean | true | 是否全量替换 |
233
234
  | enableLogging | 否 | boolean | false | 是否开启日志 |
234
235
  | priorityRule | 否 | string | 'include' | 模式规则,可选include/exclude/both |
236
+ | filterCaseInsensitive | 否 | boolean | false | 执行 includeTags、includePaths、excludeTags、excludePaths 过滤时是否忽略大小写 |
235
237
  | includeTags | 否 | (string\|RegExp)[] | - | 根据指定的 tags 生成代码, priorityRule=include则必填 |
236
238
  | includePaths | 否 | (string\|RegExp)[] | - | 根据指定的 paths 生成代码 |
237
239
  | excludeTags | 否 | (string\|RegExp)[] | - | 根据指定的 tags 不生成代码 |
@@ -21,7 +21,9 @@ const params = commander_1.program
21
21
  .option('--requestLibPath <string>', 'custom request lib path, for example: "@/request", "node-fetch" (default: "axios")')
22
22
  .option('-f, --full <boolean>', 'full replacement', true)
23
23
  .option('--enableLogging <boolean>', 'open the log', false)
24
- .option('--priorityRule <string>', 'priority rule, include/exclude/both (default: "include")')
24
+ .option('--filterCaseInsensitive <boolean>', 'whether to perform a case-insensitive match with includeTags, includePaths, excludeTags, excludePaths filters', false)
25
+ .option('--includeTags <(string|RegExp)[]>', 'generate code from include tags')
26
+ .option('--filterCaseInsensitive <boolean>', 'whether to perform a case-insensitive match with includeTags, includePaths, excludeTags, excludePaths filters', false)
25
27
  .option('--includeTags <(string|RegExp)[]>', 'generate code from include tags')
26
28
  .option('--includePaths <(string|RegExp)[]>', 'generate code from include paths')
27
29
  .option('--excludeTags <(string|RegExp)[]>', 'generate code from exclude tags')
@@ -60,6 +62,7 @@ const baseGenerate = (_params_) => {
60
62
  full: JSON.parse(_params_.full) === true,
61
63
  enableLogging: JSON.parse(_params_.enableLogging) === true,
62
64
  priorityRule: _params_.priorityRule,
65
+ filterCaseInsensitive: JSON.parse(_params_.filterCaseInsensitive) === true,
63
66
  includeTags: _params_.includeTags,
64
67
  includePaths: _params_.includePaths,
65
68
  excludeTags: _params_.excludeTags,
@@ -91,19 +91,18 @@ class ServiceGenerator {
91
91
  if (!tag) {
92
92
  return;
93
93
  }
94
- const tagLowerCase = tag.toLowerCase();
95
94
  if (priorityRule === config_1.PriorityRule.include) {
96
95
  // includeTags 为空,不会匹配任何path,故跳过
97
96
  if ((0, lodash_1.isEmpty)(includeTags)) {
98
97
  this.log('priorityRule include need includeTags or includePaths');
99
98
  return;
100
99
  }
101
- if (!this.validateRegexp(tagLowerCase, includeTags)) {
100
+ if (!this.validateRegexp(tag, includeTags)) {
102
101
  return;
103
102
  }
104
103
  }
105
104
  if (priorityRule === config_1.PriorityRule.exclude) {
106
- if (this.validateRegexp(tagLowerCase, excludeTags)) {
105
+ if (this.validateRegexp(tag, excludeTags)) {
107
106
  return;
108
107
  }
109
108
  }
@@ -113,10 +112,8 @@ class ServiceGenerator {
113
112
  this.log('priorityRule both need includeTags or includePaths');
114
113
  return;
115
114
  }
116
- const outIncludeTags = !(0, lodash_1.isEmpty)(includeTags) &&
117
- !this.validateRegexp(tagLowerCase, includeTags);
118
- const inExcludeTags = !(0, lodash_1.isEmpty)(excludeTags) &&
119
- this.validateRegexp(tagLowerCase, excludeTags);
115
+ const outIncludeTags = !(0, lodash_1.isEmpty)(includeTags) && !this.validateRegexp(tag, includeTags);
116
+ const inExcludeTags = !(0, lodash_1.isEmpty)(excludeTags) && this.validateRegexp(tag, excludeTags);
120
117
  if (outIncludeTags || inExcludeTags) {
121
118
  return;
122
119
  }
@@ -276,7 +273,7 @@ class ServiceGenerator {
276
273
  (0, lodash_1.isEmpty)(includePaths)) {
277
274
  return;
278
275
  }
279
- const flag = this.validateRegexp((0, lodash_1.filter)((0, lodash_1.map)(tags, (tag) => (tag === null || tag === void 0 ? void 0 : tag.toLowerCase) ? tag.toLowerCase() : undefined), (tag) => !!tag), includeTags);
276
+ const flag = this.validateRegexp((0, lodash_1.filter)(tags, (tag) => !!tag), includeTags);
280
277
  const pathFlag = this.validateRegexp(pathKey, includePaths);
281
278
  if (!flag || !pathFlag) {
282
279
  return;
@@ -1061,7 +1058,9 @@ class ServiceGenerator {
1061
1058
  // 提取匹配逻辑到单独的函数
1062
1059
  matches(item, reg) {
1063
1060
  if (typeof reg === 'string') {
1064
- return (0, minimatch_1.minimatch)(item, reg);
1061
+ return (0, minimatch_1.minimatch)(item, reg, {
1062
+ nocase: this.config.filterCaseInsensitive,
1063
+ });
1065
1064
  }
1066
1065
  else if (reg instanceof RegExp) {
1067
1066
  reg.lastIndex = 0; // 重置正则表达式的 lastIndex 属性
package/dist/index.d.ts CHANGED
@@ -32,6 +32,10 @@ export type GenerateServiceProps = {
32
32
  * 优先规则, include(只允许include列表) | exclude(只排除exclude列表) | both(允许include列表,排除exclude列表)
33
33
  */
34
34
  priorityRule?: IPriorityRule;
35
+ /**
36
+ * includeTags、includePaths、excludeTags、excludePaths 过滤器执行时是否忽略大小写
37
+ */
38
+ filterCaseInsensitive?: boolean;
35
39
  /**
36
40
  * 只解析归属于 tags 集合的 api 和 schema
37
41
  */
package/dist/index.js CHANGED
@@ -34,7 +34,7 @@ function generateService(_a) {
34
34
  }
35
35
  const requestImportStatement = (0, util_1.getImportStatement)(requestLibPath);
36
36
  const serviceGenerator = new serviceGenarator_1.default(Object.assign({ schemaPath, serversPath: './src/apis', requestImportStatement, enableLogging: false, priorityRule, includeTags: includeTags
37
- ? (0, lodash_1.map)(includeTags, (item) => (0, lodash_1.isString)(item) ? item.toLowerCase() : item)
37
+ ? includeTags
38
38
  : priorityRule === config_1.PriorityRule.include ||
39
39
  priorityRule === config_1.PriorityRule.both
40
40
  ? [/.*/g]
@@ -43,9 +43,7 @@ function generateService(_a) {
43
43
  : priorityRule === config_1.PriorityRule.include ||
44
44
  priorityRule === config_1.PriorityRule.both
45
45
  ? [/.*/g]
46
- : null, excludeTags: excludeTags
47
- ? (0, lodash_1.map)(excludeTags, (item) => (0, lodash_1.isString)(item) ? item.toLowerCase() : item)
48
- : null, excludePaths: excludePaths ? excludePaths : null, requestOptionsType: '{[key: string]: unknown}', namespace: 'API', isGenReactQuery: false, reactQueryMode, isGenJavaScript: false, isDisplayTypeLabel: false, isGenJsonSchemas: false, nullable: false, isOnlyGenTypeScriptType: false, isCamelCase: true, isSupportParseEnumDesc: false, full: true }, rest), openAPI);
46
+ : null, excludeTags: excludeTags ? excludeTags : null, excludePaths: excludePaths ? excludePaths : null, requestOptionsType: '{[key: string]: unknown}', namespace: 'API', isGenReactQuery: false, reactQueryMode, isGenJavaScript: false, isDisplayTypeLabel: false, isGenJsonSchemas: false, nullable: false, isOnlyGenTypeScriptType: false, isCamelCase: true, isSupportParseEnumDesc: false, full: true }, rest), openAPI);
49
47
  serviceGenerator.genFile();
50
48
  if (mockFolder) {
51
49
  (0, mockGenarator_1.mockGenerator)({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "1.7.3",
3
+ "version": "1.8.0",
4
4
  "description": "Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",
@@ -60,7 +60,7 @@ import * as apis from './{{ className }}';
60
60
  {%- endif -%}
61
61
  ) {
62
62
  return queryOptions({
63
- queryFn: async ({ queryKey }) => {
63
+ queryFn: ({ queryKey }) => {
64
64
  return apis.{{ api.functionName }}(queryKey[1]{{ " as typeof options" if genType === "ts" }});
65
65
  },
66
66
  queryKey: ['{{ api.functionName }}', options],
@@ -12,7 +12,7 @@
12
12
  {{ api.data }}
13
13
  {% else %}
14
14
  /** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{ api.method | upper }} {{ api.pathInComment | safe }}{{ ' ' if api.apifoxRunLink else '' }}{{ api.apifoxRunLink }} */
15
- export async function {{ api.functionName }}({
15
+ export function {{ api.functionName }}({
16
16
  {%- if api.params and api.hasParams %}
17
17
  params
18
18
  {%- if api.hasParams -%}