Skip to content

Make generated services conform to tslint rules set by angular-cli #7323

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class ApiModule {
return {
ngModule: ApiModule,
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
}
};
}

constructor( @Optional() @SkipSelf() parentModule: ApiModule) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
{{>licenseInfo}}
/* tslint:disable:no-unused-variable member-ordering */

import { Inject, Injectable, Optional } from '@angular/core';
import { Inject, Injectable, Optional } from '@angular/core';
{{#useHttpClient}}
import { HttpClient, HttpHeaders, HttpParams,
HttpResponse, HttpEvent } from '@angular/common/http';
import { CustomHttpUrlEncodingCodec } from '../encoder';
import {
HttpClient,
HttpHeaders,
HttpParams,
HttpResponse,
HttpEvent
} from '@angular/common/http';
import { CustomHttpUrlEncodingCodec } from '../encoder';
{{/useHttpClient}}
{{^useHttpClient}}
import { Http, Headers, URLSearchParams } from '@angular/http';
import { Http, Headers, URLSearchParams } from '@angular/http';
import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http';
import { Response, ResponseContentType } from '@angular/http';
import { CustomQueryEncoderHelper } from '../encoder';
import { Response, ResponseContentType } from '@angular/http';
import { CustomQueryEncoderHelper } from '../encoder';
{{/useHttpClient}}

import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs/Observable';
{{^useHttpClient}}
import '../rxjs-operators';
{{/useHttpClient}}
Expand All @@ -23,10 +28,10 @@ import '../rxjs-operators';
import { {{classname}} } from '../{{filename}}';
{{/imports}}

import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';
{{#withInterfaces}}
import { {{classname}}Interface } from './{{classname}}Interface';
import { {{classname}}Interface } from './{{classname}}Interface';
{{/withInterfaces}}

{{#operations}}
Expand All @@ -48,7 +53,7 @@ export class {{classname}} {
public defaultHeaders = new {{#useHttpClient}}Http{{/useHttpClient}}Headers();
public configuration = new Configuration();

constructor(protected {{#useHttpClient}}httpClient: HttpClient{{/useHttpClient}}{{^useHttpClient}}http: Http{{/useHttpClient}}, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
constructor(protected {{#useHttpClient}}httpClient: HttpClient{{/useHttpClient}}{{^useHttpClient}}http: Http{{/useHttpClient}}, @Optional() @Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
if (basePath) {
this.basePath = basePath;
}
Expand All @@ -64,7 +69,7 @@ export class {{classname}} {
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
for (const consume of consumes) {
if (form === consume) {
return true;
}
Expand Down Expand Up @@ -115,7 +120,7 @@ export class {{classname}} {
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}observe?: 'body', reportProgress?: boolean): Observable<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>;
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>>;
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}observe: any = 'body', reportProgress: boolean = false ): Observable<any> {
public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}observe: any = 'body', reportProgress: boolean = false): Observable<any> {
{{/useHttpClient}}
{{^useHttpClient}}
public {{nickname}}WithHttpInfo({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: RequestOptionsArgs): Observable<Response> {
Expand All @@ -130,7 +135,7 @@ export class {{classname}} {

{{#hasQueryParams}}
{{#useHttpClient}}
let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
let queryParameters = new HttpParams({ encoder: new CustomHttpUrlEncodingCodec() });
{{/useHttpClient}}
{{^useHttpClient}}
let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper());
Expand Down Expand Up @@ -208,35 +213,35 @@ export class {{classname}} {
{{/isOAuth}}
{{/authMethods}}
// to determine the Accept header
let httpHeaderAccepts: string[] = [
const httpHeaderAccepts: string[] = [
{{#produces}}
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
{{/produces}}
];
let httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
{{^useHttpClient}}
headers.set("Accept", httpHeaderAcceptSelected);
headers.set('Accept', httpHeaderAcceptSelected);
{{/useHttpClient}}
{{#useHttpClient}}
headers = headers.set("Accept", httpHeaderAcceptSelected);
headers = headers.set('Accept', httpHeaderAcceptSelected);
{{/useHttpClient}}
}

// to determine the Content-Type header
let consumes: string[] = [
const consumes: string[] = [
{{#consumes}}
'{{{mediaType}}}'{{#hasMore}},{{/hasMore}}
{{/consumes}}
];
{{#bodyParam}}
let httpContentTypeSelected:string | undefined = this.configuration.selectHeaderContentType(consumes);
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);
headers = headers.set('Content-Type', httpContentTypeSelected);
{{/useHttpClient}}
}
{{/bodyParam}}
Expand All @@ -258,7 +263,7 @@ export class {{classname}} {
formParams = new FormData();
} else {
{{#useHttpClient}}
formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
formParams = new HttpParams({ encoder: new CustomHttpUrlEncodingCodec() });
{{/useHttpClient}}
{{^useHttpClient}}
// TODO: this fails if a parameter is a file, the api can't consume "multipart/form-data" and a blob is passed.
Expand Down Expand Up @@ -298,7 +303,7 @@ export class {{classname}} {
params: queryParameters,
{{/hasQueryParams}}
{{#isResponseFile}}
responseType: "blob",
responseType: 'blob',
{{/isResponseFile}}
withCredentials: this.configuration.withCredentials,
headers: headers,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface ConfigurationParameters {
apiKeys?: {[ key: string ]: string};
apiKeys?: { [key: string ]: string };
username?: string;
password?: string;
accessToken?: string | (() => string);
Expand All @@ -8,7 +8,7 @@ export interface ConfigurationParameters {
}

export class Configuration {
apiKeys?: {[ key: string ]: string};
apiKeys?: { [key: string ]: string };
username?: string;
password?: string;
accessToken?: string | (() => string);
Expand All @@ -31,12 +31,12 @@ export class Configuration {
* @param {string[]} contentTypes - the array of content types that are available for selection
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderContentType (contentTypes: string[]): string | undefined {
if (contentTypes.length == 0) {
public selectHeaderContentType(contentTypes: string[]): string | undefined {
if (contentTypes.length === 0) {
return undefined;
}

let type = contentTypes.find(x => this.isJsonMime(x));
const type = contentTypes.find(x => this.isJsonMime(x));
if (type === undefined) {
return contentTypes[0];
}
Expand All @@ -51,11 +51,11 @@ export class Configuration {
* @returns {string} the selected content-type or <code>undefined</code> if no selection could be made.
*/
public selectHeaderAccept(accepts: string[]): string | undefined {
if (accepts.length == 0) {
if (accepts.length === 0) {
return undefined;
}

let type = accepts.find(x => this.isJsonMime(x));
const type = accepts.find(x => this.isJsonMime(x));
if (type === undefined) {
return accepts[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export * from './api/api';
export * from './model/models';
export * from './variables';
export * from './configuration';
export * from './api.module';
export * from './api.module';
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const COLLECTION_FORMATS = {
'tsv': ' ',
'ssv': ' ',
'pipes': '|'
}
};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.0-SNAPSHOT
2.3.0
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { Configuration } from './configuration';

import { FakeService } from './api/fake.service';

@NgModule({
imports: [ CommonModule, HttpModule ],
imports: [ CommonModule, HttpClientModule ],
declarations: [],
exports: [],
providers: [ FakeService ]
providers: [
FakeService ]
})
export class ApiModule {
public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders {
public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders {
return {
ngModule: ApiModule,
providers: [ {provide: Configuration, useFactory: configurationFactory}]
providers: [ { provide: Configuration, useFactory: configurationFactory } ]
};
}

constructor( @Optional() @SkipSelf() parentModule: ApiModule) {
if (parentModule) {
throw new Error('ApiModule is already loaded. Import your base AppModule only.');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/

/* tslint:disable:no-unused-variable member-ordering */

import { Inject, Injectable, Optional } from '@angular/core';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { Inject, Injectable, Optional } from '@angular/core';
import {
HttpClient,
HttpHeaders,
HttpParams,
HttpResponse,
HttpEvent
} from '@angular/common/http';
import { CustomHttpUrlEncodingCodec } from '../encoder';

import { Observable } from 'rxjs/Observable';
import '../rxjs-operators';
import { Observable } from 'rxjs/Observable';


import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';
import { CustomHttpUrlEncodingCodec } from '../encoder';
import { BASE_PATH, COLLECTION_FORMATS } from '../variables';
import { Configuration } from '../configuration';


@Injectable()
Expand All @@ -31,7 +35,7 @@ export class FakeService {
public defaultHeaders = new HttpHeaders();
public configuration = new Configuration();

constructor(protected httpClient: HttpClient, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
constructor(protected httpClient: HttpClient, @Optional() @Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
if (basePath) {
this.basePath = basePath;
}
Expand All @@ -47,7 +51,7 @@ export class FakeService {
*/
private canConsumeForm(consumes: string[]): boolean {
const form = 'multipart/form-data';
for (let consume of consumes) {
for (const consume of consumes) {
if (form === consume) {
return true;
}
Expand All @@ -56,21 +60,36 @@ export class FakeService {
}



/**
* To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
*
* @param test code inject * &#39; &quot; &#x3D;end rn n r To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
* @param testCodeInjectEndRnNR To test code injection *_/ &#39; \&quot; &#x3D;end -- \\r\\n \\n \\r
* @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.
*/
public testCodeInjectEndRnNR(test code inject * &#39; &quot; &#x3D;end rn n r?: string): Observable<{}> {
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'body', reportProgress?: boolean): Observable<any>;
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'response', reportProgress?: boolean): Observable<HttpResponse<any>>;
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe?: 'events', reportProgress?: boolean): Observable<HttpEvent<any>>;
public testCodeInjectEndRnNR(testCodeInjectEndRnNR?: string, observe: any = 'body', reportProgress: boolean = false): Observable<any> {

let headers = this.defaultHeaders;

// to determine the Accept header
const httpHeaderAccepts: string[] = [
'application/json',
'*_/ =end -- '
];
const httpHeaderAcceptSelected: string | undefined = this.configuration.selectHeaderAccept(httpHeaderAccepts);
if (httpHeaderAcceptSelected != undefined) {
headers = headers.set('Accept', httpHeaderAcceptSelected);
}

// to determine the Content-Type header
let consumes: string[] = [
const consumes: string[] = [
'application/json',
'*_/ =end -- '
];

const canConsumeForm = this.canConsumeForm(consumes);

let formParams: { append(param: string, value: any): void; };
Expand All @@ -79,20 +98,22 @@ export class FakeService {
if (useForm) {
formParams = new FormData();
} else {
formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()});
formParams = new HttpParams({ encoder: new CustomHttpUrlEncodingCodec() });
}



if (test code inject * &#39; &quot; &#x3D;end rn n r !== undefined) {
formParams = formParams.append('test code inject */ &#39; &quot; &#x3D;end -- \r\n \n \r', <any>test code inject * &#39; &quot; &#x3D;end rn n r) || formParams;
if (testCodeInjectEndRnNR !== undefined) {
formParams = formParams.append('test code inject */ &#39; &quot; &#x3D;end -- \r\n \n \r', <any>testCodeInjectEndRnNR) || formParams;
}

return this.httpClient.put<any>(`${this.basePath}/fake`,
convertFormParamsToString ? formParams.toString() : formParams, {
headers: headers,
withCredentials: this.configuration.withCredentials,
});
return this.httpClient.put<any>(`${this.basePath}/fake`,
convertFormParamsToString ? formParams.toString() : formParams,
{
withCredentials: this.configuration.withCredentials,
headers: headers,
observe: observe,
reportProgress: reportProgress
}
);
}

}
Loading