案例主要是使用NSwag來生成ABP for angular 2+的客戶端代碼。javascript
NSwagStudio 下載地址 比較強大、能夠生成TypeScript、WebApi Controller、CSharp Client php
1:運行Web.Host項目 http://localhost:22742/swagger/java
2:安裝NSwagStudiojson
3:生成代碼promise
3.1:ABP做者提供了.nswag的配置ui
{ "swaggerGenerator": { "fromSwagger": { "url": "http://localhost:22742/swagger/v1/swagger.json", "output": null } }, "codeGenerators": { "swaggerToTypeScriptClient": { "className": "{controller}ServiceProxy", "moduleName": "", "namespace": "", "typeScriptVersion": 1.8, "template": "Angular", "promiseType": "Promise", "dateTimeType": "MomentJS", "nullValue": "Undefined", "generateClientClasses": true, "generateClientInterfaces": false, "generateOptionalParameters": false, "wrapDtoExceptions": false, "useTransformOptionsMethod": false, "useTransformResultMethod": false, "generateDtoTypes": true, "operationGenerationMode": "MultipleClientsFromPathSegments", "markOptionalProperties": false, "generateCloneMethod": false, "typeStyle": "Class", "extensionCode": "service.extensions.ts", "generateDefaultValues": true, "excludedTypeNames": [], "handleReferences": false, "generateConstructorInterface": true, "importRequiredTypes": true, "baseUrlTokenName": "API_BASE_URL", "output": "../src/shared/service-proxies/service-proxies.ts" }, "swaggerToCSharpClient": { "generateClientClasses": true, "generateClientInterfaces": false, "generateDtoTypes": true, "injectHttpClient": false, "disposeHttpClient": true, "generateExceptionClasses": true, "exceptionClass": "SwaggerException", "wrapDtoExceptions": true, "useHttpClientCreationMethod": false, "httpClientType": "System.Net.Http.HttpClient", "useHttpRequestMessageCreationMethod": false, "useBaseUrl": true, "generateSyncMethods": false, "clientClassAccessModifier": "public", "generateContractsOutput": false, "className": "{controller}Client", "namespace": "MyNamespace", "generateOptionalParameters": false, "requiredPropertiesMustBeDefined": true, "dateType": "System.DateTime", "dateTimeType": "System.DateTime", "timeType": "System.TimeSpan", "timeSpanType": "System.TimeSpan", "arrayType": "System.Collections.ObjectModel.ObservableCollection", "dictionaryType": "System.Collections.Generic.Dictionary", "classStyle": "Inpc", "operationGenerationMode": "MultipleClientsFromOperationId", "generateDefaultValues": true, "generateDataAnnotations": true, "excludedTypeNames": [], "wrapResponses": false, "generateResponseClasses": true, "responseClass": "SwaggerResponse", "handleReferences": false, "generateImmutableArrayProperties": false, "generateImmutableDictionaryProperties": false, "output": null }, "swaggerToCSharpController": { "className": "{controller}", "namespace": "MyNamespace", "additionalNamespaceUsages": [ "System.Web.Http" ], "generateOptionalParameters": false, "requiredPropertiesMustBeDefined": true, "dateType": "System.DateTime", "dateTimeType": "System.DateTime", "timeType": "System.TimeSpan", "timeSpanType": "System.TimeSpan", "arrayType": "System.Collections.Generic.IEnumerable", "dictionaryType": "System.Collections.Generic.Dictionary", "classStyle": "Inpc", "operationGenerationMode": "MultipleClientsFromOperationId", "generateDefaultValues": true, "generateDataAnnotations": true, "excludedTypeNames": [], "wrapResponses": false, "generateResponseClasses": true, "responseClass": "SwaggerResponse", "handleReferences": false, "generateImmutableArrayProperties": false, "generateImmutableDictionaryProperties": false, "output": null } } }
3.2:上面內容保存爲.nswag的文件,打開方式以NSwagStudiourl
3.3:點擊 Generate Files Soeasy spa