swagger-fsd-gen 1.0.2 → 2.0.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,100 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.0.0] - 2025-12-28
9
+
10
+ ### 🎉 Major Release - v2.0
11
+
12
+ 이 릴리스는 여러 새로운 기능과 개선사항을 포함합니다!
13
+
14
+ ### Added
15
+
16
+ - ✨ **HTTP Client Selection**: axios와 ky 중 선택 가능
17
+ - `--http-client` CLI 옵션 추가
18
+ - `httpClient` config 옵션 추가
19
+ - axios와 ky 전용 템플릿 분리
20
+
21
+ - ♾️ **Infinite Query 자동 생성**: 페이지네이션 엔드포인트에 대해 `useInfiniteQuery` 훅 자동 생성
22
+ - `page`, `cursor`, `offset`, `pageToken` 파라미터 자동 감지
23
+ - 페이지네이션 타입에 맞는 `getNextPageParam`, `getPreviousPageParam` 로직 생성
24
+ - 모든 페이지네이션 전략 지원
25
+
26
+ - ⚙️ **Config 파일 지원**: `swagger-codegen.config.js` 파일로 설정 관리
27
+ - Config 파일 자동 로드
28
+ - CLI 인수가 config 파일 설정보다 우선
29
+ - 환경 변수 지원
30
+
31
+ - 👀 **Watch 모드**: 파일 변경 감지 시 자동 재생성
32
+ - `--watch` CLI 옵션 추가
33
+ - 로컬 파일 변경 감지 (chokidar)
34
+ - 원격 URL 폴링 (ETag/Last-Modified)
35
+ - Graceful shutdown 지원
36
+
37
+ - 🎯 **Module Filtering**: 특정 모듈만 선택적으로 생성
38
+ - `--include` 옵션: 특정 모듈만 생성
39
+ - `--exclude` 옵션: 특정 모듈 제외
40
+ - Config 파일에서도 설정 가능
41
+
42
+ ### Changed
43
+
44
+ - 🔄 **Breaking**: HTTP 클라이언트 기본값이 `ky`에서 `axios`로 변경
45
+ - 기존 ky 사용자는 `httpClient: 'ky'` 설정 필요
46
+
47
+ - 📁 **템플릿 구조 재구성**
48
+ - `templates/modular/axios/` - axios 전용 템플릿
49
+ - `templates/modular/ky/` - ky 전용 템플릿
50
+ - `templates/tanstack-query/axios/` - axios mutation 템플릿
51
+ - `templates/tanstack-query/ky/` - ky mutation 템플릿
52
+
53
+ - 📦 **의존성 업데이트**
54
+ - `chokidar@^3.5.3` 추가 (watch 모드)
55
+
56
+ ### Migration
57
+
58
+ **v1.x에서 v2.0으로 마이그레이션:**
59
+
60
+ 기존 ky 사용자는 config 파일에 다음 설정을 추가하세요:
61
+
62
+ ```javascript
63
+ // swagger-codegen.config.js
64
+ export default {
65
+ httpClient: 'ky',
66
+ };
67
+ ```
68
+
69
+ 새로운 사용자는 별도 설정 없이 axios가 기본값으로 사용됩니다.
70
+
71
+ ## [1.0.2] - 2024-XX-XX
72
+
73
+ ### Fixed
74
+
75
+ - 프로젝트의 prettier 설정 자동 적용
76
+
77
+ ## [1.0.1] - 2024-XX-XX
78
+
79
+ ### Changed
80
+
81
+ - README.md 업데이트
82
+ - package.json 메타데이터 개선
83
+
84
+ ## [1.0.0] - 2024-XX-XX
85
+
86
+ ### Added
87
+
88
+ - 🎉 Initial release
89
+ - ky HTTP 클라이언트 기반 API 생성
90
+ - TanStack Query 훅 생성 (useQuery, useMutation)
91
+ - FSD 패턴 지원
92
+ - TypeScript 완전 지원
93
+ - Prettier 설정 자동 적용
94
+
95
+ ---
96
+
97
+ [2.0.0]: https://github.com/sen-jik/swagger-autogen/compare/v1.0.2...v2.0.0
98
+ [1.0.2]: https://github.com/sen-jik/swagger-autogen/compare/v1.0.1...v1.0.2
99
+ [1.0.1]: https://github.com/sen-jik/swagger-autogen/compare/v1.0.0...v1.0.1
100
+ [1.0.0]: https://github.com/sen-jik/swagger-autogen/releases/tag/v1.0.0
package/README.md CHANGED
@@ -1,12 +1,19 @@
1
1
  # swagger-fsd-gen
