From 2d83994305ab541199e2971fcf61bb4b2c96fcdb Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 19:41:18 +0200 Subject: [PATCH 01/12] fix compilation error in eclipse by updating package declarations in moved files (eclipse validates that package and folder names match) --- .../TypeScriptAngularJsClientOptionsTest.java | 2 +- .../typescriptangularjs/TypeScriptAngularJsModelTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsClientOptionsTest.java index 21ec78e7552..49bad5d9335 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsClientOptionsTest.java @@ -1,4 +1,4 @@ -package io.swagger.codegen.typescript.typescriptangular; +package io.swagger.codegen.typescript.typescriptangularjs; import io.swagger.codegen.AbstractOptionsTest; import io.swagger.codegen.CodegenConfig; diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsModelTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsModelTest.java index 7f3fd744a20..cb0e7bec7f3 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsModelTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangularjs/TypeScriptAngularJsModelTest.java @@ -1,4 +1,4 @@ -package io.swagger.codegen.typescript.typescriptangular; +package io.swagger.codegen.typescript.typescriptangularjs; import io.swagger.codegen.CodegenModel; import io.swagger.codegen.CodegenProperty; From 8fff95d55ca88a76d4fbb74ed3147bf4e333cc93 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 20:32:33 +0200 Subject: [PATCH 02/12] permit specifying the full angular version simplifying the templates by moving trivial case splits to the model --- .../TypeScriptAngularClientCodegen.java | 31 +++++------------ .../java/io/swagger/codegen/utils/SemVer.java | 33 +++++++++++++++++++ .../typescript-angular/package.mustache | 18 +++++----- .../typescript-angular/variables.mustache | 4 +-- .../TypeScriptAngularClientOptionsTest.java | 2 -- 5 files changed, 53 insertions(+), 35 deletions(-) create mode 100644 modules/swagger-codegen/src/main/java/io/swagger/codegen/utils/SemVer.java diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index bd29088651f..73960ba59e8 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -14,6 +14,7 @@ import io.swagger.codegen.CodegenParameter; import io.swagger.codegen.CodegenOperation; import io.swagger.codegen.SupportingFile; +import io.swagger.codegen.utils.SemVer; import io.swagger.models.ModelImpl; import io.swagger.models.properties.ArrayProperty; import io.swagger.models.properties.BooleanProperty; @@ -35,7 +36,6 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode protected String npmName = null; protected String npmVersion = "1.0.0"; protected String npmRepository = null; - protected String ngVersion = "4"; public TypeScriptAngularClientCodegen() { super(); @@ -55,7 +55,7 @@ public TypeScriptAngularClientCodegen() { this.cliOptions.add(new CliOption(NPM_REPOSITORY, "Use this property to set an url your private npmRepo in the package.json")); this.cliOptions.add(new CliOption(SNAPSHOT, "When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString())); this.cliOptions.add(new CliOption(WITH_INTERFACES, "Setting this property to true will generate interfaces next to the default class implementations.", BooleanProperty.TYPE).defaultValue(Boolean.FALSE.toString())); - this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular (2 or 4). Default is '4'")); + this.cliOptions.add(new CliOption(NG_VERSION, "The version of Angular. Default is '4.3'")); } @Override @@ -100,21 +100,16 @@ public void processOpts() { } // determine NG version + SemVer ngVersion; if (additionalProperties.containsKey(NG_VERSION)) { - if ("2".equals(additionalProperties.get(NG_VERSION).toString())) { - additionalProperties.put("isNg2x", true); - setNgVersion("2"); - } else if ("4".equals(additionalProperties.get(NG_VERSION).toString())) { - additionalProperties.put("isNg4x", true); - setNgVersion("4"); - } else { - throw new IllegalArgumentException("Invalid ngVersion, which must be either '2' or '4'"); - } + ngVersion = new SemVer(additionalProperties.get(NG_VERSION).toString()); } else { - // default to 4 - additionalProperties.put("isNg4x", true); - setNgVersion("4"); + ngVersion = new SemVer("4.3.0"); } + 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("httpClientSupported", ngVersion.atLeast("4.3.0") ? "true" : null); } private void addNpmPackageGeneration() { @@ -316,14 +311,6 @@ public String toModelImport(String name) { return modelPackage() + "/" + toModelFilename(name); } - public String getNgVersion() { - return ngVersion; - } - - public void setNgVersion(String ngVersion) { - this.ngVersion = ngVersion; - } - public String getNpmName() { return npmName; } diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/utils/SemVer.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/utils/SemVer.java new file mode 100644 index 00000000000..ec8b17f31bb --- /dev/null +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/utils/SemVer.java @@ -0,0 +1,33 @@ +package io.swagger.codegen.utils; + +public class SemVer implements Comparable { + + public final int major; + public final int minor; + public final int revision; + + public SemVer(String versionString) { + String[] tokens = versionString.split("\\."); + major = Integer.parseInt(tokens[0]); + minor = tokens.length < 2 ? 0 : Integer.parseInt(tokens[1]); + revision = tokens.length < 3 ? 0 : Integer.parseInt(tokens[2]); + } + + @Override + public int compareTo(SemVer o) { + int cmp = major - o.major; + if (cmp != 0) return cmp; + cmp = minor - o.minor; + if (cmp != 0) return cmp; + return revision - o.revision; + } + + public boolean atLeast(String other) { + return compareTo(new SemVer(other)) >= 0; + } + + @Override + public String toString() { + return major + "." + minor + "." + revision; + } +} \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/package.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/package.mustache index 8c4dd1749b5..9123cb8eb66 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/package.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/package.mustache @@ -14,21 +14,21 @@ "postinstall": "npm run build" }, "peerDependencies": { - "@angular/core": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/http": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/common": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/compiler": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", + "@angular/core": "^{{ngVersion}}", + "@angular/http": "^{{ngVersion}}", + "@angular/common": "^{{ngVersion}}", + "@angular/compiler": "^{{ngVersion}}", "core-js": "^2.4.0", "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6" }, "devDependencies": { - "@angular/core": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/http": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/common": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/compiler": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", - "@angular/platform-browser": "{{#isNg2x}}^2.2.2{{/isNg2x}}{{#isNg4x}}^4.2.5{{/isNg4x}}", + "@angular/core": "^{{ngVersion}}", + "@angular/http": "^{{ngVersion}}", + "@angular/common": "^{{ngVersion}}", + "@angular/compiler": "^{{ngVersion}}", + "@angular/platform-browser": "^{{ngVersion}}", "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6", diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache index 59e72e28ca9..b3241fcebcd 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular/variables.mustache @@ -1,6 +1,6 @@ -import { {{#isNg2x}}OpaqueToken{{/isNg2x}}{{#isNg4x}}InjectionToken{{/isNg4x}} } from '@angular/core'; +import { {{injectionToken}} } from '@angular/core'; -export const BASE_PATH = new {{#isNg2x}}OpaqueToken{{/isNg2x}}{{#isNg4x}}InjectionToken{{/isNg4x}}('basePath'); +export const BASE_PATH = new {{injectionToken}}{{#injectionTokenTyped}}{{/injectionTokenTyped}}('basePath'); export const COLLECTION_FORMATS = { 'csv': ',', 'tsv': ' ', diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java index f7b8f994231..6dd88157eb1 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/typescript/typescriptangular/TypeScriptAngularClientOptionsTest.java @@ -30,8 +30,6 @@ protected void setExpectations() { times = 1; clientCodegen.setModelPropertyNaming(TypeScriptAngularClientOptionsProvider.MODEL_PROPERTY_NAMING_VALUE); times = 1; - clientCodegen.setNgVersion(TypeScriptAngularClientOptionsProvider.NG_VERSION); - times = 1; clientCodegen.setSupportsES6(Boolean.valueOf(TypeScriptAngularClientOptionsProvider.SUPPORTS_ES6_VALUE)); times = 1; }}; From 3a16a2cf93ffc584e97821c36dd33995d7398704 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 20:36:35 +0200 Subject: [PATCH 03/12] remove dead code this method is never called ... --- .../typescript-angular/api.service.mustache | 15 --------------- 1 file changed, 15 deletions(-) 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 5da473f5ccb..8c1751640cc 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 @@ -49,21 +49,6 @@ export class {{classname}} { } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise From 8e70bf066cd2932c5a3bd99d6baeed7300ab6249 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 21:30:38 +0200 Subject: [PATCH 04/12] support HttpClient in addition to Http, clean up generated code Fixes #6080 --- .../TypeScriptAngularClientCodegen.java | 61 ++++---- .../typescript-angular/api.service.mustache | 132 ++++++++++-------- 2 files changed, 105 insertions(+), 88 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java index 73960ba59e8..2e4cbd1e8c3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngularClientCodegen.java @@ -6,6 +6,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -105,11 +106,13 @@ public void processOpts() { ngVersion = new SemVer(additionalProperties.get(NG_VERSION).toString()); } else { ngVersion = new SemVer("4.3.0"); + LOGGER.info("generating code for Angular {} ...", ngVersion); + LOGGER.info(" (you can select the angular version by setting the additionalProperty ngVersion)"); } 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("httpClientSupported", ngVersion.atLeast("4.3.0") ? "true" : null); + additionalProperties.put("useHttpClient", ngVersion.atLeast("4.3.0")); } private void addNpmPackageGeneration() { @@ -212,32 +215,36 @@ public Map postProcessOperations(Map operations) List ops = (List) objs.get("operation"); for (CodegenOperation op : ops) { - // 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"); + 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"); + } } // Convert path to TypeScript template string 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 8c1751640cc..387a255fa02 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 @@ -2,9 +2,14 @@ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; +{{#useHttpClient}} +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +{{/useHttpClient}} +{{^useHttpClient}} import { Http, Headers, URLSearchParams } from '@angular/http'; import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; import { Response, ResponseContentType } from '@angular/http'; +{{/useHttpClient}} import { Observable } from 'rxjs/Observable'; import '../rxjs-operators'; @@ -36,16 +41,16 @@ export class {{classname}} { {{/withInterfaces}} protected basePath = '{{{basePath}}}'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new {{#useHttpClient}}Http{{/useHttpClient}}Headers(); + public configuration = new Configuration(); - constructor(protected http: Http, @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; } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } @@ -63,6 +68,9 @@ export class {{classname}} { return false; } +{{^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. }} {{#operation}} /** * {{¬es}} @@ -71,12 +79,8 @@ export class {{classname}} { {{/summary}} {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ -{{^isResponseFile}} - public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { -{{/isResponseFile}} -{{#isResponseFile}} - public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable<{{#returnType}}{{{returnType}}}|undefined{{/returnType}}{{^returnType}}{}{{/returnType}}> { -{{/isResponseFile}} + {{! if you change this method signature, also change the version below }} + public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{^useHttpClient}}extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { return this.{{nickname}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -93,6 +97,7 @@ export class {{classname}} { } {{/operation}} +{{/useHttpClient}} {{#operation}} /** @@ -100,124 +105,113 @@ export class {{classname}} { * {{notes}} {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ - public {{nickname}}WithHttpInfo({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable { - const path = this.basePath + '{{{path}}}'{{#pathParams}} - .replace('${' + '{{baseName}}' + '}', String({{paramName}})){{/pathParams}}; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - + public {{nickname}}{{^useHttpClient}}WithHttpInfo{{/useHttpClient}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{^useHttpClient}}extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#useHttpClient}}{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}{{/useHttpClient}}{{^useHttpClient}}Response{{/useHttpClient}}> { {{#allParams}} {{#required}} - // verify required parameter '{{paramName}}' is not null or undefined if ({{paramName}} === null || {{paramName}} === undefined) { throw new Error('Required parameter {{paramName}} was null or undefined when calling {{nickname}}.'); } {{/required}} {{/allParams}} + +{{#hasQueryParams}} + let queryParameters = new {{#useHttpClient}}HttpParams{{/useHttpClient}}{{^useHttpClient}}URLSearchParams{{/useHttpClient}}(); {{#queryParams}} {{#isListContainer}} if ({{paramName}}) { {{#isCollectionFormatMulti}} {{paramName}}.forEach((element) => { - queryParameters.append('{{baseName}}', element); + {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.append('{{baseName}}', element); }) {{/isCollectionFormatMulti}} {{^isCollectionFormatMulti}} - queryParameters.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); {{/isCollectionFormatMulti}} } {{/isListContainer}} {{^isListContainer}} if ({{paramName}} !== undefined) { {{#isDateTime}} - queryParameters.set('{{baseName}}', {{paramName}}.toISOString()); + {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', {{paramName}}.toISOString()); {{/isDateTime}} {{^isDateTime}} - queryParameters.set('{{baseName}}', {{paramName}}); + {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{baseName}}', {{paramName}}); {{/isDateTime}} } {{/isListContainer}} {{/queryParams}} + +{{/hasQueryParams}} + let headers = {{#useHttpClient}}this.defaultHeaders;{{/useHttpClient}}{{^useHttpClient}}new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845{{/useHttpClient}} {{#headerParams}} {{#isListContainer}} if ({{paramName}}) { - headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{baseName}}', {{paramName}}.join(COLLECTION_FORMATS['{{collectionFormat}}'])); } {{/isListContainer}} {{^isListContainer}} if ({{paramName}} !== undefined && {{paramName}} !== null) { - headers.set('{{baseName}}', String({{paramName}})); + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{baseName}}', String({{paramName}})); } {{/isListContainer}} - {{/headerParams}} -{{#hasFormParams}} - // to determine the Content-Type header - let consumes: string[] = [ - {{#consumes}} - '{{{mediaType}}}'{{#hasMore}},{{/hasMore}} - {{/consumes}} - ]; - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; -{{#formParams}} -{{#isFile}} - useForm = canConsumeForm; -{{/isFile}} -{{/formParams}} - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; -{{/hasFormParams}} - - // to determine the Accept header - let produces: string[] = [ - {{#produces}} - '{{{mediaType}}}'{{#hasMore}},{{/hasMore}} - {{/produces}} - ]; {{#authMethods}} // authentication ({{name}}) required {{#isApiKey}} {{#isKeyInHeader}} if (this.configuration.apiKeys["{{keyParamName}}"]) { - headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); } {{/isKeyInHeader}} {{#isKeyInQuery}} if (this.configuration.apiKeys["{{keyParamName}}"]) { - queryParameters.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); + {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); } {{/isKeyInQuery}} {{/isApiKey}} {{#isBasic}} - // http basic authentication required if (this.configuration.username || this.configuration.password) { - headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password)); + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password)); } {{/isBasic}} {{#isOAuth}} - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('Authorization', 'Bearer ' + accessToken); } {{/isOAuth}} {{/authMethods}} - {{#bodyParam}} +{{^useHttpClient}} headers.set('Content-Type', 'application/json'); +{{/useHttpClient}} {{/bodyParam}} +{{#hasFormParams}} + // to determine the Content-Type header + let consumes: string[] = [ + {{#consumes}} + '{{{mediaType}}}'{{#hasMore}},{{/hasMore}} + {{/consumes}} + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; +{{#formParams}} +{{#isFile}} + useForm = canConsumeForm; +{{/isFile}} +{{/formParams}} + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; {{#formParams}} {{#isListContainer}} if ({{paramName}}) { @@ -236,8 +230,22 @@ export class {{classname}} { formParams.set('{{baseName}}', {{paramName}}); } {{/isListContainer}} - {{/formParams}} + +{{/hasFormParams}} +{{#useHttpClient}} + return this.httpClient.{{httpMethod}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}}{{#hasFormParams}}formParams, {{/hasFormParams}}{ +{{#hasQueryParams}} + params: queryParameters, +{{/hasQueryParams}} + headers: headers, +{{#isResponseFile}} + responseType: "blob", +{{/isResponseFile}} + withCredentials: this.configuration.withCredentials, + }); +{{/useHttpClient}} +{{^useHttpClient}} let requestOptions: RequestOptionsArgs = new RequestOptions({ method: {{httpMethod}}, headers: headers, @@ -250,7 +258,9 @@ export class {{classname}} { {{#isResponseFile}} responseType: ResponseContentType.Blob, {{/isResponseFile}} +{{#hasQueryParams}} search: queryParameters, +{{/hasQueryParams}} withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -258,9 +268,9 @@ export class {{classname}} { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}{{{path}}}`, requestOptions); +{{/useHttpClient}} } -{{/operation}} -} +{{/operation}}} {{/operations}} From ab166b0db5a12d827ca49ae6baf9ac1e18abc9e9 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 21:40:29 +0200 Subject: [PATCH 05/12] added new sample, and regenerated existing samples --- ...pescript-angular-v4.3-petstore-with-npm.sh | 31 + .../typescript-angular-v2/npm/package.json | 18 +- .../typescript-angular-v4.3/npm/.gitignore | 4 + .../npm/.swagger-codegen-ignore | 23 + .../npm/.swagger-codegen/VERSION | 1 + .../typescript-angular-v4.3/npm/README.md | 98 +++ .../typescript-angular-v4.3/npm/api.module.ts | 23 + .../typescript-angular-v4.3/npm/api/api.ts | 7 + .../npm/api/pet.service.ts | 638 ++++++++++++++++++ .../npm/api/store.service.ts | 292 ++++++++ .../npm/api/user.service.ts | 530 +++++++++++++++ .../npm/configuration.ts | 26 + .../typescript-angular-v4.3/npm/encoder.ts | 17 + .../typescript-angular-v4.3/npm/git_push.sh | 52 ++ .../typescript-angular-v4.3/npm/index.ts | 5 + .../npm/model/apiResponse.ts | 25 + .../npm/model/category.ts | 23 + .../npm/model/models.ts | 6 + .../npm/model/order.ts | 41 ++ .../typescript-angular-v4.3/npm/model/pet.ts | 43 ++ .../typescript-angular-v4.3/npm/model/tag.ts | 23 + .../typescript-angular-v4.3/npm/model/user.ts | 38 ++ .../typescript-angular-v4.3/npm/package.json | 40 ++ .../npm/rxjs-operators.ts | 11 + .../typescript-angular-v4.3/npm/tsconfig.json | 25 + .../typescript-angular-v4.3/npm/typings.json | 5 + .../typescript-angular-v4.3/npm/variables.ts | 9 + .../typescript-angular-v4/npm/package.json | 18 +- 28 files changed, 2054 insertions(+), 18 deletions(-) create mode 100644 bin/typescript-angular-v4.3-petstore-with-npm.sh create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/.gitignore create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen-ignore create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen/VERSION create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/README.md create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/api.module.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/api/api.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/configuration.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/git_push.sh create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/index.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/models.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/package.json create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/rxjs-operators.ts create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/tsconfig.json create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/typings.json create mode 100644 samples/client/petstore/typescript-angular-v4.3/npm/variables.ts diff --git a/bin/typescript-angular-v4.3-petstore-with-npm.sh b/bin/typescript-angular-v4.3-petstore-with-npm.sh new file mode 100644 index 00000000000..35f8447c5de --- /dev/null +++ b/bin/typescript-angular-v4.3-petstore-with-npm.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +SCRIPT="$0" + +while [ -h "$SCRIPT" ] ; do + ls=`ls -ld "$SCRIPT"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + SCRIPT="$link" + else + SCRIPT=`dirname "$SCRIPT"`/"$link" + fi +done + +if [ ! -d "${APP_DIR}" ]; then + APP_DIR=`dirname "$SCRIPT"`/.. + APP_DIR=`cd "${APP_DIR}"; pwd` +fi + +executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar" + +if [ ! -f "$executable" ] +then + mvn clean package +fi + +# if you've executed sbt assembly previously it will use that instead. +export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular-v4.3/npm --additional-properties ngVersion=4.3" + +java $JAVA_OPTS -jar $executable $ags diff --git a/samples/client/petstore/typescript-angular-v2/npm/package.json b/samples/client/petstore/typescript-angular-v2/npm/package.json index d2e8c69bf95..d6aee04c589 100644 --- a/samples/client/petstore/typescript-angular-v2/npm/package.json +++ b/samples/client/petstore/typescript-angular-v2/npm/package.json @@ -14,21 +14,21 @@ "postinstall": "npm run build" }, "peerDependencies": { - "@angular/core": "^2.2.2", - "@angular/http": "^2.2.2", - "@angular/common": "^2.2.2", - "@angular/compiler": "^2.2.2", + "@angular/core": "^2.0.0", + "@angular/http": "^2.0.0", + "@angular/common": "^2.0.0", + "@angular/compiler": "^2.0.0", "core-js": "^2.4.0", "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6" }, "devDependencies": { - "@angular/core": "^2.2.2", - "@angular/http": "^2.2.2", - "@angular/common": "^2.2.2", - "@angular/compiler": "^2.2.2", - "@angular/platform-browser": "^2.2.2", + "@angular/core": "^2.0.0", + "@angular/http": "^2.0.0", + "@angular/common": "^2.0.0", + "@angular/compiler": "^2.0.0", + "@angular/platform-browser": "^2.0.0", "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6", diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/.gitignore b/samples/client/petstore/typescript-angular-v4.3/npm/.gitignore new file mode 100644 index 00000000000..149b5765472 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen-ignore b/samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen-ignore @@ -0,0 +1,23 @@ +# Swagger Codegen Ignore +# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen/VERSION b/samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen/VERSION new file mode 100644 index 00000000000..f9f7450d135 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/.swagger-codegen/VERSION @@ -0,0 +1 @@ +2.3.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/README.md b/samples/client/petstore/typescript-angular-v4.3/npm/README.md new file mode 100644 index 00000000000..038fd51491c --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/README.md @@ -0,0 +1,98 @@ +## @swagger/angular2-typescript-petstore@0.0.1 + +### Building + +To build an compile the typescript sources to javascript use: +``` +npm install +npm run build +``` + +### publishing + +First build the package than run ```npm publish``` + +### consuming + +navigate to the folder of your consuming project and run one of next commando's. + +_published:_ + +``` +npm install @swagger/angular2-typescript-petstore@0.0.1 --save +``` + +_unPublished (not recommended):_ + +``` +npm install PATH_TO_GENERATED_PACKAGE --save +``` + +_using `npm link`:_ + +In PATH_TO_GENERATED_PACKAGE: +``` +npm link +``` + +In your project: +``` +npm link @swagger/angular2-typescript-petstore@0.0.1 +``` + +In your angular2 project: + +``` +import { DefaultApi } from '@swagger/angular2-typescript-petstore/api/api'; +@NgModule({ + imports: [], + declarations: [], + exports: [], + providers: [AppModule] +}) +export class CoreModule {} +``` +``` +import { DefaultApi } from '@swagger/angular2-typescript-petstore/api/api'; + +export class AppComponent { + constructor(private apiGateway: DefaultApi) { } +} +``` + +### Set service base path +If different than the generated base path, during app bootstrap, you can provide the base path to your service. + +``` +import { BASE_PATH } from './path-to-swagger-gen-service/index'; + +bootstrap(AppComponent, [ + { provide: BASE_PATH, useValue: 'https://your-web-service.com' }, +]); +``` + +#### Using @angular/cli +First extend your `src/environments/*.ts` files by adding the corresponding base path: + +``` +export const environment = { + production: false, + API_BASE_PATH: 'http://127.0.0.1:8080' +}; +``` + +In the src/app/app.module.ts: +``` +import { BASE_PATH } from '@swagger/angular2-typescript-petstore'; +import { environment } from '../environments/environment'; + +@NgModule({ + declarations: [ + AppComponent, + ], + imports: [ ], + providers: [{ provide: BASE_PATH, useValue: useValue: environment.API_BASE_PATH }], + bootstrap: [AppComponent] +}) +export class AppModule { } +``` \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api.module.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api.module.ts new file mode 100644 index 00000000000..dcce0dbd628 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api.module.ts @@ -0,0 +1,23 @@ +import { NgModule, ModuleWithProviders } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { HttpModule } from '@angular/http'; +import { Configuration } from './configuration'; + +import { PetService } from './api/pet.service'; +import { StoreService } from './api/store.service'; +import { UserService } from './api/user.service'; + +@NgModule({ + imports: [ CommonModule, HttpModule ], + declarations: [], + exports: [], + providers: [ PetService, StoreService, UserService ] +}) +export class ApiModule { + public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders { + return { + ngModule: ApiModule, + providers: [ {provide: Configuration, useFactory: configurationFactory}] + } + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/api.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/api.ts new file mode 100644 index 00000000000..8e44b64083d --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/api.ts @@ -0,0 +1,7 @@ +export * from './pet.service'; +import { PetService } from './pet.service'; +export * from './store.service'; +import { StoreService } from './store.service'; +export * from './user.service'; +import { UserService } from './user.service'; +export const APIS = [PetService, StoreService, UserService]; 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 new file mode 100644 index 00000000000..b05fe8fc637 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -0,0 +1,638 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * 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 { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import '../rxjs-operators'; + +import { ApiResponse } from '../model/apiResponse'; +import { Pet } from '../model/pet'; + +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; + + +@Injectable() +export class PetService { + + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; + } + } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + (objA as any)[key] = (objB as any)[key]; + } + } + return objA; + } + + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + + /** + * + * @summary Add a new pet to the store + * @param body Pet object that needs to be added to the store + */ + public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + return this.addPetWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Deletes a pet + * @param petId Pet id to delete + * @param apiKey + */ + public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { + return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Multiple status values can be provided with comma separated strings + * @summary Finds Pets by status + * @param status Status values that need to be considered for filter + */ + public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { + return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @summary Finds Pets by tags + * @param tags Tags to filter by + */ + public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { + return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Returns a single pet + * @summary Find pet by ID + * @param petId ID of pet to return + */ + public getPetById(petId: number, extraHttpRequestParams?: any): Observable { + return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Update an existing pet + * @param body Pet object that needs to be added to the store + */ + public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + return this.updatePetWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Updates a pet in the store with form data + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary uploads an image + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { + return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling addPet.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling deletePet.'); + } + if (apiKey !== undefined && apiKey !== null) { + headers.set('api_key', String(apiKey)); + } + + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma separated strings + * @param status Status values that need to be considered for filter + */ + public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/findByStatus'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'status' is not null or undefined + if (status === null || status === undefined) { + throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); + } + if (status) { + queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); + } + + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + */ + public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/findByTags'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'tags' is not null or undefined + if (tags === null || tags === undefined) { + throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); + } + if (tags) { + queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); + } + + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Find pet by ID + * Returns a single pet + * @param petId ID of pet to return + */ + public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling getPetById.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (api_key) required + if (this.configuration.apiKeys["api_key"]) { + headers.set('api_key', this.configuration.apiKeys["api_key"]); + } + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling updatePet.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + if (name !== undefined) { + formParams.set('name', name); + } + + if (status !== undefined) { + formParams.set('status', status); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}/uploadImage' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + 'multipart/form-data' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + useForm = canConsumeForm; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; + + // to determine the Accept header + let produces: string[] = [ + 'application/json' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + + if (additionalMetadata !== undefined) { + formParams.set('additionalMetadata', additionalMetadata); + } + + if (file !== undefined) { + formParams.set('file', file); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + +} 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 new file mode 100644 index 00000000000..8765ad7c4a9 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -0,0 +1,292 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * 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 { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import '../rxjs-operators'; + +import { Order } from '../model/order'; + +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; + + +@Injectable() +export class StoreService { + + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; + } + } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + (objA as any)[key] = (objB as any)[key]; + } + } + return objA; + } + + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + + /** + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @summary Delete purchase order by ID + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { + return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Returns a map of status codes to quantities + * @summary Returns pet inventories by status + */ + public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { + return this.getInventoryWithHttpInfo(extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @summary Find purchase order by ID + * @param orderId ID of pet that needs to be fetched + */ + public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { + return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Place an order for a pet + * @param body order placed for purchasing the pet + */ + public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { + return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/order/${orderId}' + .replace('${' + 'orderId' + '}', String(orderId)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/inventory'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + + // to determine the Accept header + let produces: string[] = [ + 'application/json' + ]; + + // authentication (api_key) required + if (this.configuration.apiKeys["api_key"]) { + headers.set('api_key', this.configuration.apiKeys["api_key"]); + } + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + */ + public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/order/${orderId}' + .replace('${' + 'orderId' + '}', String(orderId)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/order'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling placeOrder.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + +} 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 new file mode 100644 index 00000000000..4322a11f7ef --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -0,0 +1,530 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * 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 { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import '../rxjs-operators'; + +import { User } from '../model/user'; + +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { CustomQueryEncoderHelper } from '../encoder'; + + +@Injectable() +export class UserService { + + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + this.basePath = basePath || configuration.basePath || this.basePath; + } + } + + /** + * + * Extends object by coping non-existing properties. + * @param objA object to be extended + * @param objB source object + */ + private extendObj(objA: T1, objB: T2) { + for(let key in objB){ + if(objB.hasOwnProperty(key)){ + (objA as any)[key] = (objB as any)[key]; + } + } + return objA; + } + + /** + * @param consumes string[] mime-types + * @return true: consumes contains 'multipart/form-data', false: otherwise + */ + private canConsumeForm(consumes: string[]): boolean { + const form = 'multipart/form-data'; + for (let consume of consumes) { + if (form === consume) { + return true; + } + } + return false; + } + + /** + * This can only be done by the logged in user. + * @summary Create user + * @param body Created user object + */ + public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { + return this.createUserWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Creates list of users with given input array + * @param body List of user object + */ + public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Creates list of users with given input array + * @param body List of user object + */ + public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * This can only be done by the logged in user. + * @summary Delete user + * @param username The name that needs to be deleted + */ + public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { + return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Get user by user name + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByName(username: string, extraHttpRequestParams?: any): Observable { + return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Logs user into the system + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { + return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * + * @summary Logs out current logged in user session + */ + public logoutUser(extraHttpRequestParams?: any): Observable<{}> { + return this.logoutUserWithHttpInfo(extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * This can only be done by the logged in user. + * @summary Updated user + * @param username name that need to be deleted + * @param body Updated user object + */ + public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { + return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUser.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/createWithArray'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/createWithList'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/${username}' + .replace('${' + 'username' + '}', String(username)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling deleteUser.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/${username}' + .replace('${' + 'username' + '}', String(username)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling getUserByName.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/login'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling loginUser.'); + } + // verify required parameter 'password' is not null or undefined + if (password === null || password === undefined) { + throw new Error('Required parameter password was null or undefined when calling loginUser.'); + } + if (username !== undefined) { + queryParameters.set('username', username); + } + + if (password !== undefined) { + queryParameters.set('password', password); + } + + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Logs out current logged in user session + * + */ + public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/logout'; + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + */ + public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/${username}' + .replace('${' + 'username' + '}', String(username)); + + let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling updateUser.'); + } + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling updateUser.'); + } + + // to determine the Accept header + let produces: string[] = [ + 'application/xml', + 'application/json' + ]; + + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/configuration.ts b/samples/client/petstore/typescript-angular-v4.3/npm/configuration.ts new file mode 100644 index 00000000000..005c3a26df3 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/configuration.ts @@ -0,0 +1,26 @@ +export interface ConfigurationParameters { + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | (() => string); + basePath?: string; + withCredentials?: boolean; +} + +export class Configuration { + apiKeys?: {[ key: string ]: string}; + username?: string; + password?: string; + accessToken?: string | (() => string); + basePath?: string; + withCredentials?: boolean; + + constructor(configurationParameters: ConfigurationParameters = {}) { + this.apiKeys = configurationParameters.apiKeys; + this.username = configurationParameters.username; + this.password = configurationParameters.password; + this.accessToken = configurationParameters.accessToken; + this.basePath = configurationParameters.basePath; + this.withCredentials = configurationParameters.withCredentials; + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts b/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts new file mode 100644 index 00000000000..319f79da15a --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/encoder.ts @@ -0,0 +1,17 @@ +import { QueryEncoder } from "@angular/http"; + +/** +* CustomQueryEncoderHelper +* 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'); + } +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/git_push.sh b/samples/client/petstore/typescript-angular-v4.3/npm/git_push.sh new file mode 100644 index 00000000000..ed374619b13 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/git_push.sh @@ -0,0 +1,52 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 swagger-petstore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git crediential in your environment." + git remote add origin https://github.com/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@github.com/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://github.com/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/index.ts b/samples/client/petstore/typescript-angular-v4.3/npm/index.ts new file mode 100644 index 00000000000..c312b70fa3e --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/index.ts @@ -0,0 +1,5 @@ +export * from './api/api'; +export * from './model/models'; +export * from './variables'; +export * from './configuration'; +export * from './api.module'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts new file mode 100644 index 00000000000..3af781cf580 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/apiResponse.ts @@ -0,0 +1,25 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +/** + * Describes the result of uploading an image resource + */ +export interface ApiResponse { + code?: number; + + type?: string; + + message?: string; + +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts new file mode 100644 index 00000000000..d09f8d7b265 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/category.ts @@ -0,0 +1,23 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +/** + * A category for a pet + */ +export interface Category { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/models.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/models.ts new file mode 100644 index 00000000000..8607c5dabd0 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/models.ts @@ -0,0 +1,6 @@ +export * from './apiResponse'; +export * from './category'; +export * from './order'; +export * from './pet'; +export * from './tag'; +export * from './user'; diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts new file mode 100644 index 00000000000..402a86689c8 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/order.ts @@ -0,0 +1,41 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +/** + * An order for a pets from the pet store + */ +export interface Order { + id?: number; + + petId?: number; + + quantity?: number; + + shipDate?: Date; + + /** + * Order Status + */ + status?: Order.StatusEnum; + + complete?: boolean; + +} +export namespace Order { + export enum StatusEnum { + Placed = 'placed', + Approved = 'approved', + Delivered = 'delivered' + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts new file mode 100644 index 00000000000..0d6137d02cf --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/pet.ts @@ -0,0 +1,43 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + +import { Category } from './category'; +import { Tag } from './tag'; + + +/** + * A pet for sale in the pet store + */ +export interface Pet { + id?: number; + + category?: Category; + + name: string; + + photoUrls: Array; + + tags?: Array; + + /** + * pet status in the store + */ + status?: Pet.StatusEnum; + +} +export namespace Pet { + export enum StatusEnum { + Available = 'available', + Pending = 'pending', + Sold = 'sold' + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts new file mode 100644 index 00000000000..3ed1eeff8f3 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/tag.ts @@ -0,0 +1,23 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +/** + * A tag for a pet + */ +export interface Tag { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts b/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts new file mode 100644 index 00000000000..f4914ae2608 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/model/user.ts @@ -0,0 +1,38 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git + * Do not edit the class manually. + */ + + + +/** + * A User who is purchasing from the pet store + */ +export interface User { + id?: number; + + username?: string; + + firstName?: string; + + lastName?: string; + + email?: string; + + password?: string; + + phone?: string; + + /** + * User Status + */ + userStatus?: number; + +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/package.json b/samples/client/petstore/typescript-angular-v4.3/npm/package.json new file mode 100644 index 00000000000..40157c62927 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/package.json @@ -0,0 +1,40 @@ +{ + "name": "@swagger/angular2-typescript-petstore", + "version": "0.0.1", + "description": "swagger client for @swagger/angular2-typescript-petstore", + "author": "Swagger Codegen Contributors", + "keywords": [ + "swagger-client" + ], + "license": "Unlicense", + "main": "dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc --outDir dist/", + "postinstall": "npm run build" + }, + "peerDependencies": { + "@angular/core": "^4.3.0", + "@angular/http": "^4.3.0", + "@angular/common": "^4.3.0", + "@angular/compiler": "^4.3.0", + "core-js": "^2.4.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6" + }, + "devDependencies": { + "@angular/core": "^4.3.0", + "@angular/http": "^4.3.0", + "@angular/common": "^4.3.0", + "@angular/compiler": "^4.3.0", + "@angular/platform-browser": "^4.3.0", + "reflect-metadata": "^0.1.3", + "rxjs": "^5.4.0", + "zone.js": "^0.7.6", + "typescript": "^2.1.5" + }, + "publishConfig": { + "registry":"https://skimdb.npmjs.com/registry" + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/rxjs-operators.ts b/samples/client/petstore/typescript-angular-v4.3/npm/rxjs-operators.ts new file mode 100644 index 00000000000..5659cd0694f --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/rxjs-operators.ts @@ -0,0 +1,11 @@ +// 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'; diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/tsconfig.json b/samples/client/petstore/typescript-angular-v4.3/npm/tsconfig.json new file mode 100644 index 00000000000..a6e9096bbf7 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/tsconfig.json @@ -0,0 +1,25 @@ +{ + "compilerOptions": { + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "noImplicitAny": false, + "suppressImplicitAnyIndexErrors": true, + "target": "es5", + "module": "es6", + "moduleResolution": "node", + "removeComments": true, + "sourceMap": true, + "outDir": "./dist", + "noLib": false, + "declaration": true, + "lib": [ "es6", "dom" ] + }, + "exclude": [ + "node_modules", + "dist" + ], + "filesGlob": [ + "./model/*.ts", + "./api/*.ts" + ] +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/typings.json b/samples/client/petstore/typescript-angular-v4.3/npm/typings.json new file mode 100644 index 00000000000..507c40e5cbe --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/typings.json @@ -0,0 +1,5 @@ +{ + "globalDependencies": { + "core-js": "registry:dt/core-js#0.0.0+20160725163759" + } +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts new file mode 100644 index 00000000000..6fe58549f39 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/variables.ts @@ -0,0 +1,9 @@ +import { InjectionToken } from '@angular/core'; + +export const BASE_PATH = new InjectionToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} diff --git a/samples/client/petstore/typescript-angular-v4/npm/package.json b/samples/client/petstore/typescript-angular-v4/npm/package.json index a15c011fe29..af9c5d898e6 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/package.json +++ b/samples/client/petstore/typescript-angular-v4/npm/package.json @@ -14,21 +14,21 @@ "postinstall": "npm run build" }, "peerDependencies": { - "@angular/core": "^4.2.5", - "@angular/http": "^4.2.5", - "@angular/common": "^4.2.5", - "@angular/compiler": "^4.2.5", + "@angular/core": "^4.0.0", + "@angular/http": "^4.0.0", + "@angular/common": "^4.0.0", + "@angular/compiler": "^4.0.0", "core-js": "^2.4.0", "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6" }, "devDependencies": { - "@angular/core": "^4.2.5", - "@angular/http": "^4.2.5", - "@angular/common": "^4.2.5", - "@angular/compiler": "^4.2.5", - "@angular/platform-browser": "^4.2.5", + "@angular/core": "^4.0.0", + "@angular/http": "^4.0.0", + "@angular/common": "^4.0.0", + "@angular/compiler": "^4.0.0", + "@angular/platform-browser": "^4.0.0", "reflect-metadata": "^0.1.3", "rxjs": "^5.4.0", "zone.js": "^0.7.6", From c57ff8f828ce5b7d0607c7c23fc25004e13a4e8e Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 22:34:49 +0200 Subject: [PATCH 06/12] updated samples this time with the freshly build generator ... --- .../default/api/pet.service.ts | 234 +++------ .../default/api/store.service.ts | 99 +--- .../default/api/user.service.ts | 184 ++----- .../npm/api/pet.service.ts | 234 +++------ .../npm/api/store.service.ts | 99 +--- .../npm/api/user.service.ts | 184 ++----- .../with-interfaces/api/pet.service.ts | 234 +++------ .../with-interfaces/api/store.service.ts | 99 +--- .../with-interfaces/api/user.service.ts | 184 ++----- .../npm/api/pet.service.ts | 463 +++--------------- .../npm/api/store.service.ts | 203 +------- .../npm/api/user.service.ts | 395 ++------------- .../npm/api/pet.service.ts | 234 +++------ .../npm/api/store.service.ts | 99 +--- .../npm/api/user.service.ts | 184 ++----- 15 files changed, 585 insertions(+), 2544 deletions(-) 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 b05fe8fc637..ecd750ff906 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 @@ -32,8 +32,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class PetService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -41,25 +41,10 @@ export class PetService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -79,7 +64,7 @@ export class PetService { * @summary Add a new pet to the store * @param body Pet object that needs to be added to the store */ - public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public addPet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.addPetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -96,7 +81,7 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { + public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -112,7 +97,7 @@ export class PetService { * @summary Finds Pets by status * @param status Status values that need to be considered for filter */ - public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByStatus(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -128,7 +113,7 @@ export class PetService { * @summary Finds Pets by tags * @param tags Tags to filter by */ - public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByTags(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -144,7 +129,7 @@ export class PetService { * @summary Find pet by ID * @param petId ID of pet to return */ - public getPetById(petId: number, extraHttpRequestParams?: any): Observable { + public getPetById(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -160,7 +145,7 @@ export class PetService { * @summary Update an existing pet * @param body Pet object that needs to be added to the store */ - public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public updatePet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -178,7 +163,7 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -196,7 +181,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -213,25 +198,14 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addPet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -239,14 +213,12 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -254,7 +226,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -263,30 +235,17 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 if (apiKey !== undefined && apiKey !== null) { headers.set('api_key', String(apiKey)); } - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -294,11 +253,9 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -306,7 +263,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -314,29 +271,20 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByStatus'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'status' is not null or undefined + public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (status === null || status === undefined) { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } + + let queryParameters = new URLSearchParams(); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -344,7 +292,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -356,7 +303,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -364,29 +311,20 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByTags'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'tags' is not null or undefined + public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (tags === null || tags === undefined) { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } + + let queryParameters = new URLSearchParams(); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -394,7 +332,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -406,7 +343,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -414,34 +351,21 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -449,7 +373,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -457,25 +381,14 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -483,14 +396,12 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -498,7 +409,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -508,35 +419,14 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -544,11 +434,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; if (name !== undefined) { formParams.set('name', name); } - if (status !== undefined) { formParams.set('status', status); } @@ -557,7 +454,6 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -565,7 +461,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -575,17 +471,21 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + // authentication (petstore_auth) required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); } + // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -596,26 +496,9 @@ export class PetService { let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -624,7 +507,6 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -632,7 +514,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); } } 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 8765ad7c4a9..05ee087ba4e 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 @@ -31,8 +31,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class StoreService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -40,25 +40,10 @@ export class StoreService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -78,7 +63,7 @@ export class StoreService { * @summary Delete purchase order by ID * @param orderId ID of the order that needs to be deleted */ - public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteOrder(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -93,7 +78,7 @@ export class StoreService { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { + public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -109,7 +94,7 @@ export class StoreService { * @summary Find purchase order by ID * @param orderId ID of pet that needs to be fetched */ - public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { + public getOrderById(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -125,7 +110,7 @@ export class StoreService { * @summary Place an order for a pet * @param body order placed for purchasing the pet */ - public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { + public placeOrder(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -142,29 +127,16 @@ export class StoreService { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -172,35 +144,25 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/inventory'; + public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -208,7 +170,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -216,29 +178,16 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -246,7 +195,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** @@ -254,31 +203,19 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -286,7 +223,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order`, requestOptions); } } 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 4322a11f7ef..9869c67fdf1 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 @@ -31,8 +31,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class UserService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -40,25 +40,10 @@ export class UserService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -78,7 +63,7 @@ export class UserService { * @summary Create user * @param body Created user object */ - public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { + public createUser(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUserWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -94,7 +79,7 @@ export class UserService { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -110,7 +95,7 @@ export class UserService { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithListInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -126,7 +111,7 @@ export class UserService { * @summary Delete user * @param username The name that needs to be deleted */ - public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteUser(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -142,7 +127,7 @@ export class UserService { * @summary Get user by user name * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName(username: string, extraHttpRequestParams?: any): Observable { + public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -159,7 +144,7 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { + public loginUser(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -174,7 +159,7 @@ export class UserService { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: any): Observable<{}> { + public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -191,7 +176,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { + public updateUser(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -208,31 +193,19 @@ export class UserService { * This can only be done by the logged in user. * @param body Created user object */ - public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUserWithHttpInfo(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -240,7 +213,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -248,31 +221,19 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithArray'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -280,7 +241,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -288,31 +249,19 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithList'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -320,7 +269,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -328,29 +277,16 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -358,7 +294,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -366,29 +302,16 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -396,7 +319,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -405,20 +328,15 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/login'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling loginUser.'); } - // verify required parameter 'password' is not null or undefined if (password === null || password === undefined) { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } + + let queryParameters = new URLSearchParams(); if (username !== undefined) { queryParameters.set('username', username); } @@ -428,13 +346,8 @@ export class UserService { } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -446,31 +359,20 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/login`, requestOptions); } /** * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/logout'; + public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -478,7 +380,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -487,36 +389,22 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -524,7 +412,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } } 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 b05fe8fc637..ecd750ff906 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 @@ -32,8 +32,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class PetService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -41,25 +41,10 @@ export class PetService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -79,7 +64,7 @@ export class PetService { * @summary Add a new pet to the store * @param body Pet object that needs to be added to the store */ - public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public addPet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.addPetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -96,7 +81,7 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { + public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -112,7 +97,7 @@ export class PetService { * @summary Finds Pets by status * @param status Status values that need to be considered for filter */ - public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByStatus(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -128,7 +113,7 @@ export class PetService { * @summary Finds Pets by tags * @param tags Tags to filter by */ - public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByTags(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -144,7 +129,7 @@ export class PetService { * @summary Find pet by ID * @param petId ID of pet to return */ - public getPetById(petId: number, extraHttpRequestParams?: any): Observable { + public getPetById(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -160,7 +145,7 @@ export class PetService { * @summary Update an existing pet * @param body Pet object that needs to be added to the store */ - public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public updatePet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -178,7 +163,7 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -196,7 +181,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -213,25 +198,14 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addPet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -239,14 +213,12 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -254,7 +226,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -263,30 +235,17 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 if (apiKey !== undefined && apiKey !== null) { headers.set('api_key', String(apiKey)); } - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -294,11 +253,9 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -306,7 +263,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -314,29 +271,20 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByStatus'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'status' is not null or undefined + public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (status === null || status === undefined) { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } + + let queryParameters = new URLSearchParams(); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -344,7 +292,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -356,7 +303,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -364,29 +311,20 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByTags'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'tags' is not null or undefined + public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (tags === null || tags === undefined) { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } + + let queryParameters = new URLSearchParams(); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -394,7 +332,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -406,7 +343,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -414,34 +351,21 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -449,7 +373,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -457,25 +381,14 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -483,14 +396,12 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -498,7 +409,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -508,35 +419,14 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -544,11 +434,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; if (name !== undefined) { formParams.set('name', name); } - if (status !== undefined) { formParams.set('status', status); } @@ -557,7 +454,6 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -565,7 +461,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -575,17 +471,21 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + // authentication (petstore_auth) required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); } + // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -596,26 +496,9 @@ export class PetService { let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -624,7 +507,6 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -632,7 +514,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); } } 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 8765ad7c4a9..05ee087ba4e 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 @@ -31,8 +31,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class StoreService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -40,25 +40,10 @@ export class StoreService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -78,7 +63,7 @@ export class StoreService { * @summary Delete purchase order by ID * @param orderId ID of the order that needs to be deleted */ - public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteOrder(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -93,7 +78,7 @@ export class StoreService { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { + public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -109,7 +94,7 @@ export class StoreService { * @summary Find purchase order by ID * @param orderId ID of pet that needs to be fetched */ - public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { + public getOrderById(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -125,7 +110,7 @@ export class StoreService { * @summary Place an order for a pet * @param body order placed for purchasing the pet */ - public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { + public placeOrder(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -142,29 +127,16 @@ export class StoreService { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -172,35 +144,25 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/inventory'; + public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -208,7 +170,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -216,29 +178,16 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -246,7 +195,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** @@ -254,31 +203,19 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -286,7 +223,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order`, requestOptions); } } 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 4322a11f7ef..9869c67fdf1 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 @@ -31,8 +31,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class UserService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -40,25 +40,10 @@ export class UserService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -78,7 +63,7 @@ export class UserService { * @summary Create user * @param body Created user object */ - public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { + public createUser(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUserWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -94,7 +79,7 @@ export class UserService { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -110,7 +95,7 @@ export class UserService { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithListInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -126,7 +111,7 @@ export class UserService { * @summary Delete user * @param username The name that needs to be deleted */ - public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteUser(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -142,7 +127,7 @@ export class UserService { * @summary Get user by user name * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName(username: string, extraHttpRequestParams?: any): Observable { + public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -159,7 +144,7 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { + public loginUser(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -174,7 +159,7 @@ export class UserService { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: any): Observable<{}> { + public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -191,7 +176,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { + public updateUser(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -208,31 +193,19 @@ export class UserService { * This can only be done by the logged in user. * @param body Created user object */ - public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUserWithHttpInfo(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -240,7 +213,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -248,31 +221,19 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithArray'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -280,7 +241,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -288,31 +249,19 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithList'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -320,7 +269,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -328,29 +277,16 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -358,7 +294,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -366,29 +302,16 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -396,7 +319,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -405,20 +328,15 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/login'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling loginUser.'); } - // verify required parameter 'password' is not null or undefined if (password === null || password === undefined) { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } + + let queryParameters = new URLSearchParams(); if (username !== undefined) { queryParameters.set('username', username); } @@ -428,13 +346,8 @@ export class UserService { } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -446,31 +359,20 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/login`, requestOptions); } /** * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/logout'; + public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -478,7 +380,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -487,36 +389,22 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -524,7 +412,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } } 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 cfba1741216..461c98f431f 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 @@ -33,8 +33,8 @@ import { PetServiceInterface } from './PetServiceInte export class PetService implements PetServiceInterface { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -42,25 +42,10 @@ export class PetService implements PetServiceInterface { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -80,7 +65,7 @@ export class PetService implements PetServiceInterface { * @summary Add a new pet to the store * @param body Pet object that needs to be added to the store */ - public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public addPet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.addPetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -97,7 +82,7 @@ export class PetService implements PetServiceInterface { * @param petId Pet id to delete * @param apiKey */ - public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { + public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -113,7 +98,7 @@ export class PetService implements PetServiceInterface { * @summary Finds Pets by status * @param status Status values that need to be considered for filter */ - public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByStatus(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -129,7 +114,7 @@ export class PetService implements PetServiceInterface { * @summary Finds Pets by tags * @param tags Tags to filter by */ - public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByTags(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -145,7 +130,7 @@ export class PetService implements PetServiceInterface { * @summary Find pet by ID * @param petId ID of pet to return */ - public getPetById(petId: number, extraHttpRequestParams?: any): Observable { + public getPetById(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -161,7 +146,7 @@ export class PetService implements PetServiceInterface { * @summary Update an existing pet * @param body Pet object that needs to be added to the store */ - public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public updatePet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -179,7 +164,7 @@ export class PetService implements PetServiceInterface { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -197,7 +182,7 @@ export class PetService implements PetServiceInterface { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -214,25 +199,14 @@ export class PetService implements PetServiceInterface { * * @param body Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addPet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -240,14 +214,12 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -255,7 +227,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -264,30 +236,17 @@ export class PetService implements PetServiceInterface { * @param petId Pet id to delete * @param apiKey */ - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 if (apiKey !== undefined && apiKey !== null) { headers.set('api_key', String(apiKey)); } - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -295,11 +254,9 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -307,7 +264,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -315,29 +272,20 @@ export class PetService implements PetServiceInterface { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByStatus'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'status' is not null or undefined + public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (status === null || status === undefined) { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } + + let queryParameters = new URLSearchParams(); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -345,7 +293,6 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -357,7 +304,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -365,29 +312,20 @@ export class PetService implements PetServiceInterface { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByTags'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'tags' is not null or undefined + public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (tags === null || tags === undefined) { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } + + let queryParameters = new URLSearchParams(); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -395,7 +333,6 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -407,7 +344,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -415,34 +352,21 @@ export class PetService implements PetServiceInterface { * Returns a single pet * @param petId ID of pet to return */ - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -450,7 +374,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -458,25 +382,14 @@ export class PetService implements PetServiceInterface { * * @param body Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -484,14 +397,12 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -499,7 +410,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -509,35 +420,14 @@ export class PetService implements PetServiceInterface { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -545,11 +435,18 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; if (name !== undefined) { formParams.set('name', name); } - if (status !== undefined) { formParams.set('status', status); } @@ -558,7 +455,6 @@ export class PetService implements PetServiceInterface { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -566,7 +462,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -576,17 +472,21 @@ export class PetService implements PetServiceInterface { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + // authentication (petstore_auth) required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); } + // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -597,26 +497,9 @@ export class PetService implements PetServiceInterface { let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -625,7 +508,6 @@ export class PetService implements PetServiceInterface { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -633,7 +515,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); } } 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 6a3d0fc745c..e205de0ca3a 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 @@ -32,8 +32,8 @@ import { StoreServiceInterface } from './StoreService export class StoreService implements StoreServiceInterface { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -41,25 +41,10 @@ export class StoreService implements StoreServiceInterface { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -79,7 +64,7 @@ export class StoreService implements StoreServiceInterface { * @summary Delete purchase order by ID * @param orderId ID of the order that needs to be deleted */ - public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteOrder(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -94,7 +79,7 @@ export class StoreService implements StoreServiceInterface { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { + public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -110,7 +95,7 @@ export class StoreService implements StoreServiceInterface { * @summary Find purchase order by ID * @param orderId ID of pet that needs to be fetched */ - public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { + public getOrderById(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -126,7 +111,7 @@ export class StoreService implements StoreServiceInterface { * @summary Place an order for a pet * @param body order placed for purchasing the pet */ - public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { + public placeOrder(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -143,29 +128,16 @@ export class StoreService implements StoreServiceInterface { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -173,35 +145,25 @@ export class StoreService implements StoreServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/inventory'; + public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -209,7 +171,7 @@ export class StoreService implements StoreServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -217,29 +179,16 @@ export class StoreService implements StoreServiceInterface { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -247,7 +196,7 @@ export class StoreService implements StoreServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** @@ -255,31 +204,19 @@ export class StoreService implements StoreServiceInterface { * * @param body order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -287,7 +224,7 @@ export class StoreService implements StoreServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order`, requestOptions); } } 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 593c8d71a92..2ada4f5dec8 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 @@ -32,8 +32,8 @@ import { UserServiceInterface } from './UserServiceIn export class UserService implements UserServiceInterface { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -41,25 +41,10 @@ export class UserService implements UserServiceInterface { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -79,7 +64,7 @@ export class UserService implements UserServiceInterface { * @summary Create user * @param body Created user object */ - public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { + public createUser(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUserWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -95,7 +80,7 @@ export class UserService implements UserServiceInterface { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -111,7 +96,7 @@ export class UserService implements UserServiceInterface { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithListInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -127,7 +112,7 @@ export class UserService implements UserServiceInterface { * @summary Delete user * @param username The name that needs to be deleted */ - public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteUser(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -143,7 +128,7 @@ export class UserService implements UserServiceInterface { * @summary Get user by user name * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName(username: string, extraHttpRequestParams?: any): Observable { + public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -160,7 +145,7 @@ export class UserService implements UserServiceInterface { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { + public loginUser(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -175,7 +160,7 @@ export class UserService implements UserServiceInterface { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: any): Observable<{}> { + public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -192,7 +177,7 @@ export class UserService implements UserServiceInterface { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { + public updateUser(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -209,31 +194,19 @@ export class UserService implements UserServiceInterface { * This can only be done by the logged in user. * @param body Created user object */ - public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUserWithHttpInfo(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -241,7 +214,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -249,31 +222,19 @@ export class UserService implements UserServiceInterface { * * @param body List of user object */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithArray'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -281,7 +242,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -289,31 +250,19 @@ export class UserService implements UserServiceInterface { * * @param body List of user object */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithList'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -321,7 +270,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -329,29 +278,16 @@ export class UserService implements UserServiceInterface { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -359,7 +295,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -367,29 +303,16 @@ export class UserService implements UserServiceInterface { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -397,7 +320,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -406,20 +329,15 @@ export class UserService implements UserServiceInterface { * @param username The user name for login * @param password The password for login in clear text */ - public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/login'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling loginUser.'); } - // verify required parameter 'password' is not null or undefined if (password === null || password === undefined) { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } + + let queryParameters = new URLSearchParams(); if (username !== undefined) { queryParameters.set('username', username); } @@ -429,13 +347,8 @@ export class UserService implements UserServiceInterface { } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -447,31 +360,20 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/login`, requestOptions); } /** * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/logout'; + public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -479,7 +381,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -488,36 +390,22 @@ export class UserService implements UserServiceInterface { * @param username name that need to be deleted * @param body Updated user object */ - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -525,7 +413,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } } 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 b05fe8fc637..c4d9c129200 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 @@ -13,9 +13,7 @@ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { Http, Headers, URLSearchParams } from '@angular/http'; -import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; -import { Response, ResponseContentType } from '@angular/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import '../rxjs-operators'; @@ -32,34 +30,19 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class PetService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); - constructor(protected http: Http, @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; } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -74,187 +57,31 @@ export class PetService { return false; } - /** - * - * @summary Add a new pet to the store - * @param body Pet object that needs to be added to the store - */ - public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { - return this.addPetWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Deletes a pet - * @param petId Pet id to delete - * @param apiKey - */ - public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { - return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Multiple status values can be provided with comma separated strings - * @summary Finds Pets by status - * @param status Status values that need to be considered for filter - */ - public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { - return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. - * @summary Finds Pets by tags - * @param tags Tags to filter by - */ - public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { - return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Returns a single pet - * @summary Find pet by ID - * @param petId ID of pet to return - */ - public getPetById(petId: number, extraHttpRequestParams?: any): Observable { - return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Update an existing pet - * @param body Pet object that needs to be added to the store - */ - public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { - return this.updatePetWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Updates a pet in the store with form data - * @param petId ID of pet that needs to be updated - * @param name Updated name of the pet - * @param status Updated status of the pet - */ - public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { - return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary uploads an image - * @param petId ID of pet to update - * @param additionalMetadata Additional data to pass to server - * @param file file to upload - */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - /** * Add a new pet to the store * * @param body Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public addPet(body: Pet, ): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addPet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + headers = headers.set('Authorization', 'Bearer ' + accessToken); } - - headers.set('Content-Type', 'application/json'); - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/pet`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -263,50 +90,28 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public deletePet(petId: number, apiKey?: string, ): Observable<{}> { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + + let headers = this.defaultHeaders; if (apiKey !== undefined && apiKey !== null) { - headers.set('api_key', String(apiKey)); + headers = headers.set('api_key', String(apiKey)); } - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + headers = headers.set('Authorization', 'Bearer ' + accessToken); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, + return this.httpClient.delete(`${this.basePath}/pet/${petId}`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -314,49 +119,32 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByStatus'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'status' is not null or undefined + public findPetsByStatus(status: Array, ): Observable> { if (status === null || status === undefined) { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } + + let queryParameters = new HttpParams(); if (status) { - queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); + queryParameters = queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + headers = headers.set('Authorization', 'Bearer ' + accessToken); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/pet/findByStatus`, { + params: queryParameters, headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -364,49 +152,32 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByTags'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'tags' is not null or undefined + public findPetsByTags(tags: Array, ): Observable> { if (tags === null || tags === undefined) { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } + + let queryParameters = new HttpParams(); if (tags) { - queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); + queryParameters = queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + headers = headers.set('Authorization', 'Bearer ' + accessToken); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/pet/findByTags`, { + params: queryParameters, headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -414,42 +185,22 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public getPetById(petId: number, ): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/pet/${petId}`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -457,48 +208,25 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public updatePet(body: Pet, ): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + headers = headers.set('Authorization', 'Bearer ' + accessToken); } - - headers.set('Content-Type', 'application/json'); - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, + return this.httpClient.put(`${this.basePath}/pet`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -508,64 +236,41 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public updatePetWithForm(petId: number, name?: string, status?: string, ): Observable<{}> { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); + headers = headers.set('Authorization', 'Bearer ' + accessToken); } - + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; if (name !== undefined) { formParams.set('name', name); } - if (status !== undefined) { formParams.set('status', status); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/pet/${petId}`, formParams, { headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -575,17 +280,21 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, ): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } + + let headers = this.defaultHeaders; + + // authentication (petstore_auth) required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers = headers.set('Authorization', 'Bearer ' + accessToken); + } + // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -596,43 +305,17 @@ export class PetService { let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/pet/${petId}/uploadImage`, formParams, { headers: headers, - body: formParams.toString(), - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } } 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 8765ad7c4a9..795e2bfbc6b 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 @@ -13,9 +13,7 @@ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { Http, Headers, URLSearchParams } from '@angular/http'; -import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; -import { Response, ResponseContentType } from '@angular/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import '../rxjs-operators'; @@ -31,34 +29,19 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class StoreService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); - constructor(protected http: Http, @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; } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -73,142 +56,42 @@ export class StoreService { return false; } - /** - * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - * @summary Delete purchase order by ID - * @param orderId ID of the order that needs to be deleted - */ - public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { - return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * Returns a map of status codes to quantities - * @summary Returns pet inventories by status - */ - public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { - return this.getInventoryWithHttpInfo(extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions - * @summary Find purchase order by ID - * @param orderId ID of pet that needs to be fetched - */ - public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { - return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Place an order for a pet - * @param body order placed for purchasing the pet - */ - public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { - return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - /** * Delete purchase order by ID * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public deleteOrder(orderId: string, ): Observable<{}> { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, + return this.httpClient.delete(`${this.basePath}/store/order/${orderId}`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/inventory'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - + public getInventory(): Observable<{ [key: string]: number; }> { - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; + let headers = this.defaultHeaders; // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { - headers.set('api_key', this.configuration.apiKeys["api_key"]); + headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/store/inventory`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -216,37 +99,17 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public getOrderById(orderId: number, ): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/store/order/${orderId}`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -254,39 +117,17 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public placeOrder(body: Order, ): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - - headers.set('Content-Type', 'application/json'); + let headers = this.defaultHeaders; - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/store/order`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } } 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 4322a11f7ef..a464c578477 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 @@ -13,9 +13,7 @@ /* tslint:disable:no-unused-variable member-ordering */ import { Inject, Injectable, Optional } from '@angular/core'; -import { Http, Headers, URLSearchParams } from '@angular/http'; -import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; -import { Response, ResponseContentType } from '@angular/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs/Observable'; import '../rxjs-operators'; @@ -31,34 +29,19 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class UserService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new HttpHeaders(); + public configuration = new Configuration(); - constructor(protected http: Http, @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; } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -73,174 +56,23 @@ export class UserService { return false; } - /** - * This can only be done by the logged in user. - * @summary Create user - * @param body Created user object - */ - public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { - return this.createUserWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Creates list of users with given input array - * @param body List of user object - */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { - return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Creates list of users with given input array - * @param body List of user object - */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { - return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * This can only be done by the logged in user. - * @summary Delete user - * @param username The name that needs to be deleted - */ - public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { - return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Get user by user name - * @param username The name that needs to be fetched. Use user1 for testing. - */ - public getUserByName(username: string, extraHttpRequestParams?: any): Observable { - return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Logs user into the system - * @param username The user name for login - * @param password The password for login in clear text - */ - public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { - return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * - * @summary Logs out current logged in user session - */ - public logoutUser(extraHttpRequestParams?: any): Observable<{}> { - return this.logoutUserWithHttpInfo(extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - - /** - * This can only be done by the logged in user. - * @summary Updated user - * @param username name that need to be deleted - * @param body Updated user object - */ - public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { - return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) - .map((response: Response) => { - if (response.status === 204) { - return undefined; - } else { - return response.json() || {}; - } - }); - } - /** * Create user * This can only be done by the logged in user. * @param body Created user object */ - public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUser(body: User, ): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - - headers.set('Content-Type', 'application/json'); + let headers = this.defaultHeaders; - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/user`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -248,39 +80,17 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithArray'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithArrayInput(body: Array, ): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - - headers.set('Content-Type', 'application/json'); + let headers = this.defaultHeaders; - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/user/createWithArray`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -288,39 +98,17 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithList'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithListInput(body: Array, ): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; - - headers.set('Content-Type', 'application/json'); - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Post, + return this.httpClient.post(`${this.basePath}/user/createWithList`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -328,37 +116,17 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public deleteUser(username: string, ): Observable<{}> { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Delete, + return this.httpClient.delete(`${this.basePath}/user/${username}`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -366,37 +134,17 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public getUserByName(username: string, ): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/user/${username}`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -405,80 +153,45 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/login'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public loginUser(username: string, password: string, ): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling loginUser.'); } - // verify required parameter 'password' is not null or undefined if (password === null || password === undefined) { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } + + let queryParameters = new HttpParams(); if (username !== undefined) { - queryParameters.set('username', username); + queryParameters = queryParameters.set('username', username); } if (password !== undefined) { - queryParameters.set('password', password); + queryParameters = queryParameters.set('password', password); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = this.defaultHeaders; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/user/login`, { + params: queryParameters, headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/logout'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + public logoutUser(): Observable<{}> { + let headers = this.defaultHeaders; - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Get, + return this.httpClient.get(`${this.basePath}/user/logout`, { headers: headers, - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } /** @@ -487,44 +200,20 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public updateUser(username: string, body: User, ): Observable<{}> { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - - headers.set('Content-Type', 'application/json'); + let headers = this.defaultHeaders; - let requestOptions: RequestOptionsArgs = new RequestOptions({ - method: RequestMethod.Put, + return this.httpClient.put(`${this.basePath}/user/${username}`, body, { headers: headers, - body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, - withCredentials:this.configuration.withCredentials + withCredentials: this.configuration.withCredentials, }); - // https://github.com/swagger-api/swagger-codegen/issues/4037 - if (extraHttpRequestParams) { - requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); - } - - return this.http.request(path, requestOptions); } } 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 b05fe8fc637..ecd750ff906 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 @@ -32,8 +32,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class PetService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -41,25 +41,10 @@ export class PetService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -79,7 +64,7 @@ export class PetService { * @summary Add a new pet to the store * @param body Pet object that needs to be added to the store */ - public addPet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public addPet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.addPetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -96,7 +81,7 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { + public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -112,7 +97,7 @@ export class PetService { * @summary Finds Pets by status * @param status Status values that need to be considered for filter */ - public findPetsByStatus(status: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByStatus(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -128,7 +113,7 @@ export class PetService { * @summary Finds Pets by tags * @param tags Tags to filter by */ - public findPetsByTags(tags: Array, extraHttpRequestParams?: any): Observable> { + public findPetsByTags(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable> { return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -144,7 +129,7 @@ export class PetService { * @summary Find pet by ID * @param petId ID of pet to return */ - public getPetById(petId: number, extraHttpRequestParams?: any): Observable { + public getPetById(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -160,7 +145,7 @@ export class PetService { * @summary Update an existing pet * @param body Pet object that needs to be added to the store */ - public updatePet(body: Pet, extraHttpRequestParams?: any): Observable<{}> { + public updatePet(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -178,7 +163,7 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + public updatePetWithForm(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -196,7 +181,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -213,25 +198,14 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public addPetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addPet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -239,14 +213,12 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -254,7 +226,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -263,30 +235,17 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } + + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 if (apiKey !== undefined && apiKey !== null) { headers.set('api_key', String(apiKey)); } - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -294,11 +253,9 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -306,7 +263,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -314,29 +271,20 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByStatus'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'status' is not null or undefined + public findPetsByStatusWithHttpInfo(status: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (status === null || status === undefined) { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } + + let queryParameters = new URLSearchParams(); if (status) { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -344,7 +292,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -356,7 +303,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -364,29 +311,20 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/findByTags'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'tags' is not null or undefined + public findPetsByTagsWithHttpInfo(tags: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (tags === null || tags === undefined) { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } + + let queryParameters = new URLSearchParams(); if (tags) { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -394,7 +332,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -406,7 +343,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -414,34 +351,21 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -449,7 +373,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -457,25 +381,14 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public updatePetWithHttpInfo(body: Pet, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -483,14 +396,12 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -498,7 +409,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -508,35 +419,14 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', String(petId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined + public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required - // oauth required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' ? this.configuration.accessToken() @@ -544,11 +434,18 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + let canConsumeForm = this.canConsumeForm(consumes); + let useForm = false; + let formParams = new (useForm ? FormData : URLSearchParams as any)() as { + set(param: string, value: any): void; + }; if (name !== undefined) { formParams.set('name', name); } - if (status !== undefined) { formParams.set('status', status); } @@ -557,7 +454,6 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -565,7 +461,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); } /** @@ -575,17 +471,21 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', String(petId)); + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + // authentication (petstore_auth) required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); } + // to determine the Content-Type header let consumes: string[] = [ 'multipart/form-data' @@ -596,26 +496,9 @@ export class PetService { let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -624,7 +507,6 @@ export class PetService { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -632,7 +514,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); } } 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 8765ad7c4a9..05ee087ba4e 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 @@ -31,8 +31,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class StoreService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -40,25 +40,10 @@ export class StoreService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -78,7 +63,7 @@ export class StoreService { * @summary Delete purchase order by ID * @param orderId ID of the order that needs to be deleted */ - public deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteOrder(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -93,7 +78,7 @@ export class StoreService { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { + public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -109,7 +94,7 @@ export class StoreService { * @summary Find purchase order by ID * @param orderId ID of pet that needs to be fetched */ - public getOrderById(orderId: number, extraHttpRequestParams?: any): Observable { + public getOrderById(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -125,7 +110,7 @@ export class StoreService { * @summary Place an order for a pet * @param body order placed for purchasing the pet */ - public placeOrder(body: Order, extraHttpRequestParams?: any): Observable { + public placeOrder(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -142,29 +127,16 @@ export class StoreService { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -172,35 +144,25 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/inventory'; + public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -208,7 +170,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -216,29 +178,16 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', String(orderId)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined + public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -246,7 +195,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); } /** @@ -254,31 +203,19 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public placeOrderWithHttpInfo(body: Order, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -286,7 +223,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order`, requestOptions); } } 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 4322a11f7ef..9869c67fdf1 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 @@ -31,8 +31,8 @@ import { CustomQueryEncoderHelper } from '../encoder'; export class UserService { protected basePath = 'http://petstore.swagger.io/v2'; - public defaultHeaders: Headers = new Headers(); - public configuration: Configuration = new Configuration(); + public defaultHeaders = new Headers(); + public configuration = new Configuration(); constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { if (basePath) { @@ -40,25 +40,10 @@ export class UserService { } if (configuration) { this.configuration = configuration; - this.basePath = basePath || configuration.basePath || this.basePath; + this.basePath = basePath || configuration.basePath || this.basePath; } } - /** - * - * Extends object by coping non-existing properties. - * @param objA object to be extended - * @param objB source object - */ - private extendObj(objA: T1, objB: T2) { - for(let key in objB){ - if(objB.hasOwnProperty(key)){ - (objA as any)[key] = (objB as any)[key]; - } - } - return objA; - } - /** * @param consumes string[] mime-types * @return true: consumes contains 'multipart/form-data', false: otherwise @@ -78,7 +63,7 @@ export class UserService { * @summary Create user * @param body Created user object */ - public createUser(body: User, extraHttpRequestParams?: any): Observable<{}> { + public createUser(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUserWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -94,7 +79,7 @@ export class UserService { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithArrayInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -110,7 +95,7 @@ export class UserService { * @summary Creates list of users with given input array * @param body List of user object */ - public createUsersWithListInput(body: Array, extraHttpRequestParams?: any): Observable<{}> { + public createUsersWithListInput(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -126,7 +111,7 @@ export class UserService { * @summary Delete user * @param username The name that needs to be deleted */ - public deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}> { + public deleteUser(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -142,7 +127,7 @@ export class UserService { * @summary Get user by user name * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName(username: string, extraHttpRequestParams?: any): Observable { + public getUserByName(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -159,7 +144,7 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser(username: string, password: string, extraHttpRequestParams?: any): Observable { + public loginUser(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -174,7 +159,7 @@ export class UserService { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: any): Observable<{}> { + public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -191,7 +176,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser(username: string, body: User, extraHttpRequestParams?: any): Observable<{}> { + public updateUser(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -208,31 +193,19 @@ export class UserService { * This can only be done by the logged in user. * @param body Created user object */ - public createUserWithHttpInfo(body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUserWithHttpInfo(body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -240,7 +213,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -248,31 +221,19 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithArray'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithArrayInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -280,7 +241,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -288,31 +249,19 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/createWithList'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'body' is not null or undefined + public createUsersWithListInputWithHttpInfo(body: Array, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -320,7 +269,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -328,29 +277,16 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -358,7 +294,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -366,29 +302,16 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -396,7 +319,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } /** @@ -405,20 +328,15 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/login'; - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public loginUserWithHttpInfo(username: string, password: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling loginUser.'); } - // verify required parameter 'password' is not null or undefined if (password === null || password === undefined) { throw new Error('Required parameter password was null or undefined when calling loginUser.'); } + + let queryParameters = new URLSearchParams(); if (username !== undefined) { queryParameters.set('username', username); } @@ -428,13 +346,8 @@ export class UserService { } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -446,31 +359,20 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/login`, requestOptions); } /** * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/logout'; + public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -478,7 +380,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -487,36 +389,22 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', String(username)); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined + public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } - // verify required parameter 'body' is not null or undefined if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updateUser.'); } - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters, withCredentials:this.configuration.withCredentials }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -524,7 +412,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${username}`, requestOptions); } } From 87547cd62f81d8dab3a0b5725cf47578cc95bacf Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 23:03:41 +0200 Subject: [PATCH 07/12] improve formatting --- .../src/main/resources/typescript-angular/api.service.mustache | 1 - 1 file changed, 1 deletion(-) 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 387a255fa02..1c352098266 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 @@ -139,7 +139,6 @@ export class {{classname}} { {{/isDateTime}} } {{/isListContainer}} - {{/queryParams}} {{/hasQueryParams}} From 012d478e0ba23194812d3ac696c2c410be952b5f Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Tue, 12 Sep 2017 23:07:53 +0200 Subject: [PATCH 08/12] updated samples --- .../petstore/typescript-angular-v2/default/api/pet.service.ts | 2 -- .../petstore/typescript-angular-v2/default/api/user.service.ts | 2 -- .../petstore/typescript-angular-v2/npm/api/pet.service.ts | 2 -- .../petstore/typescript-angular-v2/npm/api/user.service.ts | 2 -- .../typescript-angular-v2/with-interfaces/api/pet.service.ts | 2 -- .../typescript-angular-v2/with-interfaces/api/user.service.ts | 2 -- .../petstore/typescript-angular-v4.3/npm/api/pet.service.ts | 2 -- .../petstore/typescript-angular-v4.3/npm/api/user.service.ts | 2 -- .../petstore/typescript-angular-v4/npm/api/pet.service.ts | 2 -- .../petstore/typescript-angular-v4/npm/api/user.service.ts | 2 -- 10 files changed, 20 deletions(-) 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 ecd750ff906..433ed8e36e3 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 @@ -281,7 +281,6 @@ export class PetService { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required @@ -321,7 +320,6 @@ export class PetService { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required 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 9869c67fdf1..b2f94e80454 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 @@ -340,12 +340,10 @@ export class UserService { if (username !== undefined) { queryParameters.set('username', username); } - if (password !== undefined) { queryParameters.set('password', password); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 ecd750ff906..433ed8e36e3 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 @@ -281,7 +281,6 @@ export class PetService { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required @@ -321,7 +320,6 @@ export class PetService { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required 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 9869c67fdf1..b2f94e80454 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 @@ -340,12 +340,10 @@ export class UserService { if (username !== undefined) { queryParameters.set('username', username); } - if (password !== undefined) { queryParameters.set('password', password); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 461c98f431f..84e1fc027f3 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 @@ -282,7 +282,6 @@ export class PetService implements PetServiceInterface { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required @@ -322,7 +321,6 @@ export class PetService implements PetServiceInterface { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required 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 2ada4f5dec8..73f4039e585 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 @@ -341,12 +341,10 @@ export class UserService implements UserServiceInterface { if (username !== undefined) { queryParameters.set('username', username); } - if (password !== undefined) { queryParameters.set('password', password); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 c4d9c129200..d27768c629a 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 @@ -129,7 +129,6 @@ export class PetService { queryParameters = queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - let headers = this.defaultHeaders; // authentication (petstore_auth) required @@ -162,7 +161,6 @@ export class PetService { queryParameters = queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - let headers = this.defaultHeaders; // authentication (petstore_auth) required 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 a464c578477..3cc9e90e26a 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 @@ -165,12 +165,10 @@ export class UserService { if (username !== undefined) { queryParameters = queryParameters.set('username', username); } - if (password !== undefined) { queryParameters = queryParameters.set('password', password); } - let headers = this.defaultHeaders; return this.httpClient.get(`${this.basePath}/user/login`, { 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 ecd750ff906..433ed8e36e3 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 @@ -281,7 +281,6 @@ export class PetService { queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required @@ -321,7 +320,6 @@ export class PetService { queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // authentication (petstore_auth) required 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 9869c67fdf1..b2f94e80454 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 @@ -340,12 +340,10 @@ export class UserService { if (username !== undefined) { queryParameters.set('username', username); } - if (password !== undefined) { queryParameters.set('password', password); } - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ From 969a7453939d1ec6d2a8c8aa0f2a0a5cbd93f4b9 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Wed, 13 Sep 2017 18:29:52 +0200 Subject: [PATCH 09/12] fix compilation error in generated code the overload for blobs does not have a type parameter --- .../src/main/resources/typescript-angular/api.service.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 1c352098266..de70edb0e99 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 @@ -233,7 +233,7 @@ export class {{classname}} { {{/hasFormParams}} {{#useHttpClient}} - return this.httpClient.{{httpMethod}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}}{{#hasFormParams}}formParams, {{/hasFormParams}}{ + return this.httpClient.{{httpMethod}}{{^isResponseFile}}{{/isResponseFile}}(`${this.basePath}{{{path}}}`, {{#bodyParam}}{{paramName}}, {{/bodyParam}}{{#hasFormParams}}formParams, {{/hasFormParams}}{ {{#hasQueryParams}} params: queryParameters, {{/hasQueryParams}} From dedfb676300f58aee0e98634781d3f9f18ee2482 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Thu, 14 Sep 2017 16:28:22 +0200 Subject: [PATCH 10/12] added the first test for the utils package --- .../io/swagger/codegen/utils/SemVerTest.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 modules/swagger-codegen/src/test/java/io/swagger/codegen/utils/SemVerTest.java diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/utils/SemVerTest.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/utils/SemVerTest.java new file mode 100644 index 00000000000..ed7c38b1130 --- /dev/null +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/utils/SemVerTest.java @@ -0,0 +1,21 @@ +package io.swagger.codegen.utils; + +import org.testng.annotations.Test; + +import static org.testng.Assert.*; + +public class SemVerTest { + + @Test + public void parsingAndPrinting() { + assertEquals("4.3.0", new SemVer("4.3").toString()); + } + + @Test + public void atLeast() { + assertTrue(new SemVer("3.2.1").atLeast("3.2.1")); + assertTrue(new SemVer("3.2.1").atLeast("2.3.4")); + assertFalse(new SemVer("3.2.1").atLeast("3.3.0")); + } + +} From 11f6a0ec19b8ff8f7811b1d30d5fca5bc9341b71 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Fri, 29 Sep 2017 18:50:47 +0200 Subject: [PATCH 11/12] fix extra trainling commas in function argument lists --- .../main/resources/typescript-angular/api.service.mustache | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 de70edb0e99..f3c5c7c72d1 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 @@ -80,7 +80,7 @@ export class {{classname}} { {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ {{! if you change this method signature, also change the version below }} - public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{^useHttpClient}}extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { + public {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{^useHttpClient}}, extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}> { return this.{{nickname}}WithHttpInfo({{#allParams}}{{paramName}}, {{/allParams}}extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -105,7 +105,7 @@ export class {{classname}} { * {{notes}} {{#allParams}}* @param {{paramName}} {{description}} {{/allParams}}*/ - public {{nickname}}{{^useHttpClient}}WithHttpInfo{{/useHttpClient}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}{{^useHttpClient}}extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#useHttpClient}}{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}{{/useHttpClient}}{{^useHttpClient}}Response{{/useHttpClient}}> { + public {{nickname}}{{^useHttpClient}}WithHttpInfo{{/useHttpClient}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{^useHttpClient}}, extraHttpRequestParams?: RequestOptionsArgs{{/useHttpClient}}): Observable<{{#useHttpClient}}{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}{}{{/returnType}}{{/useHttpClient}}{{^useHttpClient}}Response{{/useHttpClient}}> { {{#allParams}} {{#required}} if ({{paramName}} === null || {{paramName}} === undefined) { From 27cf91579f11dbe056c163d4645a4eaabaddba58 Mon Sep 17 00:00:00 2001 From: Adrian Moos Date: Fri, 29 Sep 2017 19:00:15 +0200 Subject: [PATCH 12/12] regenerated samples --- .../default/api/pet.service.ts | 135 +----------------- .../default/api/store.service.ts | 72 +--------- .../default/api/user.service.ts | 125 +--------------- .../npm/api/pet.service.ts | 135 +----------------- .../npm/api/store.service.ts | 72 +--------- .../npm/api/user.service.ts | 125 +--------------- .../with-interfaces/api/pet.service.ts | 135 +----------------- .../with-interfaces/api/store.service.ts | 72 +--------- .../with-interfaces/api/user.service.ts | 125 +--------------- .../npm/api/pet.service.ts | 24 ++-- .../npm/api/store.service.ts | 10 +- .../npm/api/user.service.ts | 20 +-- .../npm/api/pet.service.ts | 96 +------------ .../npm/api/store.service.ts | 50 +------ .../npm/api/user.service.ts | 92 +----------- .../typescript-angular-v4/npm/package.json | 2 +- 16 files changed, 80 insertions(+), 1210 deletions(-) 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 95b869ead16..af6fdd96512 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 @@ -59,11 +59,6 @@ export class PetService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -210,10 +205,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -244,18 +235,7 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ -<<<<<<< HEAD public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined ->>>>>>> master if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } @@ -265,20 +245,6 @@ export class PetService { headers.set('api_key', String(apiKey)); } -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -297,7 +263,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -317,10 +283,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -360,10 +322,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -391,28 +349,13 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ -<<<<<<< HEAD public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined ->>>>>>> master if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -428,7 +371,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -443,10 +386,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -478,45 +417,13 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ -<<<<<<< HEAD public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } -======= - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; ->>>>>>> master - - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -552,7 +459,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -562,16 +469,10 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ -<<<<<<< HEAD public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } -======= - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); ->>>>>>> master let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -587,40 +488,12 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - let canConsumeForm = this.canConsumeForm(consumes); let useForm = false; useForm = canConsumeForm; let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - ->>>>>>> master if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -639,7 +512,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}/uploadImage`, requestOptions); } } 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 f0aa6905b65..86d4f836ec1 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 @@ -58,11 +58,6 @@ export class StoreService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -83,7 +78,7 @@ export class StoreService { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { + public getInventory(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -132,32 +127,13 @@ export class StoreService { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ -<<<<<<< HEAD public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', encodeURIComponent(String(orderId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined ->>>>>>> master if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -168,30 +144,17 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public getInventoryWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -215,32 +178,13 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ -<<<<<<< HEAD public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', encodeURIComponent(String(orderId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined ->>>>>>> master if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -251,7 +195,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -266,14 +210,6 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 9dc815d759f..2d2fc881039 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 @@ -58,11 +58,6 @@ export class UserService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -164,7 +159,7 @@ export class UserService { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + public logoutUser(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -205,14 +200,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -241,14 +228,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -277,14 +256,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -306,32 +277,13 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ -<<<<<<< HEAD public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -342,7 +294,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -350,32 +302,13 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ -<<<<<<< HEAD public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -386,7 +319,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -413,20 +346,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -445,25 +364,10 @@ export class UserService { * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public logoutUserWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -483,18 +387,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ -<<<<<<< HEAD public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } @@ -504,14 +397,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -525,7 +410,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } } 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 95b869ead16..af6fdd96512 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 @@ -59,11 +59,6 @@ export class PetService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -210,10 +205,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -244,18 +235,7 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ -<<<<<<< HEAD public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined ->>>>>>> master if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } @@ -265,20 +245,6 @@ export class PetService { headers.set('api_key', String(apiKey)); } -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -297,7 +263,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -317,10 +283,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -360,10 +322,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -391,28 +349,13 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ -<<<<<<< HEAD public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined ->>>>>>> master if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -428,7 +371,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -443,10 +386,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -478,45 +417,13 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ -<<<<<<< HEAD public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } -======= - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; ->>>>>>> master - - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -552,7 +459,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -562,16 +469,10 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ -<<<<<<< HEAD public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } -======= - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); ->>>>>>> master let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -587,40 +488,12 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - let canConsumeForm = this.canConsumeForm(consumes); let useForm = false; useForm = canConsumeForm; let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - ->>>>>>> master if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -639,7 +512,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}/uploadImage`, requestOptions); } } 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 f0aa6905b65..86d4f836ec1 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 @@ -58,11 +58,6 @@ export class StoreService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -83,7 +78,7 @@ export class StoreService { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { + public getInventory(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -132,32 +127,13 @@ export class StoreService { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ -<<<<<<< HEAD public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', encodeURIComponent(String(orderId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined ->>>>>>> master if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -168,30 +144,17 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public getInventoryWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -215,32 +178,13 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ -<<<<<<< HEAD public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', encodeURIComponent(String(orderId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined ->>>>>>> master if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -251,7 +195,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -266,14 +210,6 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 9dc815d759f..2d2fc881039 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 @@ -58,11 +58,6 @@ export class UserService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -164,7 +159,7 @@ export class UserService { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + public logoutUser(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -205,14 +200,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -241,14 +228,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -277,14 +256,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -306,32 +277,13 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ -<<<<<<< HEAD public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -342,7 +294,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -350,32 +302,13 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ -<<<<<<< HEAD public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -386,7 +319,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -413,20 +346,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -445,25 +364,10 @@ export class UserService { * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public logoutUserWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -483,18 +387,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ -<<<<<<< HEAD public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } @@ -504,14 +397,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -525,7 +410,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } } 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 1c863032e8c..eb9c6fcc3bf 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 @@ -60,11 +60,6 @@ export class PetService implements PetServiceInterface { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -211,10 +206,6 @@ export class PetService implements PetServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -245,18 +236,7 @@ export class PetService implements PetServiceInterface { * @param petId Pet id to delete * @param apiKey */ -<<<<<<< HEAD public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined ->>>>>>> master if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } @@ -266,20 +246,6 @@ export class PetService implements PetServiceInterface { headers.set('api_key', String(apiKey)); } -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -298,7 +264,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -318,10 +284,6 @@ export class PetService implements PetServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -361,10 +323,6 @@ export class PetService implements PetServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -392,28 +350,13 @@ export class PetService implements PetServiceInterface { * Returns a single pet * @param petId ID of pet to return */ -<<<<<<< HEAD public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'petId' is not null or undefined ->>>>>>> master if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -429,7 +372,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -444,10 +387,6 @@ export class PetService implements PetServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -479,45 +418,13 @@ export class PetService implements PetServiceInterface { * @param name Updated name of the pet * @param status Updated status of the pet */ -<<<<<<< HEAD public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } -======= - public updatePetWithFormWithHttpInfo(petId: number, name?: string, status?: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - // verify required parameter 'petId' is not null or undefined - if (petId === null || petId === undefined) { - throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); - } - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; ->>>>>>> master - - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -553,7 +460,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -563,16 +470,10 @@ export class PetService implements PetServiceInterface { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ -<<<<<<< HEAD public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: RequestOptionsArgs): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } -======= - public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: Blob, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/pet/${petId}/uploadImage' - .replace('${' + 'petId' + '}', encodeURIComponent(String(petId))); ->>>>>>> master let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 @@ -588,40 +489,12 @@ export class PetService implements PetServiceInterface { let consumes: string[] = [ 'multipart/form-data' ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - let canConsumeForm = this.canConsumeForm(consumes); let useForm = false; useForm = canConsumeForm; let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - ->>>>>>> master if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -640,7 +513,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}/uploadImage`, requestOptions); } } 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 45ab9aae35f..12aaf319a9c 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 @@ -59,11 +59,6 @@ export class StoreService implements StoreServiceInterface { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -84,7 +79,7 @@ export class StoreService implements StoreServiceInterface { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { + public getInventory(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -133,32 +128,13 @@ export class StoreService implements StoreServiceInterface { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ -<<<<<<< HEAD public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', encodeURIComponent(String(orderId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined ->>>>>>> master if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -169,30 +145,17 @@ export class StoreService implements StoreServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public getInventoryWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -216,32 +179,13 @@ export class StoreService implements StoreServiceInterface { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ -<<<<<<< HEAD public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getOrderByIdWithHttpInfo(orderId: number, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/store/order/${orderId}' - .replace('${' + 'orderId' + '}', encodeURIComponent(String(orderId))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'orderId' is not null or undefined ->>>>>>> master if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -252,7 +196,7 @@ export class StoreService implements StoreServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -267,14 +211,6 @@ export class StoreService implements StoreServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 122c6df0138..0d10cf1874e 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 @@ -59,11 +59,6 @@ export class UserService implements UserServiceInterface { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -165,7 +160,7 @@ export class UserService implements UserServiceInterface { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + public logoutUser(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -206,14 +201,6 @@ export class UserService implements UserServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -242,14 +229,6 @@ export class UserService implements UserServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -278,14 +257,6 @@ export class UserService implements UserServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -307,32 +278,13 @@ export class UserService implements UserServiceInterface { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ -<<<<<<< HEAD public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -343,7 +295,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -351,32 +303,13 @@ export class UserService implements UserServiceInterface { * * @param username The name that needs to be fetched. Use user1 for testing. */ -<<<<<<< HEAD public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -387,7 +320,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -414,20 +347,6 @@ export class UserService implements UserServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -446,25 +365,10 @@ export class UserService implements UserServiceInterface { * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public logoutUserWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -484,18 +388,7 @@ export class UserService implements UserServiceInterface { * @param username name that need to be deleted * @param body Updated user object */ -<<<<<<< HEAD public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: RequestOptionsArgs): Observable { -======= - public updateUserWithHttpInfo(username: string, body: User, extraHttpRequestParams?: any): Observable { - const path = this.basePath + '/user/${username}' - .replace('${' + 'username' + '}', encodeURIComponent(String(username))); - - let queryParameters = new URLSearchParams('', new CustomQueryEncoderHelper()); - let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - - // verify required parameter 'username' is not null or undefined ->>>>>>> master if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } @@ -505,14 +398,6 @@ export class UserService implements UserServiceInterface { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -526,7 +411,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } } 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 d27768c629a..9e7e00d1e48 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 @@ -63,7 +63,7 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public addPet(body: Pet, ): Observable<{}> { + public addPet(body: Pet): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling addPet.'); } @@ -90,7 +90,7 @@ export class PetService { * @param petId Pet id to delete * @param apiKey */ - public deletePet(petId: number, apiKey?: string, ): Observable<{}> { + public deletePet(petId: number, apiKey?: string): Observable<{}> { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling deletePet.'); } @@ -108,7 +108,7 @@ export class PetService { headers = headers.set('Authorization', 'Bearer ' + accessToken); } - return this.httpClient.delete(`${this.basePath}/pet/${petId}`, { + return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(petId)}`, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -119,7 +119,7 @@ export class PetService { * Multiple status values can be provided with comma separated strings * @param status Status values that need to be considered for filter */ - public findPetsByStatus(status: Array, ): Observable> { + public findPetsByStatus(status: Array): Observable> { if (status === null || status === undefined) { throw new Error('Required parameter status was null or undefined when calling findPetsByStatus.'); } @@ -151,7 +151,7 @@ export class PetService { * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. * @param tags Tags to filter by */ - public findPetsByTags(tags: Array, ): Observable> { + public findPetsByTags(tags: Array): Observable> { if (tags === null || tags === undefined) { throw new Error('Required parameter tags was null or undefined when calling findPetsByTags.'); } @@ -183,7 +183,7 @@ export class PetService { * Returns a single pet * @param petId ID of pet to return */ - public getPetById(petId: number, ): Observable { + public getPetById(petId: number): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling getPetById.'); } @@ -195,7 +195,7 @@ export class PetService { headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); } - return this.httpClient.get(`${this.basePath}/pet/${petId}`, { + return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(petId)}`, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -206,7 +206,7 @@ export class PetService { * * @param body Pet object that needs to be added to the store */ - public updatePet(body: Pet, ): Observable<{}> { + public updatePet(body: Pet): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling updatePet.'); } @@ -234,7 +234,7 @@ export class PetService { * @param name Updated name of the pet * @param status Updated status of the pet */ - public updatePetWithForm(petId: number, name?: string, status?: string, ): Observable<{}> { + public updatePetWithForm(petId: number, name?: string, status?: string): Observable<{}> { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } @@ -265,7 +265,7 @@ export class PetService { formParams.set('status', status); } - return this.httpClient.post(`${this.basePath}/pet/${petId}`, formParams, { + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(petId)}`, formParams, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -278,7 +278,7 @@ export class PetService { * @param additionalMetadata Additional data to pass to server * @param file file to upload */ - public uploadFile(petId: number, additionalMetadata?: string, file?: Blob, ): Observable { + public uploadFile(petId: number, additionalMetadata?: string, file?: Blob): Observable { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); } @@ -310,7 +310,7 @@ export class PetService { formParams.set('file', file); } - return this.httpClient.post(`${this.basePath}/pet/${petId}/uploadImage`, formParams, { + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(petId)}/uploadImage`, 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 795e2bfbc6b..e52b46095ce 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 @@ -62,14 +62,14 @@ export class StoreService { * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors * @param orderId ID of the order that needs to be deleted */ - public deleteOrder(orderId: string, ): Observable<{}> { + public deleteOrder(orderId: string): Observable<{}> { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); } let headers = this.defaultHeaders; - return this.httpClient.delete(`${this.basePath}/store/order/${orderId}`, { + return this.httpClient.delete(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -99,14 +99,14 @@ export class StoreService { * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions * @param orderId ID of pet that needs to be fetched */ - public getOrderById(orderId: number, ): Observable { + public getOrderById(orderId: number): Observable { if (orderId === null || orderId === undefined) { throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); } let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/store/order/${orderId}`, { + return this.httpClient.get(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -117,7 +117,7 @@ export class StoreService { * * @param body order placed for purchasing the pet */ - public placeOrder(body: Order, ): Observable { + public placeOrder(body: Order): Observable { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling placeOrder.'); } 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 3cc9e90e26a..cc53d7367bc 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 @@ -62,7 +62,7 @@ export class UserService { * This can only be done by the logged in user. * @param body Created user object */ - public createUser(body: User, ): Observable<{}> { + public createUser(body: User): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUser.'); } @@ -80,7 +80,7 @@ export class UserService { * * @param body List of user object */ - public createUsersWithArrayInput(body: Array, ): Observable<{}> { + public createUsersWithArrayInput(body: Array): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } @@ -98,7 +98,7 @@ export class UserService { * * @param body List of user object */ - public createUsersWithListInput(body: Array, ): Observable<{}> { + public createUsersWithListInput(body: Array): Observable<{}> { if (body === null || body === undefined) { throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); } @@ -116,14 +116,14 @@ export class UserService { * This can only be done by the logged in user. * @param username The name that needs to be deleted */ - public deleteUser(username: string, ): Observable<{}> { + public deleteUser(username: string): Observable<{}> { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling deleteUser.'); } let headers = this.defaultHeaders; - return this.httpClient.delete(`${this.basePath}/user/${username}`, { + return this.httpClient.delete(`${this.basePath}/user/${encodeURIComponent(username)}`, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -134,14 +134,14 @@ export class UserService { * * @param username The name that needs to be fetched. Use user1 for testing. */ - public getUserByName(username: string, ): Observable { + public getUserByName(username: string): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling getUserByName.'); } let headers = this.defaultHeaders; - return this.httpClient.get(`${this.basePath}/user/${username}`, { + return this.httpClient.get(`${this.basePath}/user/${encodeURIComponent(username)}`, { headers: headers, withCredentials: this.configuration.withCredentials, }); @@ -153,7 +153,7 @@ export class UserService { * @param username The user name for login * @param password The password for login in clear text */ - public loginUser(username: string, password: string, ): Observable { + public loginUser(username: string, password: string): Observable { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling loginUser.'); } @@ -198,7 +198,7 @@ export class UserService { * @param username name that need to be deleted * @param body Updated user object */ - public updateUser(username: string, body: User, ): Observable<{}> { + public updateUser(username: string, body: User): Observable<{}> { if (username === null || username === undefined) { throw new Error('Required parameter username was null or undefined when calling updateUser.'); } @@ -208,7 +208,7 @@ export class UserService { let headers = this.defaultHeaders; - return this.httpClient.put(`${this.basePath}/user/${username}`, body, { + return this.httpClient.put(`${this.basePath}/user/${encodeURIComponent(username)}`, body, { headers: headers, withCredentials: this.configuration.withCredentials, }); 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 aa3a93ed879..af6fdd96512 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 @@ -59,11 +59,6 @@ export class PetService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); - } - /** * * @summary Add a new pet to the store @@ -210,10 +205,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -254,20 +245,6 @@ export class PetService { headers.set('api_key', String(apiKey)); } -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -286,7 +263,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -306,10 +283,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -349,10 +322,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -387,10 +356,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -406,7 +371,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -421,10 +386,6 @@ export class PetService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -460,30 +421,9 @@ export class PetService { if (petId === null || petId === undefined) { throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); } -<<<<<<< HEAD -======= - // to determine the Content-Type header - let consumes: string[] = [ - 'application/x-www-form-urlencoded' - ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - - let canConsumeForm = this.canConsumeForm(consumes); - let useForm = false; - let formParams = new (useForm ? FormData : URLSearchParams as any)() as { - set(param: string, value: any): void; - }; ->>>>>>> master let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - // authentication (petstore_auth) required if (this.configuration.accessToken) { let accessToken = typeof this.configuration.accessToken === 'function' @@ -519,7 +459,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -548,40 +488,12 @@ export class PetService { let consumes: string[] = [ 'multipart/form-data' ]; - - if (consumes != null && consumes.length > 0) { - headers.set('Content-Type', consumes.filter(item => this.isJsonMime(item)).join(";")); - } - let canConsumeForm = this.canConsumeForm(consumes); let useForm = false; useForm = canConsumeForm; let formParams = new (useForm ? FormData : URLSearchParams as any)() as { set(param: string, value: any): void; }; -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - // authentication (petstore_auth) required - // oauth required - if (this.configuration.accessToken) { - let accessToken = typeof this.configuration.accessToken === 'function' - ? this.configuration.accessToken() - : this.configuration.accessToken; - headers.set('Authorization', 'Bearer ' + accessToken); - } - - ->>>>>>> master if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } @@ -600,7 +512,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/pet/${petId}/uploadImage`, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}/uploadImage`, requestOptions); } } 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 ca8afc05a5d..86d4f836ec1 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 @@ -58,11 +58,6 @@ export class StoreService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -83,7 +78,7 @@ export class StoreService { * Returns a map of status codes to quantities * @summary Returns pet inventories by status */ - public getInventory(extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { + public getInventory(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{ [key: string]: number; }> { return this.getInventoryWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -139,14 +134,6 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -157,30 +144,17 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** * Returns pet inventories by status * Returns a map of status codes to quantities */ - public getInventoryWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public getInventoryWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - ->>>>>>> master // authentication (api_key) required if (this.configuration.apiKeys["api_key"]) { headers.set('api_key', this.configuration.apiKeys["api_key"]); @@ -211,14 +185,6 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -229,7 +195,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/store/order/${orderId}`, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -244,14 +210,6 @@ export class StoreService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ 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 890e61e507a..2d2fc881039 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 @@ -58,11 +58,6 @@ export class UserService { return false; } - public isJsonMime(mime: string): boolean { - const jsonMime: RegExp = new RegExp('(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$'); - 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 @@ -164,7 +159,7 @@ export class UserService { * * @summary Logs out current logged in user session */ - public logoutUser(extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { + public logoutUser(, extraHttpRequestParams?: RequestOptionsArgs): Observable<{}> { return this.logoutUserWithHttpInfo(extraHttpRequestParams) .map((response: Response) => { if (response.status === 204) { @@ -205,14 +200,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -241,14 +228,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -277,14 +256,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -313,14 +284,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, @@ -331,7 +294,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -346,14 +309,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -364,7 +319,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -391,20 +346,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -423,25 +364,10 @@ export class UserService { * Logs out current logged in user session * */ - public logoutUserWithHttpInfo(extraHttpRequestParams?: RequestOptionsArgs): Observable { + public logoutUserWithHttpInfo(, extraHttpRequestParams?: RequestOptionsArgs): Observable { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - - // to determine the Accept header - let produces: string[] = [ - 'application/xml', - 'application/json' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -471,14 +397,6 @@ export class UserService { let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 -<<<<<<< HEAD -======= - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - ->>>>>>> master headers.set('Content-Type', 'application/json'); let requestOptions: RequestOptionsArgs = new RequestOptions({ @@ -492,7 +410,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(`${this.basePath}/user/${username}`, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } } diff --git a/samples/client/petstore/typescript-angular-v4/npm/package.json b/samples/client/petstore/typescript-angular-v4/npm/package.json index b33b2586f0f..af9c5d898e6 100644 --- a/samples/client/petstore/typescript-angular-v4/npm/package.json +++ b/samples/client/petstore/typescript-angular-v4/npm/package.json @@ -35,6 +35,6 @@ "typescript": "^2.1.5" }, "publishConfig": { - "registry": "https://skimdb.npmjs.com/registry" + "registry":"https://skimdb.npmjs.com/registry" } }