1

I have used Swagger CodeGen to generate the API client for an Angular5 application.

I have generated the code using maven plugin configured as follows:

<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>

In the angular application, the package.json is:

{
  "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"
  }
}

The classes generated for the API contain several failing references of the namespace ng that is not available. For example:

constructor(protected $http: ng.IHttpService, protected $httpParamSerializer?: (d: any) => any, basePath?: string) {
    if (basePath !== undefined) {
        this.basePath = basePath;
    }
}

How can I make the namespace ng available ?

1 Answer 1

1

It is important to use the latest version of the maven plugin (currently 2.3.1). There are still some issues, but this has been fixed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.