diff --git a/bin/typescript-angular-v4.3-petstore-with-npm.sh b/bin/typescript-angular-v4.3-petstore-with-npm.sh old mode 100644 new mode 100755 diff --git a/bin/windows/typescript-angular-v4.3-with-npm.bat b/bin/windows/typescript-angular-v4.3-with-npm.bat new file mode 100644 index 00000000000..5ad1cbd9b2d --- /dev/null +++ b/bin/windows/typescript-angular-v4.3-with-npm.bat @@ -0,0 +1,10 @@ +set executable=.\modules\swagger-codegen-cli\target\swagger-codegen-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M +set ags=generate -i modules\swagger-codegen\src\test\resources\2_0\petstore.yaml -c bin\typescript-petstore-npm.json -l typescript-angular -o samples\client\petstore\typescript-angular-v4.3\npm --additional-properties ngVersion=4.3 + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache index 56e0e67dce8..ea2b19b7885 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache @@ -20,7 +20,12 @@ import { {{classname}} } from '../{{filename}}'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +{{#useHttpClient}} +import { CustomHttpUrlEncodingCodec } from '../encoder'; +{{/useHttpClient}} +{{^useHttpClient}} import { CustomQueryEncoderHelper } from '../encoder'; +{{/useHttpClient}} {{#withInterfaces}} import { {{classname}}Interface } from './{{classname}}Interface'; {{/withInterfaces}} @@ -69,11 +74,6 @@ export class {{classname}} { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - {{^useHttpClient}} {{! not sure why we used to generate a second method here rather than inlining those few lines of code, but let's keep it for now for the sake of backwards compatiblity. }} @@ -121,7 +121,12 @@ export class {{classname}} { {{/allParams}} {{#hasQueryParams}} - let queryParameters = new {{#useHttpClient}}HttpParams{{/useHttpClient}}{{^useHttpClient}}URLSearchParams{{/useHttpClient}}(); + {{#useHttpClient}} + let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); + {{/useHttpClient}} + {{^useHttpClient}} + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + {{/useHttpClient}} {{#queryParams}} {{#isListContainer}} if ({{paramName}}) { @@ -207,39 +212,59 @@ export class {{classname}} { '{{{mediaType}}}'{{#hasMore}},{{/hasMore}} {{/consumes}} ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; + let convertFormParamsToString = false; {{#formParams}} {{#isFile}} + // use FormData to transmit files using content-type "multipart/form-data" + // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm; {{/isFile}} {{/formParams}} - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + if (useForm) { + formParams = new FormData(); + } else { +{{#useHttpClient}} + 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. + convertFormParamsToString = true; + formParams = new URLSearchParams('', new CustomQueryEncoderHelper()); + // 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}} {{#isListContainer}} if ({{paramName}}) { {{#isCollectionFormatMulti}} {{paramName}}.forEach((element) => { - formParams.append('{{baseName}}', element); + {{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', element){{#useHttpClient}} || formParams{{/useHttpClient}}; }) {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} - formParams.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + {{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])){{#useHttpClient}} || formParams{{/useHttpClient}}; {{/isCollectionFormatMulti}} } {{/isListContainer}} {{^isListContainer}} if ({{paramName}} !== undefined) { - formParams.set('{{baseName}}', {{paramName}}); + {{#useHttpClient}}formParams = {{/useHttpClient}}formParams.append('{{baseName}}', {{paramName}}){{#useHttpClient}} || formParams{{/useHttpClient}}; } {{/isListContainer}} {{/formParams}} {{/hasFormParams}} {{#useHttpClient}} - return this.httpClient.{{httpMethod}}{{^isResponseFile}}{{/isResponseFile}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}}{{#hasFormParams}}formParams, {{/hasFormParams}}{ + return this.httpClient.{{httpMethod}}{{^isResponseFile}}{{/isResponseFile}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}} + {{#hasFormParams}}convertFormParamsToString ? formParams.toString() : formParams, {{/hasFormParams}}{ {{#hasQueryParams}} params: queryParameters, {{/hasQueryParams}} @@ -258,7 +283,7 @@ export class {{classname}} { body: {{paramName}} == null ? '' : JSON.stringify({{paramName}}), // https://github.com/angular/angular/issues/10612 {{/bodyParam}} {{#hasFormParams}} - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, {{/hasFormParams}} {{#isResponseFile}} responseType: ResponseContentType.Blob, diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/encoder.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/encoder.mustache index 319f79da15a..c3ac784124a 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/encoder.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/encoder.mustache @@ -1,5 +1,28 @@ -import { QueryEncoder } from "@angular/http"; +{{#useHttpClient}} + import { HttpUrlEncodingCodec } from '@angular/common/http'; +{{/useHttpClient}} +{{^useHttpClient}} + import { QueryEncoder } from '@angular/http'; +{{/useHttpClient}} +{{#useHttpClient}} +/** +* CustomHttpUrlEncodingCodec +* Fix plus sign (+) not encoding, so sent as blank space +* See: https://github.com/angular/angular/issues/11058#issuecomment-247367318 +*/ +export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { + 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}} +{{^useHttpClient}} /** * CustomQueryEncoderHelper * Fix plus sign (+) not encoding, so sent as blank space @@ -14,4 +37,6 @@ export class CustomQueryEncoderHelper extends QueryEncoder { v = super.encodeValue(v); return v.replace(/\+/gi, '%2B'); } -} \ No newline at end of file +} +{{/useHttpClient}} + diff --git a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts index 481f693424e..11a1b603831 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/pet.service.ts @@ -60,11 +60,6 @@ export class PetService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -282,7 +277,7 @@ export class PetService { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } @@ -321,7 +316,7 @@ export class PetService { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } @@ -442,22 +437,34 @@ export class PetService { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + let convertFormParamsToString = false; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (name !== undefined) { - formParams.set('name', name); + formParams.append('name', name); } if (status !== undefined) { - formParams.set('status', status); + formParams.append('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -494,23 +501,37 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; + let convertFormParamsToString = false; + // use FormData to transmit files using content-type "multipart/form-data" + // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.append('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.set('file', file); + formParams.append('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts index fba4c08d9aa..393d291ba3d 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/store.service.ts @@ -59,11 +59,6 @@ export class StoreService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @summary Delete purchase order by ID diff --git a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts index d7c9ee1510a..f495f1f9d39 100644 --- a/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/default/api/user.service.ts @@ -59,11 +59,6 @@ export class UserService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * This can only be done by the logged in user. * @summary Create user @@ -342,7 +337,7 @@ export class UserService { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (username !== undefined) { queryParameters.set('username', username); } diff --git a/samples/client/petstore/typescript-angular-v2/default/encoder.ts b/samples/client/petstore/typescript-angular-v2/default/encoder.ts index 319f79da15a..6fcda7b246d 100644 --- a/samples/client/petstore/typescript-angular-v2/default/encoder.ts +++ b/samples/client/petstore/typescript-angular-v2/default/encoder.ts @@ -1,4 +1,4 @@ -import { QueryEncoder } from "@angular/http"; + import { QueryEncoder } from '@angular/http'; /** * CustomQueryEncoderHelper @@ -14,4 +14,5 @@ export class CustomQueryEncoderHelper extends QueryEncoder { v = super.encodeValue(v); return v.replace(/\+/gi, '%2B'); } -} \ No newline at end of file +} + diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts index 481f693424e..11a1b603831 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/pet.service.ts @@ -60,11 +60,6 @@ export class PetService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -282,7 +277,7 @@ export class PetService { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } @@ -321,7 +316,7 @@ export class PetService { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } @@ -442,22 +437,34 @@ export class PetService { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + let convertFormParamsToString = false; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (name !== undefined) { - formParams.set('name', name); + formParams.append('name', name); } if (status !== undefined) { - formParams.set('status', status); + formParams.append('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -494,23 +501,37 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; + let convertFormParamsToString = false; + // use FormData to transmit files using content-type "multipart/form-data" + // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.append('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.set('file', file); + formParams.append('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts index fba4c08d9aa..393d291ba3d 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/store.service.ts @@ -59,11 +59,6 @@ export class StoreService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @summary Delete purchase order by ID diff --git a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts index d7c9ee1510a..f495f1f9d39 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/api/user.service.ts @@ -59,11 +59,6 @@ export class UserService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * This can only be done by the logged in user. * @summary Create user @@ -342,7 +337,7 @@ export class UserService { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (username !== undefined) { queryParameters.set('username', username); } diff --git a/samples/client/petstore/typescript-angular-v2/npm/encoder.ts b/samples/client/petstore/typescript-angular-v2/npm/encoder.ts index 319f79da15a..6fcda7b246d 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v2/npm/encoder.ts @@ -1,4 +1,4 @@ -import { QueryEncoder } from "@angular/http"; + import { QueryEncoder } from '@angular/http'; /** * CustomQueryEncoderHelper @@ -14,4 +14,5 @@ export class CustomQueryEncoderHelper extends QueryEncoder { v = super.encodeValue(v); return v.replace(/\+/gi, '%2B'); } -} \ No newline at end of file +} + diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index b87a0bd2288..8ff5eda659d 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts @@ -61,11 +61,6 @@ export class PetService implements PetServiceInterface { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -283,7 +278,7 @@ export class PetService implements PetServiceInterface { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } @@ -322,7 +317,7 @@ export class PetService implements PetServiceInterface { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } @@ -443,22 +438,34 @@ export class PetService implements PetServiceInterface { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + let convertFormParamsToString = false; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (name !== undefined) { - formParams.set('name', name); + formParams.append('name', name); } if (status !== undefined) { - formParams.set('status', status); + formParams.append('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -495,23 +502,37 @@ export class PetService implements PetServiceInterface { let consumes: string[] = [ 'multipart/form-data' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; + let convertFormParamsToString = false; + // use FormData to transmit files using content-type "multipart/form-data" + // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.append('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.set('file', file); + formParams.append('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts index d5a468340c4..1297e638d43 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/store.service.ts @@ -60,11 +60,6 @@ export class StoreService implements StoreServiceInterface { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @summary Delete purchase order by ID diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts index 3574e7f2c7e..480d00b3bb6 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/user.service.ts @@ -60,11 +60,6 @@ export class UserService implements UserServiceInterface { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * This can only be done by the logged in user. * @summary Create user @@ -343,7 +338,7 @@ export class UserService implements UserServiceInterface { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (username !== undefined) { queryParameters.set('username', username); } diff --git a/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts index 319f79da15a..6fcda7b246d 100644 --- a/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts +++ b/samples/client/petstore/typescript-angular-v2/with-interfaces/encoder.ts @@ -1,4 +1,4 @@ -import { QueryEncoder } from "@angular/http"; + import { QueryEncoder } from '@angular/http'; /** * CustomQueryEncoderHelper @@ -14,4 +14,5 @@ export class CustomQueryEncoderHelper extends QueryEncoder { v = super.encodeValue(v); return v.replace(/\+/gi, '%2B'); } -} \ No newline at end of file +} + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts index 9e7e00d1e48..ee44df243de 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -23,7 +23,7 @@ import { Pet } from '../model/pet'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; -import { CustomQueryEncoderHelper } from '../encoder'; +import { CustomHttpUrlEncodingCodec } from '../encoder'; @Injectable() @@ -58,6 +58,7 @@ export class PetService { } + /** * Add a new pet to the store * @@ -78,7 +79,8 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.post(`${this.basePath}/pet`, body, { + return this.httpClient.post(`${this.basePath}/pet`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -108,7 +110,8 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(petId)}`, { + return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -124,7 +127,7 @@ export class PetService { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } - let queryParameters = new HttpParams(); + let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (status) { queryParameters = queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } @@ -139,7 +142,8 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.get(`${this.basePath}/pet/findByStatus`, { + return this.httpClient.get(`${this.basePath}/pet/findByStatus`, + { params: queryParameters, headers: headers, withCredentials: this.configuration.withCredentials, @@ -156,7 +160,7 @@ export class PetService { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } - let queryParameters = new HttpParams(); + let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (tags) { queryParameters = queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } @@ -171,7 +175,8 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.get(`${this.basePath}/pet/findByTags`, { + return this.httpClient.get(`${this.basePath}/pet/findByTags`, + { params: queryParameters, headers: headers, withCredentials: this.configuration.withCredentials, @@ -195,7 +200,8 @@ export class PetService { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(petId)}`, { + return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -221,7 +227,8 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.put(`${this.basePath}/pet`, body, { + return this.httpClient.put(`${this.basePath}/pet`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -253,19 +260,28 @@ export class PetService { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + let convertFormParamsToString = false; + if (useForm) { + formParams = new FormData(); + } else { + formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); + } + + + if (name !== undefined) { - formParams.set('name', name); + formParams = formParams.append('name', name) || formParams; } if (status !== undefined) { - formParams.set('status', status); + formParams = formParams.append('status', status) || formParams; } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(petId)}`, formParams, { + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}`, + convertFormParamsToString ? formParams.toString() : formParams, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -297,20 +313,31 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; + let convertFormParamsToString = false; + // use FormData to transmit files using content-type "multipart/form-data" + // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + if (useForm) { + formParams = new FormData(); + } else { + formParams = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); + } + + + if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams = formParams.append('additionalMetadata', additionalMetadata) || formParams; } if (file !== undefined) { - formParams.set('file', file); + formParams = formParams.append('file', file) || formParams; } - return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(petId)}/uploadImage`, formParams, { + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(String(petId))}/uploadImage`, + convertFormParamsToString ? formParams.toString() : formParams, { headers: headers, withCredentials: this.configuration.withCredentials, }); diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts index e52b46095ce..f0cf7dbc1cb 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -22,7 +22,7 @@ import { Order } from '../model/order'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; -import { CustomQueryEncoderHelper } from '../encoder'; +import { CustomHttpUrlEncodingCodec } from '../encoder'; @Injectable() @@ -57,6 +57,7 @@ export class StoreService { } + /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors @@ -69,7 +70,8 @@ export class StoreService { let headers = this.defaultHeaders; - return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, { + return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -88,7 +90,8 @@ export class StoreService { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - return this.httpClient.get(`${this.basePath}/store/inventory`, { + return this.httpClient.get(`${this.basePath}/store/inventory`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -106,7 +109,8 @@ export class StoreService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, { + return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(String(orderId))}`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -124,7 +128,8 @@ export class StoreService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/store/order`, body, { + return this.httpClient.post(`${this.basePath}/store/order`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts index cc53d7367bc..d67fb448fc3 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -22,7 +22,7 @@ import { User } from '../model/user'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; -import { CustomQueryEncoderHelper } from '../encoder'; +import { CustomHttpUrlEncodingCodec } from '../encoder'; @Injectable() @@ -57,6 +57,7 @@ export class UserService { } + /** * Create user * This can only be done by the logged in user. @@ -69,7 +70,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/user`, body, { + return this.httpClient.post(`${this.basePath}/user`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -87,7 +89,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/user/createWithArray`, body, { + return this.httpClient.post(`${this.basePath}/user/createWithArray`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -105,7 +108,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.post(`${this.basePath}/user/createWithList`, body, { + return this.httpClient.post(`${this.basePath}/user/createWithList`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -123,7 +127,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(username)}`, { + return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -141,7 +146,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(username)}`, { + return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(String(username))}`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -161,7 +167,7 @@ export class UserService { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } - let queryParameters = new HttpParams(); + let queryParameters = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()}); if (username !== undefined) { queryParameters = queryParameters.set('username', username); } @@ -171,7 +177,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/login`, { + return this.httpClient.get(`${this.basePath}/user/login`, + { params: queryParameters, headers: headers, withCredentials: this.configuration.withCredentials, @@ -186,7 +193,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/logout`, { + return this.httpClient.get(`${this.basePath}/user/logout`, + { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -208,7 +216,8 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(username)}`, body, { + return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(String(username))}`, body, + { headers: headers, withCredentials: this.configuration.withCredentials, }); diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts b/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts index 319f79da15a..f1c6b78c9c8 100644 --- a/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts @@ -1,11 +1,11 @@ -import { QueryEncoder } from "@angular/http"; + import { HttpUrlEncodingCodec } from '@angular/common/http'; /** -* CustomQueryEncoderHelper +* CustomHttpUrlEncodingCodec * 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 { +export class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec { encodeKey(k: string): string { k = super.encodeKey(k); return k.replace(/\+/gi, '%2B'); @@ -14,4 +14,5 @@ export class CustomQueryEncoderHelper extends QueryEncoder { v = super.encodeValue(v); return v.replace(/\+/gi, '%2B'); } -} \ No newline at end of file +} + diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index 481f693424e..11a1b603831 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts @@ -60,11 +60,6 @@ export class PetService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -282,7 +277,7 @@ export class PetService { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } @@ -321,7 +316,7 @@ export class PetService { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } @@ -442,22 +437,34 @@ export class PetService { let consumes: string[] = [ 'application/x-www-form-urlencoded' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + let convertFormParamsToString = false; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (name !== undefined) { - formParams.set('name', name); + formParams.append('name', name); } if (status !== undefined) { - formParams.set('status', status); + formParams.append('status', status); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -494,23 +501,37 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - let canConsumeForm = this.canConsumeForm(consumes); + const canConsumeForm = this.canConsumeForm(consumes); + + let formParams: { append(param: string, value: any): void; }; let useForm = false; + let convertFormParamsToString = false; + // use FormData to transmit files using content-type "multipart/form-data" + // see https://stackoverflow.com/questions/4007969/application-x-www-form-urlencoded-or-multipart-form-data useForm = canConsumeForm; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; + if (useForm) { + formParams = new FormData(); + } else { + // 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('', new CustomQueryEncoderHelper()); + // 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'); + } + + + if (additionalMetadata !== undefined) { - formParams.set('additionalMetadata', additionalMetadata); + formParams.append('additionalMetadata', additionalMetadata); } if (file !== undefined) { - formParams.set('file', file); + formParams.append('file', file); } let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, - body: formParams.toString(), + body: convertFormParamsToString ? formParams.toString() : formParams, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts index fba4c08d9aa..393d291ba3d 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/store.service.ts @@ -59,11 +59,6 @@ export class StoreService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @summary Delete purchase order by ID diff --git a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts index d7c9ee1510a..f495f1f9d39 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/api/user.service.ts @@ -59,11 +59,6 @@ export class UserService { } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * This can only be done by the logged in user. * @summary Create user @@ -342,7 +337,7 @@ export class UserService { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } - let queryParameters = new URLSearchParams(); + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); if (username !== undefined) { queryParameters.set('username', username); } diff --git a/samples/client/petstore/typescript-angular-v4/npm/encoder.ts b/samples/client/petstore/typescript-angular-v4/npm/encoder.ts index 319f79da15a..6fcda7b246d 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/encoder.ts +++ b/samples/client/petstore/typescript-angular-v4/npm/encoder.ts @@ -1,4 +1,4 @@ -import { QueryEncoder } from "@angular/http"; + import { QueryEncoder } from '@angular/http'; /** * CustomQueryEncoderHelper @@ -14,4 +14,5 @@ export class CustomQueryEncoderHelper extends QueryEncoder { v = super.encodeValue(v); return v.replace(/\+/gi, '%2B'); } -} \ No newline at end of file +} +