Skip to content

Commit 2c70f78

Browse files
authored
chore: rename allowedPaths and allowedTags (#113)
* chore: rename allowedTags => includeTags, allowedPaths => includePaths
1 parent 09c2731 commit 2c70f78

File tree

16 files changed

+295
-255
lines changed

16 files changed

+295
-255
lines changed

.changeset/rich-trees-applaud.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'openapi-ts-request': minor
3+
---
4+
5+
rename allowedPath and allowedTags

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
### Patch Changes
5454

55-
- [`430c164`](https://github.com/openapi-ui/openapi-ts-request/commit/430c1648fa0cb1737ed83f762bff434678488c50) Thanks [@rookie-luochao](https://github.com/rookie-luochao)! - fix: fix $ref includes encode character causing allowedTags function error
55+
- [`430c164`](https://github.com/openapi-ui/openapi-ts-request/commit/430c1648fa0cb1737ed83f762bff434678488c50) Thanks [@rookie-luochao](https://github.com/rookie-luochao)! - fix: fix $ref includes encode character causing includeTags function error
5656

5757
## 0.8.2
5858

README-en_US.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ $ openapi --help
137137
-i, --input <string> OpenAPI specification, can be a path, url (required)
138138
-o, --output <string> output directory (required)
139139
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch", default is "axios"
140-
--allowedTags <string[]> generate code from allowed tags
140+
--enableLogging <boolean> open the log
141+
--priorityRule <string> priority rule, include/exclude/both
142+
--includeTags <string|RegExp>[] generate code from include tags
143+
--includePaths <string|RegExp>[] generate code from include paths
144+
--excludeTags <string|RegExp>[] generate code from exclude tags
145+
--excludePaths <string|RegExp>[] generate code from exclude paths
141146
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
142147
string]: unknown }")
143148
--requestImportStatement <string> custom request import statement, for example: "const request =
@@ -168,7 +173,12 @@ openapi -i ./spec.json -o ./apis
168173
| schemaPath | yes | string | - | Swagger2/OpenAPI3 URL |
169174
| serversPath | no | string | './src/apis' | the folder path for the generated results |
170175
| requestLibPath | no | string | 'axios' | custom request lib path, for example: '@/request', 'node-fetch' |
171-
| allowedTags | no | string[] | - | generate code from allowed tags |
176+
| enableLogging | no | boolean | false | open the log |
177+
| priorityRule | no | string | 'include' | priority rule, include/exclude/both |
178+
| includeTags | no | (string\|RegExp)[] | - | generate code from include tags, priorityRule=include required |
179+
| includePaths | no | (string\|RegExp)[] | - | generate code from include paths |
180+
| excludeTags | no | (string\|RegExp)[] | - | generate code from exclude tags |
181+
| excludePaths | no | (string\|RegExp)[] | - | generate code from exclude paths |
172182
| requestOptionsType | no | string | '{ [key: string]: unknown }' | custom request method options parameter type |
173183
| requestImportStatement | no | string | - | custom request import statement, for example: "const request = require('@/request')" |
174184
| apiPrefix | no | string | - | custom the prefix of the api path, for example: 'api'(variable), "'api'"(string) |

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,12 @@ $ openapi --help
137137
-i, --input <string> OpenAPI specification, can be a path, url (required)
138138
-o, --output <string> output directory (required)
139139
--requestLibPath <string> custom request lib path, for example: "@/request", "node-fetch", default is "axios"
140-
--allowedTags <string[]> generate code from allowed tags
140+
--enableLogging <boolean> open the log
141+
--priorityRule <string> priority rule, include/exclude/both
142+
--includeTags <string|RegExp>[] generate code from include tags
143+
--includePaths <string|RegExp>[] generate code from include paths
144+
--excludeTags <string|RegExp>[] generate code from exclude tags
145+
--excludePaths <string|RegExp>[] generate code from exclude paths
141146
--requestOptionsType <string> custom request method options parameter type (default: "{ [key:
142147
string]: unknown }")
143148
--requestImportStatement <string> custom request import statement, for example: "const request =
@@ -169,9 +174,9 @@ openapi --i ./spec.json --o ./apis
169174
| serversPath || string | './src/apis' | 生成结果的文件夹路径 |
170175
| requestLibPath || string | 'axios' | 自定义请求方法路径,例如:'@/request'、'node-fetch' |
171176
| enableLogging || boolean | false | 是否开启日志 |
172-
| priorityRule || string | 'exclude' | 模式规则,可选allowed/exclude/include |
173-
| allowedTags || (string\|RegExp)[] | - | 根据指定的 tags 生成代码 |
174-
| allowedPaths || (string\|RegExp)[] | - | 根据指定的 paths 生成代码 |
177+
| priorityRule || string | 'include' | 模式规则,可选include/exclude/both |
178+
| includeTags || (string\|RegExp)[] | - | 根据指定的 tags 生成代码, priorityRule=include则必填 |
179+
| includePaths || (string\|RegExp)[] | - | 根据指定的 paths 生成代码 |
175180
| excludeTags || (string\|RegExp)[] | - | 根据指定的 tags 不生成代码 |
176181
| excludePaths || (string\|RegExp)[] | - | 根据指定的 paths 不生成代码 |
177182
| requestOptionsType || string | '{ [key: string]: unknown }' | 自定义请求方法 options 参数类型 |

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bin/openapi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const params = program
1818
'--requestLibPath <string>',
1919
'custom request lib path, for example: "@/request", "node-fetch", default is "axios"'
2020
)
21-
.option('--allowedTags <string[]>', 'generate results from allowed tags')
21+
.option('--includeTags <string[]>', 'generate results from include tags')
2222
.option(
2323
'--requestOptionsType <string>',
2424
'custom request method options parameter type (default: "{ [key: string]: unknown }")'
@@ -77,7 +77,7 @@ async function run() {
7777
schemaPath: input,
7878
serversPath: output,
7979
requestLibPath: params.requestLibPath as string,
80-
allowedTags: params.allowedTags as string[],
80+
includeTags: params.includeTags as string[],
8181
requestOptionsType: params.requestOptionsType as string,
8282
apiPrefix: params.apiPrefix as string,
8383
isDisplayTypeLabel:

src/generator/serviceGenarator.ts

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -107,20 +107,20 @@ export default class ServiceGenerator {
107107
};
108108
this.generateInfoLog();
109109

110-
const allowedPaths = this.config?.allowedPaths || [];
111-
const allowedTags = this.config?.allowedTags || [];
110+
const includePaths = this.config?.includePaths || [];
111+
const includeTags = this.config?.includeTags || [];
112112
const excludePaths = this.config?.excludePaths || [];
113113
const excludeTags = this.config?.excludeTags || [];
114114

115115
const priorityRule: PriorityRule =
116116
PriorityRule[config.priorityRule as keyof typeof PriorityRule];
117117

118118
if (
119-
priorityRule === PriorityRule.allowed &&
120-
isEmpty(this.config?.allowedTags) &&
121-
isEmpty(this.config?.allowedPaths)
119+
priorityRule === PriorityRule.include &&
120+
isEmpty(this.config?.includeTags) &&
121+
isEmpty(this.config?.includePaths)
122122
) {
123-
this.log('priorityRule allowed need allowedTags or allowedPaths');
123+
this.log('priorityRule include need includeTags or includePaths');
124124
}
125125
const hookCustomFileNames =
126126
this.config.hook?.customFileNames || getDefaultFileTag;
@@ -136,16 +136,16 @@ export default class ServiceGenerator {
136136
for (const pathKey in this.openAPIData.paths) {
137137
// 这里判断paths
138138
switch (priorityRule) {
139-
case PriorityRule.allowed: {
140-
// allowedPaths and allowedTags is empty 没有任何allowed配置,直接跳过这个数组的所有元素
141-
if (isEmpty(allowedTags) && isEmpty(allowedPaths)) {
142-
this.log('priorityRule allowed need allowedTags or allowedPaths');
139+
case PriorityRule.include: {
140+
// includePaths and includeTags is empty 没有任何include配置,直接跳过这个数组的所有元素
141+
if (isEmpty(includeTags) && isEmpty(includePaths)) {
142+
this.log('priorityRule include need includeTags or includePaths');
143143
continue;
144144
}
145145

146146
if (
147-
!isEmpty(allowedPaths) &&
148-
!allowedPaths.some((pathRule) =>
147+
!isEmpty(includePaths) &&
148+
!includePaths.some((pathRule) =>
149149
typeof pathRule === 'string'
150150
? minimatch(pathKey, pathRule)
151151
: pathRule.test(pathKey)
@@ -167,16 +167,16 @@ export default class ServiceGenerator {
167167
}
168168
break;
169169
}
170-
case PriorityRule.include: {
171-
// allowedPaths is empty 没有配置,直接跳过
172-
if (isEmpty(allowedTags) && isEmpty(allowedPaths)) {
173-
this.log('priorityRule include need allowedTags or allowedPaths');
170+
case PriorityRule.both: {
171+
// includePaths is empty 没有配置,直接跳过
172+
if (isEmpty(includeTags) && isEmpty(includePaths)) {
173+
this.log('priorityRule include need includeTags or includePaths');
174174
continue;
175175
}
176176

177-
const inAllowedPaths =
178-
!isEmpty(allowedPaths) &&
179-
!allowedPaths.some((path) =>
177+
const inIncludePaths =
178+
!isEmpty(includePaths) &&
179+
!includePaths.some((path) =>
180180
typeof path === 'string'
181181
? minimatch(pathKey, path)
182182
: path.test(pathKey)
@@ -189,14 +189,14 @@ export default class ServiceGenerator {
189189
: path.test(pathKey)
190190
);
191191

192-
if (inAllowedPaths || inExcludePaths) {
192+
if (inIncludePaths || inExcludePaths) {
193193
continue;
194194
}
195195
break;
196196
}
197197
default:
198198
throw new Error(
199-
'priorityRule must be "allowed" or "exclude" or "include"'
199+
'priorityRule must be "include" or "exclude" or "include"'
200200
);
201201
}
202202

@@ -219,19 +219,19 @@ export default class ServiceGenerator {
219219
tags.forEach((tag) => {
220220
const tagLowerCase = tag.toLowerCase();
221221

222-
if (priorityRule === PriorityRule.allowed) {
223-
// allowedTags 为空, 不会匹配任何path,故跳过; allowedTagsallowedPaths 同时为空则没意义,故跳过;
222+
if (priorityRule === PriorityRule.include) {
223+
// includeTags 为空, 不会匹配任何path,故跳过; includeTagsincludePaths 同时为空则没意义,故跳过;
224224
if (
225-
isEmpty(allowedTags) ||
226-
(isEmpty(allowedTags) && isEmpty(allowedPaths))
225+
isEmpty(includeTags) ||
226+
(isEmpty(includeTags) && isEmpty(includePaths))
227227
) {
228-
this.log('priorityRule include need allowedTags or allowedPaths');
228+
this.log('priorityRule include need includeTags or includePaths');
229229
return;
230230
}
231231

232232
if (
233-
!isEmpty(allowedTags) &&
234-
!allowedTags.some((tagRule) =>
233+
!isEmpty(includeTags) &&
234+
!includeTags.some((tagRule) =>
235235
typeof tagRule === 'string'
236236
? minimatch(tagLowerCase, tagRule)
237237
: tagRule.test(tagLowerCase)
@@ -253,16 +253,16 @@ export default class ServiceGenerator {
253253
}
254254
}
255255

256-
if (priorityRule === PriorityRule.include) {
257-
// allowedTags is empty 没有配置,直接跳过
258-
if (isEmpty(allowedTags)) {
259-
this.log('priorityRule include need allowedTags or allowedPaths');
256+
if (priorityRule === PriorityRule.both) {
257+
// includeTags is empty 没有配置,直接跳过
258+
if (isEmpty(includeTags)) {
259+
this.log('priorityRule include need includeTags or includePaths');
260260
return;
261261
}
262262

263-
const inAllowedTags =
264-
!isEmpty(allowedTags) &&
265-
!allowedTags.some((tagRule) =>
263+
const inincludeTags =
264+
!isEmpty(includeTags) &&
265+
!includeTags.some((tagRule) =>
266266
typeof tagRule === 'string'
267267
? minimatch(tagLowerCase, tagRule)
268268
: tagRule.test(tagLowerCase)
@@ -274,7 +274,7 @@ export default class ServiceGenerator {
274274
? minimatch(tagLowerCase, tagRule)
275275
: tagRule.test(tagLowerCase)
276276
);
277-
if (inAllowedTags || inExcludeTags) {
277+
if (inincludeTags || inExcludeTags) {
278278
return;
279279
}
280280
}
@@ -451,13 +451,13 @@ export default class ServiceGenerator {
451451

452452
// 筛选出 pathItem 包含的 $ref 对应的schema
453453
if (
454-
!isEmpty(this.config?.allowedTags) &&
454+
!isEmpty(this.config?.includeTags) &&
455455
!isEmpty(operationObject.tags)
456456
) {
457457
if (
458458
!isEmpty(
459459
intersection(
460-
this.config.allowedTags,
460+
this.config.includeTags,
461461
map(operationObject.tags, (tag) => tag.toLowerCase())
462462
)
463463
)
@@ -548,7 +548,7 @@ export default class ServiceGenerator {
548548

549549
// 判断哪些 schema 需要添加进 type, schemas 渲染数组
550550
if (
551-
isEmpty(this.config.allowedTags) ||
551+
isEmpty(this.config.includeTags) ||
552552
(schema as ICustomSchemaObject)?.isAllowed
553553
) {
554554
const isEnum = result.isEnum as boolean;
@@ -1240,16 +1240,16 @@ export default class ServiceGenerator {
12401240
private generateInfoLog(): void {
12411241
this.log(`priorityRule: ${this.config?.priorityRule}`);
12421242

1243-
if (this.config?.allowedTags) {
1244-
this.log(`allowedTags: ${this.config?.allowedTags.join(', ')}`);
1243+
if (this.config?.includeTags) {
1244+
this.log(`includeTags: ${this.config?.includeTags.join(', ')}`);
12451245
}
12461246

12471247
if (this.config?.excludeTags) {
12481248
this.log(`excludeTags: ${this.config?.excludeTags.join(', ')}`);
12491249
}
12501250

1251-
if (this.config?.allowedPaths) {
1252-
this.log(`allowedPaths: ${this.config?.allowedPaths.join(', ')}`);
1251+
if (this.config?.includePaths) {
1252+
this.log(`includePaths: ${this.config?.includePaths.join(', ')}`);
12531253
}
12541254

12551255
if (this.config?.excludePaths) {

src/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ export type GenerateServiceProps = {
4040
enableLogging?: boolean;
4141
/**
4242
/**
43-
* 优先规则, allowed(只允许allowed列表) | exclude(只排除exclude列表) | include(允许allowed列表,排除exclude列表)
43+
* 优先规则, include(只允许include列表) | exclude(只排除exclude列表) | include(允许include列表,排除exclude列表)
4444
*/
4545
priorityRule?: string;
4646
/**
4747
* 只解析归属于 tags 集合的api 和 schema
4848
*/
49-
allowedTags?: (string | RegExp)[];
49+
includeTags?: (string | RegExp)[];
5050
/**
5151
* 只解析归属于 paths 集合的api
5252
*/
53-
allowedPaths?: (string | RegExp)[];
53+
includePaths?: (string | RegExp)[];
5454
/**
5555
* 不解析归属于 tags 集合的api 和 schema
5656
*/
@@ -199,7 +199,7 @@ export async function generateService({
199199
requestLibPath,
200200
schemaPath,
201201
mockFolder,
202-
allowedTags,
202+
includeTags,
203203
excludeTags,
204204
authorization,
205205
isTranslateToEnglishTag,
@@ -235,8 +235,8 @@ export async function generateService({
235235
isDisplayTypeLabel: false,
236236
isGenJsonSchemas: false,
237237
isOnlyGenTypeScriptType: false,
238-
allowedTags: allowedTags
239-
? map(allowedTags, (item) =>
238+
includeTags: includeTags
239+
? map(includeTags, (item) =>
240240
typeof item === 'string' ? item.toLowerCase() : item
241241
)
242242
: [],
@@ -246,7 +246,7 @@ export async function generateService({
246246
)
247247
: null,
248248
enableLogging: false,
249-
priorityRule: 'allowed',
249+
priorityRule: 'include',
250250
...rest,
251251
},
252252
openAPI

src/type.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,15 @@ export enum SchemaObjectType {
106106
}
107107

108108
export enum PriorityRule {
109-
allowed = 'allowed',
110-
exclude = 'exclude',
111109
include = 'include',
110+
exclude = 'exclude',
111+
both = 'both',
112112
}
113113

114114
export type GenerateRegExp = {
115-
allowedTags: (string | RegExp)[];
115+
includeTags: (string | RegExp)[];
116116
excludeTags: (string | RegExp)[];
117-
allowedPaths: (string | RegExp)[];
117+
includePaths: (string | RegExp)[];
118118
excludePaths: (string | RegExp)[];
119119
};
120120

0 commit comments

Comments
 (0)