[typescript-angular] drop support of angular below 6.0.0 (#6360)

* typescript-angular: drop support for angular below 6.0.0

* typescript-angular: re-generate samples

* typescript-angular: re-generate docs
This commit is contained in:
Esteban Gehring
2020-05-28 11:28:11 +02:00
committed by GitHub
parent 7d4bbcc29b
commit ec39005ae5
224 changed files with 73 additions and 20740 deletions

View File

@@ -99,7 +99,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
this.cliOptions.add(CliOption.newBoolean(PROVIDED_IN_ROOT,
"Use this property to provide Injectables in root (it is only valid in angular version greater or equal to 6.0.0).",
false));
this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular.").defaultValue(this.ngVersion));
this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular. (At least 6.0.0)").defaultValue(this.ngVersion));
this.cliOptions.add(new CliOption(API_MODULE_PREFIX, "The prefix of the generated ApiModule."));
this.cliOptions.add(new CliOption(SERVICE_SUFFIX, "The suffix of the generated service.").defaultValue(this.serviceSuffix));
this.cliOptions.add(new CliOption(SERVICE_FILE_SUFFIX, "The suffix of the file of the generated service (service<suffix>.ts).").defaultValue(this.serviceFileSuffix));
@@ -122,7 +122,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
@Override
public String getHelp() {
return "Generates a TypeScript Angular (2.x - 9.x) client library.";
return "Generates a TypeScript Angular (6.x - 9.x) client library.";
}
@Override
@@ -179,16 +179,12 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
taggedUnions = Boolean.parseBoolean(additionalProperties.get(TAGGED_UNIONS).toString());
}
if (ngVersion.atLeast("6.0.0")) {
if (!additionalProperties.containsKey(PROVIDED_IN_ROOT)) {
additionalProperties.put(PROVIDED_IN_ROOT, true);
} else {
additionalProperties.put(PROVIDED_IN_ROOT, Boolean.parseBoolean(
additionalProperties.get(PROVIDED_IN_ROOT).toString()
));
}
if (!additionalProperties.containsKey(PROVIDED_IN_ROOT)) {
additionalProperties.put(PROVIDED_IN_ROOT, true);
} else {
additionalProperties.put(PROVIDED_IN_ROOT, false);
additionalProperties.put(PROVIDED_IN_ROOT, Boolean.parseBoolean(
additionalProperties.get(PROVIDED_IN_ROOT).toString()
));
}
if (ngVersion.atLeast("9.0.0")) {
@@ -198,13 +194,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
}
additionalProperties.put(NG_VERSION, ngVersion);
additionalProperties.put("injectionToken", ngVersion.atLeast("4.0.0") ? "InjectionToken" : "OpaqueToken");
additionalProperties.put("injectionTokenTyped", ngVersion.atLeast("4.0.0"));
additionalProperties.put("useHttpClient", ngVersion.atLeast("4.3.0"));
additionalProperties.put("useRxJS6", ngVersion.atLeast("6.0.0"));
if (!ngVersion.atLeast("4.3.0")) {
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
}
if (additionalProperties.containsKey(API_MODULE_PREFIX)) {
String apiModulePrefix = additionalProperties.get(API_MODULE_PREFIX).toString();
validateClassPrefixArgument("ApiModule", apiModulePrefix);
@@ -248,13 +238,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
additionalProperties.put("tsVersion", ">=3.4.0 <3.6.0");
} else if (ngVersion.atLeast("7.0.0")) {
additionalProperties.put("tsVersion", ">=3.1.1 <3.2.0");
} else if (ngVersion.atLeast("6.0.0")) {
additionalProperties.put("tsVersion", ">=2.7.2 and <2.10.0");
} else if (ngVersion.atLeast("5.0.0")) {
additionalProperties.put("tsVersion", ">=2.1.5 <2.7.0");
} else {
// Angular v2-v4 requires typescript ">=2.1.5 <2.8"
additionalProperties.put("tsVersion", ">=2.1.5 <2.8.0");
// Angular v6 requires typescript ">=2.7.2 and <2.10.0"
additionalProperties.put("tsVersion", ">=2.7.2 and <2.10.0");
}
// Set the rxJS version compatible to the Angular version
@@ -264,30 +250,12 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
additionalProperties.put("rxjsVersion", "6.5.0");
} else if (ngVersion.atLeast("7.0.0")) {
additionalProperties.put("rxjsVersion", "6.3.0");
} else if (ngVersion.atLeast("6.0.0")) {
} else {
// Angular v6
additionalProperties.put("rxjsVersion", "6.1.0");
} else {
// Angular prior to v6
additionalProperties.put("rxjsVersion", "5.4.0");
}
if (!ngVersion.atLeast("4.3.0")) {
supportingFiles.add(new SupportingFile("rxjs-operators.mustache", getIndexDirectory(), "rxjs-operators.ts"));
}
// for Angular 2 AOT support we will use good-old ngc,
// Angular Package format wasn't invented at this time and building was much more easier
if (!ngVersion.atLeast("4.0.0")) {
LOGGER.warn("Please update your legacy Angular " + ngVersion + " project to benefit from 'Angular Package Format' support.");
additionalProperties.put("useNgPackagr", false);
} else {
additionalProperties.put("useNgPackagr", true);
supportingFiles.add(new SupportingFile("ng-package.mustache", getIndexDirectory(), "ng-package.json"));
}
// Libraries generated with v1.x of ng-packagr will ship with AoT metadata in v3, which is intended for Angular v4.
// Libraries generated with v2.x of ng-packagr will ship with AoT metadata in v4, which is intended for Angular v5 (and Angular v6).
additionalProperties.put("useOldNgPackagr", !ngVersion.atLeast("5.0.0"));
supportingFiles.add(new SupportingFile("ng-package.mustache", getIndexDirectory(), "ng-package.json"));
// Specific ng-packagr configuration
if (ngVersion.atLeast("9.0.0")) {
@@ -300,17 +268,11 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
// compatible versions with typescript version
additionalProperties.put("ngPackagrVersion", "5.1.0");
additionalProperties.put("tsickleVersion", "0.34.0");
} else if (ngVersion.atLeast("6.0.0")) {
} else {
// angular v6
// compatible versions with typescript version
additionalProperties.put("ngPackagrVersion", "3.0.6");
additionalProperties.put("tsickleVersion", "0.32.1");
} else if (ngVersion.atLeast("5.0.0")) {
// compatible versions with typescript version
additionalProperties.put("ngPackagrVersion", "2.4.5");
additionalProperties.put("tsickleVersion", "0.27.5");
} else {
// Angular versions prior to v5
additionalProperties.put("ngPackagrVersion", "1.6.0");
}
// set zone.js version
@@ -318,12 +280,9 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
additionalProperties.put("zonejsVersion", "0.10.2");
} else if (ngVersion.atLeast("8.0.0")) {
additionalProperties.put("zonejsVersion", "0.9.1");
} else if (ngVersion.atLeast("5.0.0")) {
// compatible versions to Angular 5+
additionalProperties.put("zonejsVersion", "0.8.26");
} else {
// Angular versions prior to v5
additionalProperties.put("zonejsVersion", "0.7.6");
// compatible versions to Angular 6+
additionalProperties.put("zonejsVersion", "0.8.26");
}
//Files for building our lib
@@ -385,37 +344,8 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode
if (op.getHasFormParams()) {
hasSomeFormParams = true;
}
if ((boolean) additionalProperties.get("useHttpClient")) {
op.httpMethod = op.httpMethod.toLowerCase(Locale.ENGLISH);
} else {
// Convert httpMethod to Angular's RequestMethod enum
// https://angular.io/docs/ts/latest/api/http/index/RequestMethod-enum.html
switch (op.httpMethod) {
case "GET":
op.httpMethod = "RequestMethod.Get";
break;
case "POST":
op.httpMethod = "RequestMethod.Post";
break;
case "PUT":
op.httpMethod = "RequestMethod.Put";
break;
case "DELETE":
op.httpMethod = "RequestMethod.Delete";
break;
case "OPTIONS":
op.httpMethod = "RequestMethod.Options";
break;
case "HEAD":
op.httpMethod = "RequestMethod.Head";
break;
case "PATCH":
op.httpMethod = "RequestMethod.Patch";
break;
default:
throw new RuntimeException("Unknown HTTP Method " + op.httpMethod + " not allowed");
}
}
op.httpMethod = op.httpMethod.toLowerCase(Locale.ENGLISH);
// Prep a string buffer where we're going to set up our new version of the string.
StringBuilder pathBuffer = new StringBuilder();

