Skip to content

Instantly share code, notes, and snippets.

@yeonwooz
Last active December 14, 2023 15:19
Show Gist options
  • Save yeonwooz/8f3e1bc4883ae87740389036345d5da8 to your computer and use it in GitHub Desktop.
Save yeonwooz/8f3e1bc4883ae87740389036345d5da8 to your computer and use it in GitHub Desktop.
api generator
// api generator using swagger-typescript-api
import { exec } from 'shelljs';
const swaggerPath = `${__dirname}/../packages/api/swagger.json`;
const targetPath = `${__dirname}/../packages/front/src/api`;
async function generateApi() {
exec(`npx swagger-typescript-api \
-p ${swaggerPath} \ // json 또는 yaml 파일
-o ${targetPath} \ // api 파일을 만들 목적지 디렉토리
-n api.ts \ // 파일 이름
-r \ // 요청과 응답에 대한 메타정보를 자세하게 생성
--axios \ // 내장된 axios 클라이언트 인스턴스 사용
--extract-request-params \
--extract-request-body \
--extract-response-body \
--extract-response-error \
--extract-enums \ // 타입 추출
--unwrap-response-data // response 객체에서 data 객체를 꺼내어 해줌
`)
}
generateApi()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment