| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { defineConfig } from 'orval';
- export default defineConfig({
- 'your-api': {
- // OpenAPI 规范文件路径(支持本地文件或 URL)
- input: {
- target: 'http://localhost:8080/v3/api-docs', // 可改为你的 Swagger JSON 地址,如:http://localhost:8000/openapi.json
- },
- output: {
- // 生成代码的模式:tags-按接口标签拆分文件
- mode: 'tags',
- // 客户端类型:使用 axios
- client: 'axios',
- // 生成 vue-query hooks
- target: './src/api/client.ts',
- // 生成的 TypeScript 类型存放目录
- schemas: './src/api/models',
- // 每次生成前自动清理旧文件
- clean: true,
- // 覆盖默认配置
- override: {
- // 自定义 axios 实例
- mutator: {
- path: './src/util/axios-instance.ts',
- name: 'customAxiosInstance',
- },
- // 为每个接口生成 vue-query hooks
- query: {
- useQuery: true, // 生成 useGetXXX hooks
- useMutation: true, // 生成 usePostXXX hooks
- },
- },
- },
- // 生成后自动格式化代码
- hooks: {
- afterAllFilesWrite: 'prettier --write',
- },
- },
- });
|