View File

@@ -10,12 +10,7 @@ npm run build
### publishing
{{#useNgPackagr}}
First build the package then run ```npm publish dist``` (don't forget to specify the `dist` folder!)
{{/useNgPackagr}}
{{^useNgPackagr}}
First build the package then run ```npm publish```
{{/useNgPackagr}}
### consuming
@@ -30,24 +25,14 @@ npm install {{npmName}}@{{npmVersion}} --save
_without publishing (not recommended):_
```
{{#useNgPackagr}}
npm install PATH_TO_GENERATED_PACKAGE/dist.tgz --save
{{/useNgPackagr}}
{{^useNgPackagr}}
npm install PATH_TO_GENERATED_PACKAGE/{{npmName}}-{{npmVersion}}.tgz --save
{{/useNgPackagr}}
```
_It's important to take the tgz file, otherwise you'll get trouble with links on windows_
_using `npm link`:_
{{#useNgPackagr}}
In PATH_TO_GENERATED_PACKAGE/dist:
{{/useNgPackagr}}
{{^useNgPackagr}}
In PATH_TO_GENERATED_PACKAGE:
{{/useNgPackagr}}
```
npm link
```
@@ -70,15 +55,14 @@ In your Angular project:
```
// without configuring providers
import { ApiModule } from '{{npmName}}';
{{#useHttpClient}}import { HttpClientModule } from '@angular/common/http';{{/useHttpClient}}
{{^useHttpClient}}import { HttpModule } from '@angular/http';{{/useHttpClient}}
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
ApiModule,
{{#useHttpClient}}// make sure to import the HttpClientModule in the AppModule only,
// make sure to import the HttpClientModule in the AppModule only,
// see https://github.com/angular/angular/issues/20575
HttpClientModule{{/useHttpClient}}{{^useHttpClient}}HttpModule{{/useHttpClient}}
HttpClientModule
],
declarations: [ AppComponent ],
providers: [],
@@ -150,16 +134,15 @@ in order to avoid naming conflicts:
```
import { ApiModule } from 'my-api-path';
import { ApiModule as OtherApiModule } from 'my-other-api-path';
{{#useHttpClient}}import { HttpClientModule } from '@angular/common/http';{{/useHttpClient}}
{{^useHttpClient}}import { HttpModule } from '@angular/http';{{/useHttpClient}}
import { HttpClientModule } from '@angular/common/http';
@NgModule({
imports: [
ApiModule,
OtherApiModule,
{{#useHttpClient}}// make sure to import the HttpClientModule in the AppModule only,
// make sure to import the HttpClientModule in the AppModule only,
// see https://github.com/angular/angular/issues/20575
HttpClientModule{{/useHttpClient}}{{^useHttpClient}}HttpModule{{/useHttpClient}}
HttpClientModule
]
})
export class AppModule {

View File

@@ -1,7 +1,6 @@
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { Configuration } from './configuration';
{{#useHttpClient}}import { HttpClient } from '@angular/common/http';{{/useHttpClient}}
{{^useHttpClient}}import { Http } from '@angular/http';{{/useHttpClient}}
import { HttpClient } from '@angular/common/http';
{{#apiInfo}}
{{#apis}}
@@ -26,12 +25,12 @@ export class {{apiModuleClassName}} {
}
constructor( @Optional() @SkipSelf() parentModule: {{apiModuleClassName}},
@Optional() http: {{#useHttpClient}}HttpClient{{/useHttpClient}}{{^useHttpClient}}Http{{/useHttpClient}}) {
@Optional() http: HttpClient) {
if (parentModule) {
throw new Error('{{apiModuleClassName}} is already loaded. Import in your base AppModule only.');
}
if (!http) {
throw new Error('You need to import the {{#useHttpClient}}HttpClientModule{{/useHttpClient}}{{^useHttpClient}}HttpModule{{/useHttpClient}} in your AppModule! \n' +
throw new Error('You need to import the HttpClientModule in your AppModule! \n' +
'See also https://github.com/angular/angular/issues/20575');
}
}

View File

@@ -2,26 +2,10 @@
/* tslint:disable:no-unused-variable member-ordering */
import { Inject, Injectable, Optional } from '@angular/core';
{{#useHttpClient}}
import { HttpClient, HttpHeaders, HttpParams,
HttpResponse, HttpEvent, HttpParameterCodec } from '@angular/common/http';
import { CustomHttpParameterCodec } from '../encoder';
{{/useHttpClient}}
{{^useHttpClient}}
import { Http, Headers, URLSearchParams,
RequestMethod, RequestOptions, RequestOptionsArgs,
Response, ResponseContentType, QueryEncoder } from '@angular/http';
import { CustomQueryEncoderHelper } from '../encoder';
{{/useHttpClient}}
{{^useRxJS6}}
import { Observable } from 'rxjs/Observable';
{{/useRxJS6}}
{{#useRxJS6}}
import { Observable } from 'rxjs';
{{/useRxJS6}}
{{^useHttpClient}}
import '../rxjs-operators';
{{/useHttpClient}}
{{#imports}}
import { {{classname}} } from '../model/models';
@@ -75,16 +59,11 @@ export class {{classname}} {
{{/withInterfaces}}
protected basePath = '{{{basePath}}}';
public defaultHeaders = new {{#useHttpClient}}Http{{/useHttpClient}}Headers();
public defaultHeaders = new HttpHeaders();
public configuration = new Configuration();
{{#useHttpClient}}
public encoder: HttpParameterCodec;
{{/useHttpClient}}
{{^useHttpClient}}
public encoder: QueryEncoder;
{{/useHttpClient}}
constructor(protected {{#useHttpClient}}httpClient: HttpClient{{/useHttpClient}}{{^useHttpClient}}http: Http{{/useHttpClient}}, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
if (configuration) {
this.configuration = configuration;
}
@@ -94,12 +73,7 @@ export class {{classname}} {
}
this.configuration.basePath = basePath;
}
{{#useHttpClient}}
this.encoder = this.configuration.encoder || new CustomHttpParameterCodec();
{{/useHttpClient}}
{{^useHttpClient}}
this.encoder = this.configuration.encoder || new CustomQueryEncoderHelper();
{{/useHttpClient}}
}
{{#hasSomeFormParams}}
@@ -118,45 +92,11 @@ export class {{classname}} {
}
{{/hasSomeFormParams}}
{{^useHttpClient}}
{{! Before HttpClient implementation or method overloading we relied on 2 functions, 1 to return the straight body as json
and another to get the full response.}}
{{#operation}}
/**
* {{&notes}}
{{#summary}}
* @summary {{&summary}}
{{/summary}}
{{^useSingleRequestParameter}}{{#allParams}}
* @param {{paramName}} {{description}}{{/allParams}}{{/useSingleRequestParameter}}
{{#useSingleRequestParameter}}{{#allParams.0}}
* @param requestParameters
{{/allParams.0}}{{/useSingleRequestParameter}}*/
{{! if you change this method signature, also change the version below }}
public {{nickname}}({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}RequestParams{{/allParams.0}}{{/useSingleRequestParameter}}{{^useHttpClient}}{{#hasParams}}, {{/hasParams}}extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}> {
return this.{{nickname}}WithHttpInfo({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}, {{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters, {{/allParams.0}}{{/useSingleRequestParameter}}extraHttpRequestParams)
.map((response: Response) => {
if (response.status === 204) {
return undefined;
} else {
{{^isResponseFile}}
return response.json() || {};
{{/isResponseFile}}
{{#isResponseFile}}
return response.blob();
{{/isResponseFile}}
}
});
}
{{/operation}}
{{/useHttpClient}}
private addToHttpParams(httpParams: HttpParams, value: any, key?: string): HttpParams {
if (typeof value === "object" && value instanceof Date === false) {
{{#useHttpClient}}httpParams = {{/useHttpClient}}this.addToHttpParamsRecursive(httpParams, value);
httpParams = this.addToHttpParamsRecursive(httpParams, value);
} else {
{{#useHttpClient}}httpParams = {{/useHttpClient}}this.addToHttpParamsRecursive(httpParams, value, key);
httpParams = this.addToHttpParamsRecursive(httpParams, value, key);
}
return httpParams;
}
@@ -171,17 +111,17 @@ export class {{classname}} {
(value as any[]).forEach( elem => httpParams = this.addToHttpParamsRecursive(httpParams, elem, key));
} else if (value instanceof Date) {
if (key != null) {
{{#useHttpClient}}httpParams = {{/useHttpClient}}httpParams.append(key,
httpParams = httpParams.append(key,
(value as Date).toISOString(){{^isDateTime}}.substr(0, 10)){{/isDateTime}};
} else {
throw Error("key may not be null if value is Date");
}
} else {
Object.keys(value).forEach( k => {{#useHttpClient}}httpParams = {{/useHttpClient}}this.addToHttpParamsRecursive(
Object.keys(value).forEach( k => httpParams = this.addToHttpParamsRecursive(
httpParams, value[k], key != null ? `${key}.${k}` : k));
}
} else if (key != null) {
{{#useHttpClient}}httpParams = {{/useHttpClient}}httpParams.append(key, value);
httpParams = httpParams.append(key, value);
} else {
throw Error("key may not be null if value is not object or array");
}
@@ -206,20 +146,13 @@ export class {{classname}} {
* @param requestParameters
{{/allParams.0}}
{{/useSingleRequestParameter}}
{{#useHttpClient}}
* @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body.
* @param reportProgress flag to report request and response progress.
{{/useHttpClient}}
*/
{{#useHttpClient}}
public {{nickname}}({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}RequestParams, {{/allParams.0}}{{/useSingleRequestParameter}}observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: {{#produces}}'{{mediaType}}'{{#hasMore}} | {{/hasMore}}{{/produces}}{{^produces}}undefined{{/produces}}}): Observable<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>;
public {{nickname}}({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}RequestParams, {{/allParams.0}}{{/useSingleRequestParameter}}observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: {{#produces}}'{{mediaType}}'{{#hasMore}} | {{/hasMore}}{{/produces}}{{^produces}}undefined{{/produces}}}): Observable<HttpResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
public {{nickname}}({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}RequestParams, {{/allParams.0}}{{/useSingleRequestParameter}}observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: {{#produces}}'{{mediaType}}'{{#hasMore}} | {{/hasMore}}{{/produces}}{{^produces}}undefined{{/produces}}}): Observable<HttpEvent<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
public {{nickname}}({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}RequestParams, {{/allParams.0}}{{/useSingleRequestParameter}}observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: {{#produces}}'{{mediaType}}'{{#hasMore}} | {{/hasMore}}{{/produces}}{{^produces}}undefined{{/produces}}}): Observable<any> {
{{/useHttpClient}}
{{^useHttpClient}}
public {{nickname}}WithHttpInfo({{^useSingleRequestParameter}}{{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{/useSingleRequestParameter}}{{#useSingleRequestParameter}}{{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}RequestParams, {{/allParams.0}}{{/useSingleRequestParameter}}extraHttpRequestParams?: RequestOptionsArgs, options?: {httpHeaderAccept?: {{#produces}}'{{mediaType}}'{{#hasMore}} | {{/hasMore}}{{/produces}}{{^produces}}undefined{{/produces}}}): Observable<Response> {
{{/useHttpClient}}
{{#allParams}}
{{#useSingleRequestParameter}}
const {{paramName}} = requestParameters.{{paramName}};
@@ -232,46 +165,41 @@ export class {{classname}} {
{{/allParams}}
{{#hasQueryParams}}
{{#useHttpClient}}
let queryParameters = new HttpParams({encoder: this.encoder});
{{/useHttpClient}}
{{^useHttpClient}}
let queryParameters = new URLSearchParams('', this.encoder);
{{/useHttpClient}}
{{#queryParams}}
{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
{{#useHttpClient}}queryParameters = {{/useHttpClient}}this.addToHttpParams(queryParameters,
queryParameters = this.addToHttpParams(queryParameters,
<any>element, '{{baseName}}');
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
{{#useHttpClient}}queryParameters = {{/useHttpClient}}this.addToHttpParams(queryParameters,
queryParameters = this.addToHttpParams(queryParameters,
{{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']), '{{baseName}}');
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined && {{paramName}} !== null) {
{{#useHttpClient}}queryParameters = {{/useHttpClient}}this.addToHttpParams(queryParameters,
queryParameters = this.addToHttpParams(queryParameters,
<any>{{paramName}}, '{{baseName}}');
}
{{/isListContainer}}
{{/queryParams}}
{{/hasQueryParams}}
let headers = {{#useHttpClient}}this.defaultHeaders;{{/useHttpClient}}{{^useHttpClient}}new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845{{/useHttpClient}}
let headers = this.defaultHeaders;
{{#headerParams}}
{{#isListContainer}}
if ({{paramName}}) {
{{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
headers = headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}']));
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined && {{paramName}} !== null) {
{{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{baseName}}', String({{paramName}}));
headers = headers.set('{{baseName}}', String({{paramName}}));
}
{{/isListContainer}}
{{/headerParams}}
@@ -284,10 +212,10 @@ export class {{classname}} {
const key: string | undefined = this.configuration.apiKeys["{{name}}"] || this.configuration.apiKeys["{{keyParamName}}"];
if (key) {
{{#isKeyInHeader}}
{{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{keyParamName}}', key);
headers = headers.set('{{keyParamName}}', key);
{{/isKeyInHeader}}
{{#isKeyInQuery}}
{{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{keyParamName}}', key);
queryParameters = queryParameters.set('{{keyParamName}}', key);
{{/isKeyInQuery}}
}
}
@@ -296,7 +224,7 @@ export class {{classname}} {
{{#isBasic}}
{{#isBasicBasic}}
if (this.configuration.username || this.configuration.password) {
{{#useHttpClient}}headers = {{/useHttpClient}}headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
headers = headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password));
}
{{/isBasicBasic}}
{{#isBasicBearer}}
@@ -304,7 +232,7 @@ export class {{classname}} {
const accessToken = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken()
: this.configuration.accessToken;
{{#useHttpClient}}headers = {{/useHttpClient}}headers.set('Authorization', 'Bearer ' + accessToken);
headers = headers.set('Authorization', 'Bearer ' + accessToken);
}
{{/isBasicBearer}}
{{/isBasic}}
@@ -313,7 +241,7 @@ export class {{classname}} {
const accessToken = typeof this.configuration.accessToken === 'function'
? this.configuration.accessToken()
: this.configuration.accessToken;
{{#useHttpClient}}headers = {{/useHttpClient}}headers.set('Authorization', 'Bearer ' + accessToken);
headers = headers.set('Authorization', 'Bearer ' + accessToken);
}
{{/isOAuth}}
@@ -329,12 +257,7 @@ export class {{classname}} {
httpHeaderAcceptSelected = this.configuration.selectHeaderAccept(httpHeaderAccepts);
}
if (httpHeaderAcceptSelected !== undefined) {
{{^useHttpClient}}
headers.set('Accept', httpHeaderAcceptSelected);
{{/useHttpClient}}
{{#useHttpClient}}
headers = headers.set('Accept', httpHeaderAcceptSelected);
{{/useHttpClient}}
}
{{#bodyParam}}
@@ -359,12 +282,7 @@ export class {{classname}} {
{{#bodyParam}}
const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes);
if (httpContentTypeSelected !== undefined) {
{{^useHttpClient}}
headers.set('Content-Type', httpContentTypeSelected);
{{/useHttpClient}}
{{#useHttpClient}}
headers = headers.set('Content-Type', httpContentTypeSelected);
{{/useHttpClient}}
}
{{/bodyParam}}
@@ -384,16 +302,7 @@ export class {{classname}} {
if (useForm) {
formParams = new FormData();
} else {
{{#useHttpClient}}
formParams = new HttpParams({encoder: this.encoder});
{{/useHttpClient}}
{{^useHttpClient}}
// TODO: this fails if a parameter is a file, the api can't consume "multipart/form-data" and a blob is passed.
convertFormParamsToString = true;
formParams = new URLSearchParams('', this.encoder);
// set the content-type explicitly to avoid having it set to 'text/plain'
headers.set('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8');
{{/useHttpClient}}
}
{{#formParams}}
@@ -401,29 +310,28 @@ export class {{classname}} {
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
{{paramName}}.forEach((element) => {
{{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', <any>element){{#useHttpClient}} as any || formParams{{/useHttpClient}};
formParams = formParams.append('{{baseName}}', <any>element) as any || formParams;
})
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
if (useForm) {
{{paramName}}.forEach((element) => {
{{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', <any>element){{#useHttpClient}} as any || formParams{{/useHttpClient}};
formParams = formParams.append('{{baseName}}', <any>element) as any || formParams;
})
} else {
{{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])){{#useHttpClient}} as any || formParams{{/useHttpClient}};
formParams = formParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])) as any || formParams;
}
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
{{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', {{^isModel}}<any>{{paramName}}{{/isModel}}{{#isModel}}useForm ? new Blob([JSON.stringify({{paramName}})], {type: 'application/json'}) : <any>{{paramName}}{{/isModel}}){{#useHttpClient}} as any || formParams{{/useHttpClient}};
formParams = formParams.append('{{baseName}}', {{^isModel}}<any>{{paramName}}{{/isModel}}{{#isModel}}useForm ? new Blob([JSON.stringify({{paramName}})], {type: 'application/json'}) : <any>{{paramName}}{{/isModel}}) as any || formParams;
}
{{/isListContainer}}
{{/formParams}}
{{/hasFormParams}}
{{#useHttpClient}}
{{^isResponseFile}}
let responseType: 'text' | 'json' = 'json';
if(httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text')) {
@@ -449,35 +357,6 @@ export class {{classname}} {
reportProgress: reportProgress
}
);
{{/useHttpClient}}
{{^useHttpClient}}
let requestOptions: RequestOptionsArgs = new RequestOptions({
method: {{httpMethod}},
headers: headers,
{{#bodyParam}}
body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612
{{/bodyParam}}
{{#hasFormParams}}
body: convertFormParamsToString ? formParams.toString() : formParams,
{{/hasFormParams}}
{{#isResponseFile}}
responseType: ResponseContentType.Blob,
{{/isResponseFile}}
{{^isResponseFile}}
responseType: httpHeaderAcceptSelected && httpHeaderAcceptSelected.startsWith('text') ? ResponseContentType.Text : ResponseContentType.Json,
{{/isResponseFile}}
{{#hasQueryParams}}
search: queryParameters,
{{/hasQueryParams}}
withCredentials:this.configuration.withCredentials
});
// issues#4037
if (extraHttpRequestParams) {
requestOptions = (<any>Object).assign(requestOptions, extraHttpRequestParams);
}
return this.http.request(`${this.configuration.basePath}{{{path}}}`, requestOptions);
{{/useHttpClient}}
}
{{/operation}}}

View File

@@ -1,17 +1,7 @@
{{>licenseInfo}}
{{#useHttpClient}}
import { HttpHeaders } from '@angular/common/http';
{{/useHttpClient}}
{{^useHttpClient}}
import { Headers } from '@angular/http';
{{/useHttpClient}}
{{^useRxJS6}}
import { Observable } from 'rxjs/Observable';
{{/useRxJS6}}
{{#useRxJS6}}
import { Observable } from 'rxjs';
{{/useRxJS6}}
{{#imports}}
import { {{classname}} } from '../model/models';
@@ -41,9 +31,8 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn
*/
{{/description}}
export interface {{classname}}Interface {
defaultHeaders: {{#useHttpClient}}Http{{/useHttpClient}}Headers;
defaultHeaders: HttpHeaders;
configuration: Configuration;
{{^useHttpClient}}[others: string]: any;{{/useHttpClient}}
{{#operation}}
/**

View File

@@ -1,9 +1,4 @@
{{#useHttpClient}}
import { HttpParameterCodec } from '@angular/common/http';
{{/useHttpClient}}
{{^useHttpClient}}
import { QueryEncoder } from '@angular/http';
{{/useHttpClient}}
export interface ConfigurationParameters {
apiKeys?: {[ key: string ]: string};
@@ -12,12 +7,7 @@ export interface ConfigurationParameters {
accessToken?: string | (() => string);
basePath?: string;
withCredentials?: boolean;
{{#useHttpClient}}
encoder?: HttpParameterCodec;
{{/useHttpClient}}
{{^useHttpClient}}
encoder?: QueryEncoder;
{{/useHttpClient}}
}
export class Configuration {
@@ -27,12 +17,7 @@ export class Configuration {
accessToken?: string | (() => string);
basePath?: string;
withCredentials?: boolean;
{{#useHttpClient}}
encoder?: HttpParameterCodec;
{{/useHttpClient}}
{{^useHttpClient}}
encoder?: QueryEncoder;
{{/useHttpClient}}
constructor(configurationParameters: ConfigurationParameters = {}) {
this.apiKeys = configurationParameters.apiKeys;

View File

@@ -1,11 +1,5 @@
{{#useHttpClient}}
import { HttpParameterCodec } from '@angular/common/http';
{{/useHttpClient}}
{{^useHttpClient}}
import { QueryEncoder } from '@angular/http';
{{/useHttpClient}}
{{#useHttpClient}}
/**
* Custom HttpParameterCodec
* Workaround for https://github.com/angular/angular/issues/18261
@@ -24,22 +18,3 @@ export class CustomHttpParameterCodec implements HttpParameterCodec {
return decodeURIComponent(v);
}
}
{{/useHttpClient}}
{{^useHttpClient}}
/**
* Custom QueryEncoder
* Fix plus sign (+) not encoding, so sent as blank space
* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318
*/
export class CustomQueryEncoderHelper extends QueryEncoder {
encodeKey(k: string): string {
k = super.encodeKey(k);
return k.replace(/\+/gi, '%2B');
}
encodeValue(v: string): string {
v = super.encodeValue(v);
return v.replace(/\+/gi, '%2B');
}
}
{{/useHttpClient}}

View File

@@ -8,39 +8,23 @@
"openapi-generator"
],
"license": "Unlicense",
{{#useNgPackagr}}
"scripts": {
"build": "ng-packagr -p ng-package.json"
},
{{/useNgPackagr}}
{{^useNgPackagr}}
"main": "dist/index.js",
"module": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"build": "ngc && npm pack"
},
{{/useNgPackagr}}
"peerDependencies": {
"@angular/core": "^{{ngVersion}}",{{^useHttpClient}}
"@angular/http": "^{{ngVersion}}",{{/useHttpClient}}
"@angular/common": "^{{ngVersion}}",
"@angular/compiler": "^{{ngVersion}}",
"core-js": "^2.4.0",
"reflect-metadata": "^0.1.3",
"@angular/core": "^{{ngVersion}}",
"rxjs": "^{{rxjsVersion}}"
},
"devDependencies": {
"@angular/common": "^{{ngVersion}}",
"@angular/compiler": "^{{ngVersion}}",
"@angular/compiler-cli": "^{{ngVersion}}",
"@angular/core": "^{{ngVersion}}",{{^useHttpClient}}
"@angular/http": "^{{ngVersion}}",{{/useHttpClient}}
"@angular/platform-browser": "^{{ngVersion}}",{{#useNgPackagr}}
"ng-packagr": "^{{ngPackagrVersion}}",{{/useNgPackagr}}
"@angular/core": "^{{ngVersion}}",
"@angular/platform-browser": "^{{ngVersion}}",
"ng-packagr": "^{{ngPackagrVersion}}",
"reflect-metadata": "^0.1.3",
"rxjs": "^{{rxjsVersion}}",{{#useNgPackagr}}{{^useOldNgPackagr}}
"tsickle": "^{{tsickleVersion}}",{{/useOldNgPackagr}}{{/useNgPackagr}}
"rxjs": "^{{rxjsVersion}}",
"tsickle": "^{{tsickleVersion}}",
"typescript": "{{{tsVersion}}}",
"zone.js": "^{{zonejsVersion}}"
}{{#npmRepository}},

View File

@@ -1,11 +0,0 @@
// RxJS imports according to https://angular.io/docs/ts/latest/guide/server-communication.html#!#rxjs
// See node_module/rxjs/Rxjs.js
// Import just the rxjs statics and operators we need for THIS app.
// Statics
import 'rxjs/add/observable/throw';
// Operators
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';

View File

@@ -24,9 +24,5 @@
"filesGlob": [
"./model/*.ts",
"./api/*.ts"
]{{^useNgPackagr}},
"angularCompilerOptions": {
"genDir": "dist",
"skipTemplateCodegen": true
}{{/useNgPackagr}}
]
}

View File

@@ -1,6 +1,6 @@
import { {{injectionToken}} } from '@angular/core';
import { InjectionToken } from '@angular/core';
export const BASE_PATH = new {{injectionToken}}{{#injectionTokenTyped}}<string>{{/injectionTokenTyped}}('basePath');
export const BASE_PATH = new InjectionToken<string>('basePath');
export const COLLECTION_FORMATS = {
'csv': ',',
'tsv': ' ',