我使用Swagger CodeGen为Angular5应用程序生成API客户端。
我使用maven插件生成了代码,配置如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>contracts</groupId>
<artifactId>angular-contracts-api-client</artifactId>
<packaging>jar</packaging>
<name>Angular Contracts API Client</name>
<version>2.0.0</version>
<description>Contracts API Java Client</description>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<build>
<plugins>
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<output>${project.basedir}</output>
<!-- specify the swagger yaml -->
<inputSpec>${project.basedir}/../contracts-api-editor/api/swagger/swagger.yaml</inputSpec>
<language>typescript-angular</language>
<output>${project.basedir}/contracts-api</output>
<configOptions>
<ngVersion>5.1.1</ngVersion>
<npmName>angular-contracts-api</npmName>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
</dependencies>
<properties>
<swagger-core-version>1.5.12</swagger-core-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
在angular应用程序中,package.json为:
{
"name": "adf-cli-acs-template",
"version": "2.1.0",
"blueprint": "Content Services",
"description": "ACS ADF Application with Angular CLI",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "nohup ng serve --host 0.0.0.0> exaricm-ui.log 2> exaricm-ui-err.log &",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@alfresco/adf-content-services": "2.1.0",
"@alfresco/adf-core": "2.1.0",
"@angular/animations": "5.1.1",
"@angular/cdk": "5.0.1",
"@angular/cli": "^1.6.8",
"@angular/common": "5.0.0",
"@angular/compiler": "5.1.1",
"@angular/core": "5.1.1",
"@angular/flex-layout": "2.0.0-beta.12",
"@angular/forms": "5.1.1",
"@angular/http": "5.1.1",
"@angular/material": "5.0.1",
"@angular/platform-browser": "5.1.1",
"@angular/platform-browser-dynamic": "5.1.1",
"@angular/router": "5.1.1",
"@mat-datetimepicker/core": "^1.0.1",
"@mat-datetimepicker/moment": "^1.0.1",
"@ngx-translate/core": "8.0.0",
"alfresco-js-api": "2.0.0",
"chart.js": "2.5.0",
"classlist.js": "1.1.20150312",
"core-js": "2.4.1",
"custom-event-polyfill": "0.3.0",
"hammerjs": "2.0.8",
"intl": "1.2.5",
"minimatch": "3.0.4",
"moment": "2.18.1",
"moment-es6": "^1.0.0",
"ng2-charts": "1.6.0",
"pdfjs-dist": "1.5.404",
"raphael": "2.2.7",
"reflect-metadata": "0.1.10",
"require": "^2.4.20",
"rxjs": "5.5.2",
"web-animations-js": "2.3.1",
"zone.js": "0.8.14"
},
"devDependencies": {
"@angular-devkit/core": "0.0.29",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
为API生成的类包含几个命名空间ng的失败引用,这些引用不可用。例如:
constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) {
if (basePath !== undefined) {
this.basePath = basePath;
}
}
如何使命名空间可用?
答案 0 :(得分:1)
使用最新版本的maven插件(目前为2.3.1)非常重要。 还有一些问题,但这已得到修复。