记录日期: 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"
 
这样可以不用每次输入代码执行生成
 

 
 

ABP 集成 nswag 到 VUE 项目, 自动生成操作类代码的更多相关文章

  1. SpringBoot整合Mybatis 使用generator自动生成实体类代码、Mapper代码、dao层代码

    1.新建一个SpringBoot项目,并引入Mybatis和mybatis-generator相关的依赖. <dependency> <groupId>org.springfr ...

  2. C# 连接SQLServer数据库自动生成model类代码

    Program.cs using System; using System.Collections.Generic; using System.Linq; using System.Threading ...

  3. 用Swashbuckle给ASP.NET Core的项目自动生成Swagger的API帮助文档

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用Swashbuckle给ASP.NET Core的项目自动生成Swagger的API帮助文档.

  4. java实现的一个maven多模块项目自动生成工具

    平时在做spring mvc web新项目时,都需要自己去搭建spring mvc的项目框架,包括基本pom 依赖引入,基本配置文件(web.xml,spring-mvc.xml,数据库配置文件等等) ...

  5. webpack打包vue项目之后生成的dist文件该怎么启动运行

    亲测,webpack打包vue项目之后生成的dist文件可以部署到 express 服务器上运行. 我的vue项目结构如下: 1. 进入该vue项目目录,打开git bash,执行:npm run b ...

  6. 自动生成Code First代码

    自动生成Code First代码 在前面的文章中我们提到Entity Framework的“Code First”模式也同样可以基于现有数据库进行开发.今天就让我们一起看一下使用Entity Fram ...

  7. Mybatis自动生成实体类

    Maven自动生成实体类需要的jar包 一.pom.xml中 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns ...

  8. Springboot mybatis generate 自动生成实体类和Mapper

    https://github.com/JasmineQian/SpringDemo_2019/tree/master/mybatis Springboot让java开发变得方便,Springboot中 ...

  9. 使用MyBatis Generator自动生成MyBatis的代码

    这两天需要用到MyBatis的代码自动生成的功能,由于MyBatis属于一种半自动的ORM框架,所以主要的工作就是配置Mapping映射文件,但是由于手写映射文件很容易出错,所以可利用MyBatis生 ...

随机推荐

  1. elasticsearch数据库(ES)

    1. http://blog.csdn.net/cnweike/article/details/33736429 http://www.oschina.net/translate/elasticsea ...

  2. windows远程重启

    用管理员权限打开win+r,输入cmd后: net use \ip地址 "管理员密码" /user:administrator shutdown /r /t 0 /m ip地址 即 ...

  3. PYTHON 100days学习笔记008-4:错误和异常

    目录 Day008_04:python错误和异常 1.语法错误 2.异常 3.异常处理 4.抛出异常 5.用户自定义异常 6.定义清理行为 7.预定义的清理行为 参考文章: python3错误和异常 ...

  4. poj2826(细节,计算几何)

    题目链接:https://vjudge.net/problem/POJ-2826 题意:平面中摆两根木棍,雨水从上垂直下落,问木棍中能乘多少水. 思路: 细节很多,坑QAQ.. 首先不相交时肯定为0. ...

  5. 我学会了正确的dinic

    以前写Isap的时候,总是被卡,然后学了一发Isap的当前弧优化,好像可以水过很多题 但是一直没明白为啥Isap会走一个环??? 然后写dinic了,听说不容易被卡(来自去年九省联考的指导) 然而-- ...

  6. 小木棒HDU1455(DFS+剪枝)

    题意:HDU1455 给出n个小木棒的长度,他们是又数根长度相同的木棒剪短得来的,问没剪短之前的木棒长度最短是多少. 思路: 见代码:https://www.cnblogs.com/fqfzs/p/9 ...

  7. spring——aop详细总结1

    AOP(Aspect-Oriented Programming, 面向切面编程): 是一种新的方法论, 是对传统 OOP(Object-Oriented Programming, 面向对象编程) 的补 ...

  8. win10下面opencv安装

    记得以前是安装好的,但是用了conda更新所有包以后,cv2不好用了,试验了很多方法都不管用,最后只能卸载opencv然后重新安装了. 如果电脑上安装了很多版本的python,比如我就安装了pytho ...

  9. git bash配置SSH远程连接阿里云ECS

    1.连接配置 1-1.添加安全组规则 1-2.使用GitHub的话本地都会有id_rsa.pub(公钥),id_rsa(私钥),一般保存在C盘用户目录下.ssh文件夹. 把公钥内容复制下来(ssh-r ...

  10. 【ES6 】Promise

    Promise对象定义: 用来处理异步编程 Promise对象的特点 对象的状态不受外界影响 一旦状态改变,就不会再变,任何时候都可以得到这个结果 Promise对象的状态 pending(进行中) ...