2
2
 
3
- Swagger/OpenAPI 문서를 기반으로 **ky + TanStack Query + FSD(Feature-Sliced Design) 패턴**에 맞는 API 클라이언트를 자동으로 생성하는 도구입니다.
3
+ Swagger/OpenAPI 문서를 기반으로 **axios/ky + TanStack Query (with Infinite Query) + FSD(Feature-Sliced Design) 패턴**에 맞는 API 클라이언트를 자동으로 생성하는 도구입니다.
4
4
 
5
5
  ## ✨ 주요 기능
6
6
 
7
- - 🚀 **ky HTTP 클라이언트** 기반 API 클래스 자동 생성
8
- - 🔄 **TanStack Query** 자동 생성 (useQuery, useMutation)
7
+ - 🔄 **HTTP 클라이언트 선택** - axios 또는 ky 중 선택 가능
8
+ - 🚀 **TanStack Query 완벽 지원**
9
+ - `useQuery` - 일반 조회
10
+ - `useSuspenseQuery` - Suspense 기반 조회
11
+ - `useInfiniteQuery` - 페이지네이션 자동 생성 ⭐ NEW
12
+ - `useMutation` - 데이터 변경
9
13
  - 📁 **FSD(Feature-Sliced Design)** 패턴 자동 적용
14
+ - ⚙️ **Config 파일 지원** - `swagger-codegen.config.js`로 설정 관리
15
+ - 👀 **Watch 모드** - 파일 변경 감지 자동 재생성
16
+ - 🎯 **Module Filtering** - 특정 모듈만 선택적으로 생성
10
17
  - 🔐 **HTTP Basic Authentication** 지원
11
18
  - 📝 **TypeScript** 완전 지원 (타입 안전성)
12
19
  - 🎨 **프로젝트의 Prettier 설정** 자동 적용
@@ -19,43 +26,95 @@ npm install -D swagger-fsd-gen
19
26
 
20
27
  # yarn
21
28
  yarn add -D swagger-fsd-gen
29
+
30
+ # pnpm
31
+ pnpm add -D swagger-fsd-gen
22
32
  ```
23
33
 
24
- ## 🚀 사용 방법
34
+ ## 🚀 빠른 시작
35
+
36
+ ### 1. Config 파일 생성 (권장)
37
+
38
+ 프로젝트 루트에 `swagger-codegen.config.js` 파일을 생성합니다:
39
+
40
+ ```javascript
41
+ export default {
42
+ // Swagger 문서 URL
43
+ uri: process.env.SWAGGER_URL || 'http://localhost:8000/api-json',
25
44
 
26
- ### 1. 직접 실행
45
+ // HTTP 클라이언트 선택 (axios 또는 ky)
46
+ httpClient: 'axios', // 기본값
47
+
48
+ // Basic Auth (선택사항)
49
+ username: process.env.SWAGGER_USERNAME,
50
+ password: process.env.SWAGGER_PASSWORD,
51
+
52
+ // 출력 경로 커스터마이징 (선택사항)
53
+ output: {
54
+ dto: 'src/shared/api/dto.ts',
55
+ api: 'src/entities/{moduleName}/api/index.ts',
56
+ instance: 'src/entities/{moduleName}/api/instance.ts',
57
+ queries: 'src/entities/{moduleName}/api/queries.ts',
58
+ mutations: 'src/entities/{moduleName}/api/mutations.ts',
59
+ },
60
+
61
+ // Module Filtering (선택사항)
62
+ // include: ['user', 'campaign'], // 특정 모듈만 생성
63
+ // exclude: ['admin', 'internal'], // 특정 모듈 제외
64
+ };
65
+ ```
66
+
67
+ ### 2. 코드 생성
27
68
 
28
69
  ```bash
