記錄日期: 2019-9-22 23:12:39javascript
原文連接:http://www.javashuo.com/article/p-cwlpwhpz-ek.htmlhtml
集成記錄:java
npm install nswag --save-devios
複製 NSwag\src\NSwag.CodeGeneration.TypeScript\Templates 目錄下的全部文件到 ts 項目的 nswag 目錄下,nswag 源碼下載困難,人肉拷貝吧 https://github.com/RicoSuter/NSwag/tree/master/src/NSwag.CodeGeneration.TypeScript/Templatesgit
修改 service.config.nswag 中的 templateDirectory 爲: "templateDirectory": "./Templates",github
至此,能夠隨意調整複製過來的 liquid 模板,好比增長clientBaseClass 的引用 個人 完整配置以下:npm
{ "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.resultjson
修改 Client.ProcessResponse.ReadBodyStart.liquid axios
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行增長 :api