swagger-fsd-gen
Version:
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.
138 lines (99 loc) β’ 2.86 kB
Markdown
# π Quick Start Guide
## π μꡬμ¬ν
- Node.js 18+
- Yarn 4.7.0+
## π§ μ€μΉ
```bash
# 1. μ μ₯μ ν΄λ‘
git clone <your-repo-url>
cd swagger-client-autogen
# 2. μμ‘΄μ± μ€μΉ
yarn install
# 3. μ μ μ€μΉ (μ νμ¬ν)
yarn link
```
## π‘ μ¬μ©λ²
### 1λ¨κ³: Swagger λ¬Έμ λ€μ΄λ‘λ (μ νμ¬ν)
```bash
# μ격 Swagger λ¬Έμλ₯Ό λ‘컬μ μ μ₯
fetch-swagger --url https://api.example.com/swagger.json
# μΈμ¦μ΄ νμν κ²½μ°
fetch-swagger --url https://api.example.com/swagger.json --username admin --password secret
```
### 2λ¨κ³: API ν΄λΌμ΄μΈνΈ μμ±
```bash
# μ격 URLμμ μ§μ μμ±
generate-all --uri https://api.example.com/swagger.json
# λ‘컬 νμΌμμ μμ±
generate-all --uri ./swagger/my-api.yml
# μΈμ¦μ΄ νμν κ²½μ°
generate-all --uri https://api.example.com/swagger.json --username admin --password secret
```
## π μμ±λλ νμΌ
```
src/
βββ shared/
β βββ api/
β βββ dto.ts # λͺ¨λ DTO νμ
βββ entities/
βββ {moduleName}/ # κ° Swagger νκ·Έλ³
βββ api/
βββ index.ts # API ν΄λμ€
βββ instance.ts # API μΈμ€ν΄μ€
βββ queries.ts # Query ν
βββ mutations.ts # Mutation ν
```
## π― νλ‘μ νΈμ μ μ©νκΈ°
### 1. νμν ν¨ν€μ§ μ€μΉ
```bash
npm install ky @tanstack/react-query
```
### 2. API μΈμ€ν΄μ€ μ€μ
```typescript
// src/app/providers/api.ts
import ky from "ky";
export const apiInstance = ky.create({
prefixUrl: "https://api.example.com",
headers: {
"Content-Type": "application/json",
},
});
```
### 3. μμ±λ μ½λ μ¬μ©
```typescript
// Query μ¬μ©
import { useGetUsersQuery } from "@/entities/user/api/queries";
const { data: users, isLoading } = useGetUsersQuery();
// Mutation μ¬μ©
import { useCreateUserMutation } from "@/entities/user/api/mutations";
const createUser = useCreateUserMutation({
onSuccess: () => console.log("User created!"),
});
createUser.mutate({ body: { name: "John" } });
```
## βοΈ μ»€μ€ν
μ€μ
```bash
# μΆλ ₯ κ²½λ‘ μ»€μ€ν°λ§μ΄μ§
generate-all --uri ./swagger.json \
--dto-output-path ./src/types/api.ts \
--api-output-path ./src/api/{moduleName}/client.ts \
--query-output-path ./src/api/{moduleName}/queries.ts \
--mutation-output-path ./src/api/{moduleName}/mutations.ts
# 컀μ€ν
ν
νλ¦Ώ μ¬μ©
generate-all --uri ./swagger.json --project-template ./my-templates/
```
## π λ¬Έμ ν΄κ²°
### μμ‘΄μ± μ€λ₯
```bash
yarn install
```
### κΆν μ€λ₯ (μ μ μ€μΉ μ)
```bash
yarn unlink
yarn link
```
### μμ±λ νμΌ νμΈ
```bash
# μμ±λ νμΌ λͺ©λ‘ νμΈ
find src -name "*.ts" -type f | grep -E "(api|dto)" | sort
```