29
70
  # npm
30
- npx fetch-swagger --url https://api.example.com/swagger.json --username your-username --password your-password
31
- npx generate-all --uri https://api.example.com/swagger.json --username your-username --password your-password
71
+ npx generate-all
32
72
 
33
73
  # yarn
34
- yarn fetch-swagger --url https://api.example.com/swagger.json --username your-username --password your-password
35
- yarn generate-all --uri https://api.example.com/swagger.json --username your-username --password your-password
74
+ yarn generate-all
75
+
76
+ # pnpm
77
+ pnpm generate-all
78
+ ```
79
+
80
+ ## 📋 사용 방법
81
+
82
+ ### CLI로 직접 실행
83
+
84
+ ```bash
85
+ # 기본 사용법
86
+ generate-all --uri https://api.example.com/swagger.json
87
+
88
+ # HTTP 클라이언트 지정
89
+ generate-all --uri https://api.example.com/swagger.json --http-client ky
90
+
91
+ # Watch 모드 (자동 재생성)
92
+ generate-all --uri https://api.example.com/swagger.json --watch
93
+
94
+ # Module Filtering
95
+ generate-all --uri https://api.example.com/swagger.json --include user,campaign
96
+ generate-all --uri https://api.example.com/swagger.json --exclude admin,internal
97
+
98
+ # Basic Auth
99
+ generate-all --uri https://api.example.com/swagger.json --username admin --password secret
36
100
  ```
37
101
 
38
- ### 2. package.json 스크립트 추가 (권장)
102
+ ### package.json 스크립트 (권장)
39
103
 
40
104
  ```json
41
105
  {
42
106
  "scripts": {
43
- "fetch-swagger": "fetch-swagger --url https://api.example.com/swagger.json --username your-username --password your-password",
44
- "generate-all": "generate-all --uri https://api.example.com/swagger.json --username your-username --password your-password"
107
+ "codegen": "generate-all",
108
+ "codegen:watch": "generate-all --watch"
45
109
  }
46
110
  }
47
111
  ```
48
112
 
49
- 그리고 실행:
113
+ 실행:
50
114
 
51
115
  ```bash
52
- # npm
53
- npm run fetch-swagger
54
- npm run generate-all
55
-
56
- # yarn
57
- yarn fetch-swagger
58
- yarn generate-all
116
+ npm run codegen
117
+ npm run codegen:watch
59
118
  ```
60
119
 
61
120
  ## 📁 생성되는 파일 구조
@@ -74,28 +133,325 @@ src/
74
133
  └── mutations.ts # TanStack Mutation 훅
75
134
  ```
76
135
 
77
- ## ⚙️ 옵션
136
+ ## 🔄 HTTP 클라이언트 선택
137
+
138
+ ### axios (기본값)
139
+
140
+ ```javascript
141
+ export default {
142
+ httpClient: 'axios',
143
+ };
144
+ ```
78
145
 
79
- ### fetch-swagger
146
+ **장점:**
147
+ - ✅ 가장 인기 있는 HTTP 클라이언트
148
+ - ✅ 훌륭한 TypeScript 지원
149
+ - ✅ Request/Response 인터셉터
150
+ - ✅ 더 나은 에러 핸들링
151
+ - ✅ 취소 토큰 지원
152
+
153
+ ### ky
154
+
155
+ ```javascript
156
+ export default {
157
+ httpClient: 'ky',
158
+ };
159
+ ```
80
160
 
