@acrool/rtk-query-codegen-openapi 1.2.0-alpha.0 → 1.2.0-alpha.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.
@@ -60,8 +60,17 @@ export class ApiCodeGenerator {
60
60
  // 步驟 6: 收集操作名稱
61
61
  const operationNames = endpointInfos.map(info => info.operationName);
62
62
 
63
+ // 步驟 7: 收集所有 tags
64
+ const allTags = new Set<string>();
65
+ endpointInfos.forEach(info => {
66
+ if (info.tags && Array.isArray(info.tags)) {
67
+ info.tags.forEach((tag: string) => allTags.add(tag));
68
+ }
69
+ });
70
+
63
71
  return {
64
72
  operationNames,
73
+ tags: Array.from(allTags),
65
74
  files: {
66
75
  types: typesContent,
67
76
  queryService: rtkQueryContent, // RTK Query 檔案
@@ -11,6 +11,7 @@ import { generateDoNotModifyFile } from '../generators/do-not-modify-generator';
11
11
  import type { GenerationOptions, CommonOptions } from '../types';
12
12
  import { ApiCodeGenerator } from './api-code-generator';
13
13
  import { generateUtilsFile } from '../generators/utils-generator';
14
+ import { generateTagTypesFile } from '../generators/tag-types-generator';
14
15
 
15
16
  /**
16
17
  * 統一代碼生成器選項
@@ -68,14 +69,19 @@ export class UnifiedCodeGenerator {
68
69
  componentSchema: string;
69
70
  doNotModify: string;
70
71
  utils: string;
72
+ tagTypes: string;
71
73
  } = {
72
74
  groups: [],
73
75
  commonTypes: '',
74
76
  componentSchema: '',
75
77
  doNotModify: '',
76
- utils: ''
78
+ utils: '',
79
+ tagTypes: ''
77
80
  };
78
81
 
82
+ // 收集所有 tags
83
+ private allTags: Set<string> = new Set();
84
+
79
85
 
80
86
  constructor(options: UnifiedGenerationOptions) {
81
87
  this._options = options;
@@ -98,6 +104,7 @@ export class UnifiedCodeGenerator {
98
104
  this.generateSchemaContent()
99
105
  this.generateUtilsContent()
100
106
  this.generateDoNotModifyContent()
107
+ this.generateTagTypesContent()
101
108
 
102
109
  return await this.release();
103
110
  }
@@ -176,6 +183,11 @@ export class UnifiedCodeGenerator {
176
183
  outputPath: groupInfo.outputPath,
177
184
  content: groupContent
178
185
  });
186
+
187
+ // 收集此群組的所有 tags
188
+ if (groupContent.tags && Array.isArray(groupContent.tags)) {
189
+ groupContent.tags.forEach((tag: string) => this.allTags.add(tag));
190
+ }
179
191
  }
180
192
  // 如果沒有任何 endpoint,則跳過此群組,不創建資料夾
181
193
  } catch (error) {
@@ -217,6 +229,14 @@ export class UnifiedCodeGenerator {
217
229
  this.generatedContent.utils = generateUtilsFile();
218
230
  }
219
231
 
232
+ /**
233
+ * 生成 Tag Types
234
+ */
235
+ private async generateTagTypesContent(): Promise<void> {
236
+ const tagsArray = Array.from(this.allTags);
237
+ this.generatedContent.tagTypes = generateTagTypesFile(tagsArray);
238
+ }
239
+
220
240
 
221
241
 
222
242
 
@@ -273,6 +293,15 @@ export class UnifiedCodeGenerator {
273
293
  results.push(...sharedResults);
274
294
  }
275
295
 
296
+ // 寫入 tagTypes.ts
297
+ if (this.generatedContent.tagTypes) {
298
+ const tagTypesResult = await this.fileWriterService.writeFile(
299
+ path.join(outputDir, 'tagTypes.ts'),
300
+ this.generatedContent.tagTypes
301
+ );
302
+ results.push(tagTypesResult);
303
+ }
304
+
276
305
  // 寫入 component schema
277
306
  if (this.generatedContent.componentSchema) {
278
307
  const schemaResults = await this.fileWriterService.writeSchemaFile(
package/src/types.ts CHANGED
@@ -73,15 +73,6 @@ export interface CommonOptions {
73
73
  file: string;
74
74
  importReturnTypeName: string; // 用於指定別名導入,例如 IRestFulEndpointsQueryReturn
75
75
  };
76
- /**
77
- * Cache tag types configuration for RTK Query cache invalidation
78
- * If provided, will import the specified type from the given file in enhanceEndpoints.ts
79
- * Example: { file: "@/store/tagTypes", importName: "ECacheTagTypes" }
80
- */
81
- cacheTagTypes?: {
82
- file: string;
83
- importReturnTypeName: string;
84
- };
85
76
  /**
86
77
  * defaults to "enhancedApi"
87
78
  */
@@ -206,6 +197,7 @@ export type ConfigFile =
206
197
 
207
198
  export type GenerateApiResult = {
208
199
  operationNames: string[];
200
+ tags: string[]; // 收集到的所有 tags
209
201
  files: {
210
202
  types: string;
211
203
  queryService: string; // RTK Query generated file