• ABP使用NSwagStudio for Swagger Api生成ServiceProxies


    案例主要是使用NSwag来生成ABP for angular 2+的客户端代码。

    NSwagStudio 下载地址 比较强大、可以生成TypeScript、WebApi Controller、CSharp Client 

    1:运行Web.Host项目 http://localhost:22742/swagger/

    2:安装NSwagStudio

    3:生成代码

      3.1:ABP作者提供了.nswag的配置

    {
      "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的文件,打开方式以NSwagStudio

      3.3:点击 Generate Files  Soeasy  

     

  • 相关阅读:
    (二十九)动态单元格
    (二十八)QQ好友列表的展开收缩
    (二十七)QQ好友列表的实现
    (二十六)静态单元格(Cell)
    (二十五)键盘的设置与TextField细节处理
    poj 1734 Sightseeing trip
    BZOJ 2200: [Usaco2011 Jan]道路和航线
    LUOGU P1073 最优贸易
    poj 3662 Telephone Lines
    poj 3539 Elevator
  • 原文地址:https://www.cnblogs.com/yy690486439/p/7890697.html
Copyright © 2020-2023  润新知