81
- | 옵션 | 설명 | 필수 |
82
- | ---------- | ------------------- | ---- |
83
- | --url | Swagger 문서 URL | ✅ |
84
- | --username | Basic Auth 사용자명 | - |
85
- | --password | Basic Auth 비밀번호 | - |
161
+ **장점:**
162
+ - 경량 (axios 대비 10배 작음)
163
+ - 모던한 fetch 기반
164
+ - 내장 재시도 기능
165
+ - 깔끔한 API
166
+
167
+ ## ♾️ Infinite Query 자동 생성
168
+
169
+ 페이지네이션이 있는 엔드포인트는 `useInfiniteQuery` 훅이 자동으로 생성됩니다!
170
+
171
+ ### 지원되는 페이지네이션 파라미터
172
+
173
+ 다음 쿼리 파라미터 중 하나라도 있으면 자동으로 Infinite Query가 생성됩니다:
174
+
175
+ - `page` - 페이지 기반 (`?page=1`)
176
+ - `cursor` - 커서 기반 (`?cursor=abc`)
177
+ - `offset` - 오프셋 기반 (`?offset=0&limit=20`)
178
+ - `pageToken` - 토큰 기반 (`?pageToken=xyz`)
179
+
180
+ ### 사용 예시
181
+
182
+ **Swagger 정의:**
183
+
184
+ ```yaml
185
+ /api/campaigns:
186
+ get:
187
+ parameters:
188
+ - name: page
189
+ in: query
190
+ schema:
191
+ type: integer
192
+ - name: category
193
+ in: query
194
+ schema:
195
+ type: string
196
+ ```
197
+
198
+ **생성된 코드 (queries.ts):**
199
+
200
+ ```typescript
201
+ // 일반 Query
202
+ export const useGetCampaignsQuery = (params?: { page?: number; category?: string }) => {
203
+ return useQuery({
204
+ queryKey: ['campaigns', params],
205
+ queryFn: () => campaignApi.getCampaigns(params),
206
+ });
207
+ };
208
+
209
+ // ⭐ Infinite Query (자동 생성!)
210
+ export const useGetCampaignsInfiniteQuery = (
211
+ params?: { category?: string }, // page는 제외됨
212
+ options?: UseInfiniteQueryOptions
213
+ ) => {
214
+ return useInfiniteQuery({
215
+ queryKey: ['campaigns', params],
216
+ queryFn: ({ pageParam }) => campaignApi.getCampaigns({ ...params, page: pageParam }),
217
+ initialPageParam: 1,
218
+ getNextPageParam: (lastPage) => {
219
+ if (!lastPage?.hasNext) return undefined;
220
+ return (lastPage?.page ?? 0) + 1;
221
+ },
222
+ getPreviousPageParam: (firstPage) => {
223
+ if ((firstPage?.page ?? 1) <= 1) return undefined;
224
+ return (firstPage?.page ?? 1) - 1;
225
+ },
226
+ ...options,
227
+ });
228
+ };
229
+ ```
230
+
231
+ **컴포넌트에서 사용:**
232
+
233
+ ```tsx
234
+ function CampaignList() {
235
+ const { data, fetchNextPage, hasNextPage, isFetching } = useGetCampaignsInfiniteQuery({
236
+ category: 'food',
237
+ });
238
+
239
+ return (
240
+ <div>
241
+ {data?.pages.map(page =>
242
+ page.items.map(campaign => (
243
+ <CampaignCard key={campaign.id} {...campaign} />
244
+ ))
245
+ )}
246
+
247
+ {hasNextPage && (
248
+ <button onClick={() => fetchNextPage()} disabled={isFetching}>
249
+ 더 보기
250
+ </button>
251
+ )}
252
+ </div>
253
+ );
254
+ }
255
+ ```
256
+
257
+ ## 👀 Watch 모드
258
+
259
+ 개발 중 Swagger 문서가 변경될 때 자동으로 코드를 재생성합니다.
260
+
261
+ ```bash
262
+ # CLI
263
+ generate-all --watch
264
+
265
+ # Config
266
+ {
267
+ "scripts": {
268
+ "codegen:watch": "generate-all --watch"
269
+ }
270
+ }
271
+ ```
86
272
 
87
- ### generate-all
273
+ **특징:**
274
+ - 로컬 파일: `chokidar`로 변경 감지
275
+ - 원격 URL: 10초마다 ETag/Last-Modified 체크
88
276
 
