Comments (2)
这个可以通过自定义代码模板解决
my-pont-template.ts
import { CodeGenerator, Interface, Mod, BaseClass } from 'pont-engine';
import * as pont from 'pont-engine';
export default class MyGenerator extends CodeGenerator {
/** 获取接口实现内容的代码 */
getInterfaceContent(inter: Interface) {
const bodyParmas = inter.getBodyParamsCode();
const requestParams = bodyParmas ? `params, bodyParams` : `params`;
return `
/**
* @desc ${inter.description}
*/
import * as defs from '../../baseClass';
// 修改为自己的 fetch函数
import pontFetch from 'src/utils/pontFetch';
export ${inter.getParamsCode()}
export const init = ${inter.response.initialValue};
export async function request(${requestParams}) {
return pontFetch({
url: '${inter.path}',
${bodyParmas ? 'params: bodyParams' : 'params'},
method: '${inter.method}',
});
}
`;
}
}
这是我的代码生成模板, 参考一下
https://github.com/gaoletian/nuxt-ts-pont-demo/blob/275876a93f1de63765b2470a12b69acc9c7337bc/app/config/pont-template-nuxt.ts#L80
from pont.
我理解每个项目的 fetch 都有自己的业务逻辑,所以 pont 的默认模板里,并没有声明 fetch 方法如何实现。比如接口结构中,如何算成功,错误信息如何取,这个是 pont 不应该关心的。
每个项目应该会有自己实现的公共的 fetch 方法,'import pontFetch from src/utils/pontFetch' 可以在 自定义代码生成(templatePath)被覆盖,指向你实现的 fetch 方法。
from pont.
Related Issues (20)
- 获远程接口数据失败 Error: compiler error in defname HOT 3
- 多个origins时重写CodeGenerator的getInterfaceContentInDeclaration方法不生效
- 能否在 Interface 中添加 operationId 属性
- 获远程接口数据失败 Error: compiler error in defname: DataList«task_alert_contact的实体类» HOT 2
- 修改 templatePath 对应模板中自定义接口内容,执行生成代码操作,outDir 接口文件内容不更新 HOT 1
- Extension causes high cpu load
- 所有的翻译插件失效,pont解析swagger报错 HOT 1
- 不生成 pontCore.js HOT 2
- 请问有没有nodejs api使用文档? HOT 1
- swagger V2生成baseClass时,超过两层的对象属性未读取 HOT 2
- nestjs swagger3.0 mods为空 HOT 1
- vs-code插件没有自动启动mock服务 HOT 1
- Java后端入参类型是List<Object>,生成的代码入参是Object,不识别List格式 HOT 1
- 无法设置rootDir
- "spiltApiLock": true, 执行pont scan 报错 找不到api.lock.json HOT 1
- "parameters" 原有的parameters数据,被覆盖,导致数据丢失 HOT 1
- 如何给单独请求添加headers HOT 1
- 获远程接口数据失败 Error: compiler error in defname: HOT 1
- 群号是不加不上了啊33661609 HOT 1
- 配置跳过翻译流程 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pont.