orval.config.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { defineConfig } from 'orval';
  2. export default defineConfig({
  3. 'your-api': {
  4. // OpenAPI 规范文件路径(支持本地文件或 URL)
  5. input: {
  6. target: 'http://localhost:8080/v3/api-docs', // 可改为你的 Swagger JSON 地址,如:http://localhost:8000/openapi.json
  7. },
  8. output: {
  9. // 生成代码的模式:tags-按接口标签拆分文件
  10. mode: 'tags',
  11. // 客户端类型:使用 axios
  12. client: 'axios',
  13. // 生成 vue-query hooks
  14. target: './src/api/client.ts',
  15. // 生成的 TypeScript 类型存放目录
  16. schemas: './src/api/models',
  17. // 每次生成前自动清理旧文件
  18. clean: true,
  19. // 覆盖默认配置
  20. override: {
  21. // 自定义 axios 实例
  22. mutator: {
  23. path: './src/util/axios-instance.ts',
  24. name: 'customAxiosInstance',
  25. },
  26. // 为每个接口生成 vue-query hooks
  27. query: {
  28. useQuery: true, // 生成 useGetXXX hooks
  29. useMutation: true, // 生成 usePostXXX hooks
  30. },
  31. },
  32. },
  33. // 生成后自动格式化代码
  34. hooks: {
  35. afterAllFilesWrite: 'prettier --write',
  36. },
  37. },
  38. });