89
- | 옵션 | 설명 | 기본값 |
90
- | ---------------------- | --------------------- | ------------------------------------------ |
91
- | --uri | Swagger 문서 URL/경로 | 필수 |
92
- | --username | Basic Auth 사용자명 | - |
93
- | --password | Basic Auth 비밀번호 | - |
94
- | --dto-output-path | DTO 파일 경로 | src/shared/api/dto.ts |
95
- | --api-output-path | API 클래스 경로 | src/entities/{moduleName}/api/index.ts |
96
- | --query-output-path | Query 훅 경로 | src/entities/{moduleName}/api/queries.ts |
97
- | --mutation-output-path | Mutation 훅 경로 | src/entities/{moduleName}/api/mutations.ts |
277
+ ## 🎯 Module Filtering
278
+
279
+ 필요한 모듈만 선택적으로 생성할 있습니다.
280
+
281
+ ### Include (특정 모듈만 생성)
282
+
283
+ ```javascript
284
+ export default {
285
+ include: ['user', 'campaign', 'schedule'],
286
+ };
287
+ ```
288
+
289
+ 또는
290
+
291
+ ```bash
292
+ generate-all --include user,campaign,schedule
293
+ ```
294
+
295
+ ### Exclude (특정 모듈 제외)
296
+
297
+ ```javascript
298
+ export default {
299
+ exclude: ['admin', 'internal'],
300
+ };
301
+ ```
302
+
303
+ 또는
304
+
305
+ ```bash
306
+ generate-all --exclude admin,internal
307
+ ```
308
+
309
+ **주의:** `include`와 `exclude`는 동시에 사용할 수 없습니다.
310
+
311
+ ## ⚙️ 전체 옵션
312
+
313
+ ### CLI 옵션
314
+
315
+ | 옵션 | 단축키 | 설명 | 기본값 |
316
+ | ----------------------------- | ------ | ------------------------------------------- | --------------------------------------------- |
317
+ | `--uri` | `-u` | Swagger 문서 URL/경로 | 필수 |
318
+ | `--http-client` | `-hc` | HTTP 클라이언트 (axios/ky) | `axios` |
319
+ | `--username` | `-un` | Basic Auth 사용자명 | - |
320
+ | `--password` | `-pw` | Basic Auth 비밀번호 | - |
321
+ | `--dto-output-path` | `-dp` | DTO 파일 경로 | `src/shared/api/dto.ts` |
322
+ | `--api-output-path` | `-ap` | API 클래스 경로 | `src/entities/{moduleName}/api/index.ts` |
323
+ | `--api-instance-output-path` | `-aip` | API 인스턴스 경로 | `src/entities/{moduleName}/api/instance.ts` |
324
+ | `--query-output-path` | `-qp` | Query 훅 경로 | `src/entities/{moduleName}/api/queries.ts` |
325
+ | `--mutation-output-path` | `-mp` | Mutation 훅 경로 | `src/entities/{moduleName}/api/mutations.ts` |
326
+ | `--project-template` | `-pt` | 커스텀 템플릿 경로 | - |
327
+ | `--watch` | `-w` | Watch 모드 활성화 | `false` |
328
+ | `--include` | - | 포함할 모듈 (쉼표로 구분) | - |
329
+ | `--exclude` | - | 제외할 모듈 (쉼표로 구분) | - |
330
+
331
+ ### Config 파일 옵션
332
+
333
+ ```javascript
334
+ export default {
335
+ // 필수
336
+ uri: string,
337
+
338
+ // HTTP 클라이언트
339
+ httpClient: 'axios' | 'ky', // 기본값: 'axios'
340
+
341
+ // 인증
342
+ username?: string,
343
+ password?: string,
344
+
345
+ // 출력 경로
346
+ output?: {
347
+ dto?: string,
348
+ api?: string,
349
+ instance?: string,
350
+ queries?: string,
351
+ mutations?: string,
352
+ },
353
+
354
+ // 템플릿
355
+ templates?: string,
356
+
357
+ // Module Filtering
358
+ include?: string[],
359
+ exclude?: string[],
360
+ };
361
+ ```
362
+
363
+ ## 🔧 고급 설정
364
+
365
+ ### 커스텀 템플릿 사용
366
+
367
+ 자체 EJS 템플릿을 사용하려면:
368
+
369
+ ```javascript
370
+ export default {
371
+ templates: './custom-templates',
372
+ };
373
+ ```
374
+
375
+ 템플릿 구조:
376
+
377
+ ```
378
+ custom-templates/
379
+ ├── modular/
380
+ │ ├── axios/
381
+ │ │ └── procedure-call.ejs
382
+ │ ├── ky/
383
+ │ │ └── procedure-call.ejs
384
+ │ ├── api.ejs
385
+ │ ├── data-contracts.ejs
386
+ │ └── route-docs.ejs
387
+ └── tanstack-query/
388
+ ├── axios/
389
+ │ └── route-types.ejs
390
+ ├── ky/
391
+ │ └── route-types.ejs
392
+ └── api.ejs
393
+ ```
394
+
395
+ ### 환경 변수 사용
396
+
397
+ `.env` 파일:
398
+
399
+ ```env
400
+ SWAGGER_URL=http://localhost:8000/api-json
401
+ SWAGGER_USERNAME=admin
402
+ SWAGGER_PASSWORD=secret
403
+ ```
404
+
405
+ `swagger-codegen.config.js`:
406
+
407
+ ```javascript
408
+ import 'dotenv/config';
409
+
410
+ export default {
411
+ uri: process.env.SWAGGER_URL,
412
+ username: process.env.SWAGGER_USERNAME,
413
+ password: process.env.SWAGGER_PASSWORD,
414
+ };
415
+ ```
416
+
417
+ ## 📦 Migration Guide
418
+
419
+ ### v1.x에서 v2.0으로 마이그레이션
420
+
421
+ #### Breaking Changes
422
+
423
+ **HTTP Client 기본값 변경**
424
+
425
+ - v1.x: `ky`만 지원
426
+ - v2.0: `axios` 기본값, `ky` 선택 가능
427
+
428
+ **기존 ky 사용자:**
429
+
430
+ ```javascript
431
+ // swagger-codegen.config.js
432
+ export default {
433
+ httpClient: 'ky',
434
+ };
435
+ ```
436
+
437
+ #### New Features
438
+
439
+ - ✅ HTTP 클라이언트 선택 (axios/ky)
440
+ - ✅ 자동 Infinite Query 생성
441
+ - ✅ Config 파일 지원
442
+ - ✅ Watch 모드
443
+ - ✅ Module Filtering
444
+
445
+ ## 🤝 기여
446
+
447
+ 기여는 언제나 환영입니다! 이슈와 PR을 자유롭게 제출해주세요.
98
448
 
