记录日期: 2019-9-22 23:12:39

原文链接:https://www.cnblogs.com/Qbit/p/11569906.html

集成记录:

npm install nswag --save-dev

复制  NSwag\src\NSwag.CodeGeneration.TypeScript\Templates 目录下的所有文件到 ts 项目的 nswag 目录下,nswag 源码下载困难,人肉拷贝吧 https://github.com/RicoSuter/NSwag/tree/master/src/NSwag.CodeGeneration.TypeScript/Templates

修改 service.config.nswag 中的 templateDirectory 为: "templateDirectory": "./Templates",

至此,可以随意调整复制过来的 liquid 模板,比如增加clientBaseClass 的引用  我的 完整配置如下:

{
"runtime": "Default",
"defaultVariables": null,
"documentGenerator": {
"fromDocument": {
"json": "",
"url": "http://localhost:21021/swagger/v1/swagger.json",
"output": null
}
},
"codeGenerators": {
"openApiToTypeScriptClient": {
"className": "{controller}ServiceProxy",
"moduleName": "",
"namespace": "",
"typeScriptVersion": 2.7,
"template": "Axios",
"promiseType": "Promise",
"httpClass": "HttpClient",
"useSingletonProvider": false,
"injectionTokenType": "InjectionToken",
"rxJsVersion": 6.0,
"dateTimeType": "Date",
"nullValue": "Null",
"generateClientClasses": true,
"generateClientInterfaces": false,
"generateOptionalParameters": false,
"exportTypes": true,
"wrapDtoExceptions": false,
"exceptionClass": "ApiException",
"clientBaseClass": "AbpServiceBase",
"wrapResponses": false,
"wrapResponseMethods": [],
"generateResponseClasses": true,
"responseClass": "SwaggerResponse",
"protectedMethods": [],
"configurationClass": null,
"useTransformOptionsMethod": false,
"useTransformResultMethod": true,
"generateDtoTypes": true,
"operationGenerationMode": "MultipleClientsFromPathSegments",
"markOptionalProperties": false,
"generateCloneMethod": false,
"typeStyle": "Class",
"classTypes": [],
"extendedClasses": [],
"extensionCode": "",
"generateDefaultValues": true,
"excludedTypeNames": [],
"excludedParameterNames": [],
"handleReferences": true,
"generateConstructorInterface": false,
"convertConstructorInterfaceData": true,
"importRequiredTypes": true,
"useGetBaseUrlMethod": false,
"baseUrlTokenName": "API_BASE_URL",
"queryNullValue": "",
"inlineNamedDictionaries": false,
"inlineNamedAny": false,
"templateDirectory": "./Templates",
"typeNameGeneratorType": null,
"propertyNameGeneratorType": null,
"enumNameGeneratorType": null,
"serviceHost": null,
"serviceSchemes": null,
"output": "../src/api/abp-service-proxies.ts"
}
}
}

ABP 的swagger 必须使用这种方式获取data.result

修改 Client.ProcessResponse.ReadBodyStart.liquid

{% elseif Framework.IsAxios -%}
const _responseText = response.data.result;    
 
或者你不去修改模板,使用 我的配置,然后继承这个类,去除注释代码
 
import { AxiosResponse } from "axios";

export class AbpServiceBase {

    protected transformResult(url: string, response: AxiosResponse, processor: (response: AxiosResponse) => Promise<any>): Promise<any> {
// if(response.data.result){
// response.data=response.data.result;
// }
console.log(response)
return processor(response);
}
}

  

修改 File.liquid 文件,在48行增加 :

import { AbpServiceBase } from './abp-service-base';
 
在项目的 packge.json scripts 中增加:
  "genApi":"cd nswag &.\\refresh.bat"
 
这样可以不用每次输入代码执行生成
 

 
 

最新文章

  1. javascript 类型转换。
  2. spring4mvc返回json(bean,list,map)
  3. js实现页面跳转的几种方式
  4. junit高级篇(参数化、打包测试)-实例代码
  5. 网友对twisted deferr的理解
  6. Google Analytics SEO 实时 网站 访问量 统计
  7. 内核与内核模块:depmod,lsmod,modinfo,insmod,rmmod,mdprobe
  8. sql -以零作除数
  9. 写入和读取LOB类型的对象
  10. [置顶] SSO单点登录系列6:cas单点登录防止登出退出后刷新后退ticket失效报500错
  11. 4.java.lang.NumberFormatException(数据类型转换异常)
  12. ZenCoding Syntax
  13. CSS属性合写
  14. Java文件操作(IO流)
  15. css中单位 px、em 的区别【转载】
  16. 在Hadoop2.2基础上安装Spark(伪分布式)
  17. thinkphp3.2-更改控制器名后找不到相应的表?报1146的错
  18. angular2 学习笔记 ( Rxjs, Promise, Async/Await 的区别 )
  19. window.location各属性含义
  20. asp.net针对SQLSERVER数据库备份和恢复的一揽子问题解决

热门文章

  1. 用elasticsearchdump备份恢复数据
  2. Web应用搭建
  3. C# 添加日志文件
  4. 洛谷 题解 P4955 【[USACO14JAN]Cross Country Skiing 越野滑雪】
  5. chrome 监听touch类事件报错:无法被动侦听事件preventDefault
  6. flink两种安装方式
  7. 【hash】Seek the Name, Seek the Fame
  8. 二、python数据类型、字符编码、文件处理
  9. Java多线程(九):生产者消费者模型
  10. Java并发与多线程教程(2)