diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache index 005c3a26df3..d7847235074 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/configuration.mustache @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache index 5659cd0694f..f81b512d8f0 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/rxjs-operators.mustache @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION b/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION index 7fea99011a6..f9f7450d135 100644 --- a/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION +++ b/samples/client/petstore-security-test/typescript-angular2/.swagger-codegen/VERSION @@ -1 +1 @@ -2.2.3-SNAPSHOT \ No newline at end of file +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore-security-test/typescript-angular2/api.module.ts b/samples/client/petstore-security-test/typescript-angular2/api.module.ts index 4ed0510d0d1..c3bde487bc4 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api.module.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api.module.ts @@ -12,10 +12,10 @@ import { FakeService } from './api/fake.service'; providers: [ FakeService ] }) export class ApiModule { - public static forConfig(configuration: Configuration): ModuleWithProviders { + public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { return { ngModule: ApiModule, - providers: [ {provide: Configuration, useValue: configuration}] + providers: [ {provide: Configuration, useFactory: configurationFactory}] } } } diff --git a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts index ec12093e92c..6f5ac0cd33d 100644 --- a/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts +++ b/samples/client/petstore-security-test/typescript-angular2/api/fake.service.ts @@ -10,6 +10,8 @@ * Do not edit the class manually. */ +/* tslint:disable:no-unused-variable member-ordering */ + import { Inject, Injectable, Optional } from '@angular/core'; import { Http, Headers, URLSearchParams } from '@angular/http'; import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; @@ -22,11 +24,10 @@ import '../rxjs-operators'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; -/* tslint:disable:no-unused-variable member-ordering */ - @Injectable() export class FakeService { + protected basePath = 'https://petstore.swagger.io *_/ ' \" =end -- \\r\\n \\n \\r/v2 *_/ ' \" =end -- \\r\\n \\n \\r'; public defaultHeaders: Headers = new Headers(); public configuration: Configuration = new Configuration(); @@ -37,12 +38,12 @@ export class FakeService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } /** - * + * * Extends object by coping non-existing properties. * @param objA object to be extended * @param objB source object @@ -71,8 +72,8 @@ export class FakeService { } /** - * To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * + * @summary To test code injection *_/ ' \" =end -- \\r\\n \\n \\r * @param test code inject * ' " =end rn n r To test code injection *_/ ' \" =end -- \\r\\n \\n \\r */ public testCodeInjectEndRnNR(test code inject * ' " =end rn n r?: string, extraHttpRequestParams?: any): Observable<{}> { @@ -96,11 +97,11 @@ export class FakeService { const path = this.basePath + '/fake'; let queryParameters = new URLSearchParams(); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let headersObservable = Observable.of(new Headers(this.defaultHeaders.toJSON())); // https://github.com/angular/angular/issues/6845 // to determine the Content-Type header let consumes: string[] = [ - 'application/json', + 'application/json', '*_/ =end -- ' ]; let canConsumeForm = this.canConsumeForm(consumes); @@ -111,28 +112,32 @@ export class FakeService { // to determine the Accept header let produces: string[] = [ - 'application/json', + 'application/json', '*_/ =end -- ' ]; - + if (test code inject * ' " =end rn n r !== undefined) { formParams.set('test code inject */ ' " =end -- \r\n \n \r', test code inject * ' " =end rn n r); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, - headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + let requestOptionsObservable = headersObservable.map((headers: Headers) => { + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return requestOptions; }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - return this.http.request(path, requestOptions); + return requestOptionsObservable.mergeMap((requestOptions: RequestOptionsArgs) => this.http.request(path, requestOptions)); } } diff --git a/samples/client/petstore-security-test/typescript-angular2/configuration.ts b/samples/client/petstore-security-test/typescript-angular2/configuration.ts index 0eed43fd575..d7847235074 100644 --- a/samples/client/petstore-security-test/typescript-angular2/configuration.ts +++ b/samples/client/petstore-security-test/typescript-angular2/configuration.ts @@ -1,19 +1,21 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string; + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } export class Configuration { - apiKeys: {[ key: string ]: string}; - username: string; - password: string; - accessToken: string | (() => string); - basePath: string; - withCredentials: boolean; + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | ((name: string, scopes?: string[]) => Observable); + basePath?: string; + withCredentials?: boolean; constructor(configurationParameters: ConfigurationParameters = {}) { this.apiKeys = configurationParameters.apiKeys; diff --git a/samples/client/petstore-security-test/typescript-angular2/rxjs-operators.ts b/samples/client/petstore-security-test/typescript-angular2/rxjs-operators.ts index 5659cd0694f..f81b512d8f0 100644 --- a/samples/client/petstore-security-test/typescript-angular2/rxjs-operators.ts +++ b/samples/client/petstore-security-test/typescript-angular2/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore-security-test/typescript-angular2/variables.ts b/samples/client/petstore-security-test/typescript-angular2/variables.ts index b734b2e5918..6fe58549f39 100644 --- a/samples/client/petstore-security-test/typescript-angular2/variables.ts +++ b/samples/client/petstore-security-test/typescript-angular2/variables.ts @@ -1,4 +1,4 @@ -import { InjectionToken } from '@angular/core'; +import { InjectionToken } from '@angular/core'; export const BASE_PATH = new InjectionToken('basePath'); export const COLLECTION_FORMATS = { @@ -6,4 +6,4 @@ export const COLLECTION_FORMATS = { 'tsv': ' ', 'ssv': ' ', 'pipes': '|' -} \ No newline at end of file +} diff --git a/samples/client/petstore/typescript-angular-v2/default/configuration.ts b/samples/client/petstore/typescript-angular-v2/default/configuration.ts index 005c3a26df3..d7847235074 100644 --- a/samples/client/petstore/typescript-angular-v2/default/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/default/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts index 5659cd0694f..f81b512d8f0 100644 --- a/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v2/default/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular-v2/npm/configuration.ts b/samples/client/petstore/typescript-angular-v2/npm/configuration.ts index 005c3a26df3..d7847235074 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts index 5659cd0694f..f81b512d8f0 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts index 005c3a26df3..d7847235074 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/configuration.ts @@ -1,8 +1,10 @@ +import { Observable } from 'rxjs/Observable'; + export interface ConfigurationParameters { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; } @@ -11,7 +13,7 @@ export class Configuration { apiKeys?: {[ key: string ]: string}; username?: string; password?: string; - accessToken?: string | (() => string); + accessToken?: string | ((name: string, scopes?: string[]) => Observable); basePath?: string; withCredentials?: boolean; diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts index 5659cd0694f..f81b512d8f0 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular-v4/npm/package-lock.json b/samples/client/petstore/typescript-angular-v4/npm/package-lock.json index 270b88ce43f..a0f1508cfb2 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/package-lock.json +++ b/samples/client/petstore/typescript-angular-v4/npm/package-lock.json @@ -1,5 +1,5 @@ { - "name": "@swagger/angular2-typescript-petstore", + "name": "@swagger/angular4-typescript-petstore", "version": "0.0.1", "lockfileVersion": 1, "dependencies": { diff --git a/samples/client/petstore/typescript-angular-v4/npm/package.json b/samples/client/petstore/typescript-angular-v4/npm/package.json index a15c011fe29..a916124d2e4 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/package.json +++ b/samples/client/petstore/typescript-angular-v4/npm/package.json @@ -1,5 +1,5 @@ { - "name": "@swagger/angular2-typescript-petstore", + "name": "@swagger/angular4-typescript-petstore", "version": "0.0.1", "description": "swagger client for @swagger/angular2-typescript-petstore", "author": "Swagger Codegen Contributors", diff --git a/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts index 5659cd0694f..f81b512d8f0 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/rxjs-operators.ts @@ -5,7 +5,11 @@ // Statics import 'rxjs/add/observable/throw'; +import 'rxjs/add/observable/of'; // Operators import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/map'; +import 'rxjs/add/operator/zip'; +import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/mergeMap'; diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/README.md b/samples/client/petstore/typescript-angular2/with-interfaces/README.md new file mode 100644 index 00000000000..038fd51491c --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/README.md @@ -0,0 +1,98 @@ +## @swagger/angular2-typescript-petstore@0.0.1 + +### Building + +To build an compile the typescript sources to javascript use: +``` +npm install +npm run build +``` + +### publishing + +First build the package than run ```npm publish``` + +### consuming + +navigate to the folder of your consuming project and run one of next commando's. + +_published:_ + +``` +npm install @swagger/angular2-typescript-petstore@0.0.1 --save +``` + +_unPublished (not recommended):_ + +``` +npm install PATH_TO_GENERATED_PACKAGE --save +``` + +_using `npm link`:_ + +In PATH_TO_GENERATED_PACKAGE: +``` +npm link +``` + +In your project: +``` +npm link @swagger/angular2-typescript-petstore@0.0.1 +``` + +In your angular2 project: + +``` +import { DefaultApi } from '@swagger/angular2-typescript-petstore/api/api'; +@NgModule({ + imports: [], + declarations: [], + exports: [], + providers: [AppModule] +}) +export class CoreModule {} +``` +``` +import { DefaultApi } from '@swagger/angular2-typescript-petstore/api/api'; + +export class AppComponent { + constructor(private apiGateway: DefaultApi) { } +} +``` + +### Set service base path +If different than the generated base path, during app bootstrap, you can provide the base path to your service. + +``` +import { BASE_PATH } from './path-to-swagger-gen-service/index'; + +bootstrap(AppComponent, [ + { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, +]); +``` + +#### Using @angular/cli +First extend your `src/environments/*.ts` files by adding the corresponding base path: + +``` +export const environment = { + production: false, + API_BASE_PATH: 'http://127.0.0.1:8080' +}; +``` + +In the src/app/app.module.ts: +``` +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; +import { environment } from '../environments/environment'; + +@NgModule({ + declarations: [ + AppComponent, + ], + imports: [ ], + providers: [{ provide: BASE_PATH, useValue: useValue: environment.API_BASE_PATH }], + bootstrap: [AppComponent] +}) +export class AppModule { } +``` \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/package.json b/samples/client/petstore/typescript-angular2/with-interfaces/package.json new file mode 100644 index 00000000000..d2e8c69bf95 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/package.json @@ -0,0 +1,40 @@ +{ + "name": "@swagger/angular2-typescript-petstore", + "version": "0.0.1", + "description": "swagger client for @swagger/angular2-typescript-petstore", + "author": "Swagger Codegen Contributors", + "keywords": [ + "swagger-client" + ], + "license": "Unlicense", + "main": "dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc --outDir dist/", + "postinstall": "npm run build" + }, + "peerDependencies": { + "@angular/core": "^2.2.2", + "@angular/http": "^2.2.2", + "@angular/common": "^2.2.2", + "@angular/compiler": "^2.2.2", + "core-js": "^2.4.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6" + }, + "devDependencies": { + "@angular/core": "^2.2.2", + "@angular/http": "^2.2.2", + "@angular/common": "^2.2.2", + "@angular/compiler": "^2.2.2", + "@angular/platform-browser": "^2.2.2", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6", + "typescript": "^2.1.5" + }, + "publishConfig": { + "registry":"https://skimdb.npmjs.com/registry" + } +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/tsconfig.json b/samples/client/petstore/typescript-angular2/with-interfaces/tsconfig.json new file mode 100644 index 00000000000..a6e9096bbf7 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "es6", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./dist", + "noLib": false, + "declaration": true, + "lib": [ "es6", "dom" ] + }, + "exclude": [ + "node_modules", + "dist" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts" + ] +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/typings.json b/samples/client/petstore/typescript-angular2/with-interfaces/typings.json new file mode 100644 index 00000000000..507c40e5cbe --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/typings.json @@ -0,0 +1,5 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160725163759" + } +} diff --git a/samples/client/petstore/typescript-angular4/npm/configuration.ts b/samples/client/petstore/typescript-angular4/npm/configuration.ts new file mode 100644 index 00000000000..d7847235074 --- /dev/null +++ b/samples/client/petstore/typescript-angular4/npm/configuration.ts @@ -0,0 +1,28 @@ +import { Observable } from 'rxjs/Observable'; + +export interface ConfigurationParameters { + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | ((name: string, scopes?: string[]) => Observable); + basePath?: string; + withCredentials?: boolean; +} + +export class Configuration { + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | ((name: string, scopes?: string[]) => Observable); + basePath?: string; + withCredentials?: boolean; + + constructor(configurationParameters: ConfigurationParameters = {}) { + this.apiKeys = configurationParameters.apiKeys; + this.username = configurationParameters.username; + this.password = configurationParameters.password; + this.accessToken = configurationParameters.accessToken; + this.basePath = configurationParameters.basePath; + this.withCredentials = configurationParameters.withCredentials; + } +} diff --git a/samples/server/petstore/jaxrs-cxf-cdi/swagger.json b/samples/server/petstore/jaxrs-cxf-cdi/swagger.json index a16c8a8a14d..604bfd0a6b5 100644 --- a/samples/server/petstore/jaxrs-cxf-cdi/swagger.json +++ b/samples/server/petstore/jaxrs-cxf-cdi/swagger.json @@ -108,8 +108,8 @@ "type" : "array", "items" : { "type" : "string", - "enum" : [ "available", "pending", "sold" ], - "default" : "available" + "default" : "available", + "enum" : [ "available", "pending", "sold" ] }, "collectionFormat" : "csv" } ],