99
449
  ## 📄 라이선스
100
450
 
101
451
  MIT © [sen2y](https://github.com/sen-jik)
452
+
453
+ ## 🔗 링크
454
+
455
+ - [GitHub Repository](https://github.com/sen-jik/swagger-autogen)
456
+ - [Issues](https://github.com/sen-jik/swagger-autogen/issues)
457
+ - [npm Package](https://www.npmjs.com/package/swagger-fsd-gen)
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "swagger-fsd-gen",
3
- "version": "1.0.2",
3
+ "version": "2.0.2",
4
4
  "main": "index.js",
5
- "description": "Swagger API client generator that creates type-safe API clients using ky and TanStack Query with Feature Sliced Design pattern. Automatically generates API client code from Swagger/OpenAPI specifications.",
5
+ "description": "Swagger API client generator that creates type-safe API clients with axios/ky support, TanStack Query (including infinite queries), and Feature Sliced Design pattern. Automatically generates API client code from Swagger/OpenAPI specifications.",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1"
8
8
  },
@@ -12,7 +12,9 @@
12
12
  "api-client",
13
13
  "typescript",
14
14
  "ky",
15
+ "axios",
15
16
  "tanstack-query",
17
+ "infinite-query",
16
18
  "code-generator",
17
19
  "fsd"
18
20
  ],
@@ -24,6 +26,7 @@
24
26
  "generate-all": "./scripts/generate-all.js"
25
27
  },
26
28
  "dependencies": {
29
+ "chokidar": "^3.5.3",
27
30
  "js-yaml": "^4.1.0",
28
31
  "minimist": "^1.2.8",
29
32
  "node-fetch": "^3.3.2",