import { defineConfig } from 'orval'; /** * Orval config * * Backend: FastAPI (Negodata BackOffice API) — exposes the OpenAPI schema at * `${BACKEND_URL}/openapi.json` automatically. * * Generates a React Query client using the native `fetch` API (no axios needed). * Run with: `npm run orval` (see package.json script). */ export default defineConfig({ negodata: { input: { // Live FastAPI schema (negodata 백엔드 9400). ORVAL_INPUT 로 저장 파일 지정 가능 // (예: 백엔드의 openapi.json — 서버 안 띄우고도 생성). target: process.env.ORVAL_INPUT ?? 'http://localhost:9400/openapi.json', }, output: { mode: 'tags-split', target: './src/api/generated', schemas: './src/api/generated/model', client: 'react-query', // httpClient: 'fetch' 를 쓰면 오퍼레이션마다 Response200/404/Success/Error/Response // 상태코드별 유니온 타입이 강제로 쏟아진다. 우리 mutator는 본문(data)만 반환하므로 // 기본 mutator 방식(config-object)으로 두어 함수가 본문 타입을 바로 반환하게 한다. clean: true, prettier: true, override: { // FastAPI 기본 operationId("list_items_v1_item_list_get")에서 "_v1_" 앞부분만 취해 // camelCase 로 정리 → listItems/useListItems 등 기존 함수명 복원(백엔드 무수정). operationName: (operation) => { const id = operation.operationId ?? ''; const base = id.split('_v1_')[0] || id; return base.replace(/_([a-z])/g, (_m, c) => c.toUpperCase()); }, // 모든 생성 호출을 공통 fetch mutator로 통과시킨다(토큰/에러/baseURL 처리). mutator: { path: './src/api/mutator/custom-fetch.ts', name: 'customFetch', }, query: { useQuery: true, useInfinite: false, signal: true, }, }, }, }, });