o2o-infinith-frontend/orval.config.ts

51 lines
1.6 KiB
TypeScript

import { defineConfig } from 'orval'
// .env 로드 (Node 20.12+ 기본 기능, 추가 의존성 불필요)
try {
process.loadEnvFile('.env')
} catch {
// .env 파일이 없으면 무시 (기본값 사용)
}
const apiBaseUrl = process.env.VITE_API_BASE_URL ?? 'http://localhost:8001'
export default defineConfig({
api: {
// sdk 파일 및 모델 가져올 swagger 서버 주소 (.env 의 VITE_API_BASE_URL)
input: `${apiBaseUrl}/openapi.json`,
output: {
mode: 'tags-split',
target: './src/shared/api/generated',
schemas: './src/shared/api/model',
client: 'react-query',
httpClient: 'fetch',
clean: true,
prettier: true,
override: {
mutator: {
path: './src/shared/api/api.ts',
name: 'customFetcher',
},
query: {
useQuery: true,
useMutation: true,
// orval 7.21이 fetch httpClient + queryFn 조합에서 signal을 잘못 넘기는 버그가 있어 비활성
signal: false,
options: {
staleTime: 60_000,
},
},
operationName: (operation) => {
// FastAPI 기본 operationId: <controller_name>_<path>_<verb>\
// 컨트롤러 함수명만 사용하기
const opId = operation.operationId ?? ''
const verbPattern = /_(get|post|put|delete|patch|options|head)$/i
const beforeApi = opId.split(/_api_/)[0]
const name = beforeApi !== opId ? beforeApi : opId.replace(verbPattern, '')
return name.replace(/_+([a-zA-Z])/g, (_, c) => c.toUpperCase())
},
},
},
},
})