- 添加 target/ 到 .gitignore - 从 git 暂存区移除已追踪的 target 目录 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { defineConfig } from 'orval';
|
|
|
|
export default defineConfig({
|
|
readingPlatform: {
|
|
output: {
|
|
mode: 'split',
|
|
target: 'src/api/generated/index.ts',
|
|
schemas: 'src/api/generated/model',
|
|
client: 'axios',
|
|
override: {
|
|
mutator: {
|
|
path: 'src/api/generated/mutator.ts',
|
|
name: 'customMutator',
|
|
},
|
|
// 自定义类型名称
|
|
name: (type) => {
|
|
// 移除命名空间前缀,简化类型名称
|
|
return type.replace(/^(Result|ResultPageResult)/, '');
|
|
},
|
|
},
|
|
// 导入优化
|
|
imports: {
|
|
axios: true,
|
|
},
|
|
},
|
|
input: {
|
|
// 从 Java 后端 OpenAPI 文档生成
|
|
target: 'http://localhost:8080/v3/api-docs',
|
|
// 路径重写:确保 OpenAPI 文档中的路径正确
|
|
override: {
|
|
// 使用转换器修复路径 - 将 `/api/xxx` 转换为 `/api/v1/xxx`
|
|
transformer: (openAPIObject) => {
|
|
// 遍历所有路径,修复缺少的 `/v1` 前缀
|
|
Object.keys(openAPIObject.paths).forEach((path) => {
|
|
const newKey = path.replace(/^\/api\//, '/api/v1/');
|
|
if (newKey !== path) {
|
|
openAPIObject.paths[newKey] = openAPIObject.paths[path];
|
|
delete openAPIObject.paths[path];
|
|
}
|
|
});
|
|
return openAPIObject;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|