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/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..b2d4d5f316a 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.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -14,6 +15,7 @@ import io.swagger.codegen.CodegenModel; 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 +37,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 +56,7 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode 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 +101,18 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode } // 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"); + 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("useHttpClient", ngVersion.atLeast("4.3.0")); } private void addNpmPackageGeneration() { @@ -217,36 +215,40 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode 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 - op.path = op.path.replaceAll("\\{(.*?)\\}", "\\$\\{$1\\}"); + // Convert path to TypeScript template string, applying URI encoding + op.path = op.path.replaceAll("\\{(.*?)\\}", "\\$\\{encodeURIComponent($1)\\}"); } // Add additional filename information for model imports in the services @@ -316,14 +318,6 @@ public class TypeScriptAngularClientCodegen extends AbstractTypeScriptClientCode 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/api.service.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular/api.service.mustache index c8775b7d7dd..5426add37bd 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,34 +41,19 @@ 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; } } - /** - * - * 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,11 +68,15 @@ export class {{classname}} { return false; } + public isJsonMime(mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); } +{{^useHttpClient}} +{{! not sure why we used to generate a second method here rather than inlining those few lines of code, + but let's keep it for now for the sake of backwards compatiblity. }} {{#operation}} /** * {{¬es}} @@ -91,12 +85,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}}}{{#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) { @@ -113,6 +103,7 @@ export class {{classname}} { } {{/operation}} +{{/useHttpClient}} {{#operation}} /** @@ -120,59 +111,95 @@ 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}}' + '}', encodeURIComponent(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}}}{{#hasMore}}, {{/hasMore}}{{/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}} + +{{#authMethods}} + // authentication ({{name}}) required +{{#isApiKey}} +{{#isKeyInHeader}} + if (this.configuration.apiKeys["{{keyParamName}}"]) { + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); + } + +{{/isKeyInHeader}} +{{#isKeyInQuery}} + if (this.configuration.apiKeys["{{keyParamName}}"]) { + {{#useHttpClient}}queryParameters = {{/useHttpClient}}queryParameters.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); + } + +{{/isKeyInQuery}} +{{/isApiKey}} +{{#isBasic}} + if (this.configuration.username || this.configuration.password) { + {{#useHttpClient}}headers = {{/useHttpClient}}headers.set('Authorization', 'Basic ' + btoa(this.configuration.username + ':' + this.configuration.password)); + } + +{{/isBasic}} +{{#isOAuth}} + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.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[] = [ @@ -180,11 +207,6 @@ export class {{classname}} { '{{{mediaType}}}'{{#hasMore}},{{/hasMore}} {{/consumes}} ]; - - 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; {{#formParams}} @@ -195,58 +217,6 @@ export class {{classname}} { 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}} - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - -{{#authMethods}} - // authentication ({{name}}) required -{{#isApiKey}} -{{#isKeyInHeader}} - if (this.configuration.apiKeys["{{keyParamName}}"]) { - headers.set('{{keyParamName}}', this.configuration.apiKeys["{{keyParamName}}"]); - } - -{{/isKeyInHeader}} -{{#isKeyInQuery}} - if (this.configuration.apiKeys["{{keyParamName}}"]) { - 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)); - } - -{{/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); - } - -{{/isOAuth}} -{{/authMethods}} - -{{#bodyParam}} - headers.set('Content-Type', 'application/json'); - -{{/bodyParam}} {{#formParams}} {{#isListContainer}} if ({{paramName}}) { @@ -265,8 +235,22 @@ export class {{classname}} { formParams.set('{{baseName}}', {{paramName}}); } {{/isListContainer}} - {{/formParams}} + +{{/hasFormParams}} +{{#useHttpClient}} + return this.httpClient.{{httpMethod}}{{^isResponseFile}}{{/isResponseFile}}(`${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, @@ -279,7 +263,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 @@ -287,9 +273,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}} 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 @@ public class TypeScriptAngularClientOptionsTest extends AbstractOptionsTest { 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; }}; 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; 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")); + } + +} 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 f8265399f42..810cc78fea1 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 @@ -74,6 +59,7 @@ export class PetService { return false; } + public isJsonMime(mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); @@ -84,7 +70,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) { @@ -101,7 +87,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) { @@ -117,7 +103,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) { @@ -133,7 +119,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) { @@ -149,7 +135,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) { @@ -165,7 +151,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) { @@ -183,7 +169,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) { @@ -201,7 +187,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) { @@ -218,29 +204,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -248,14 +219,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 @@ -263,7 +232,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -272,34 +241,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' + '}', 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 + 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' - ]; - - 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() @@ -307,11 +259,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 @@ -319,7 +269,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -327,33 +277,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -361,7 +297,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -373,7 +308,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -381,33 +316,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -415,7 +336,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -427,7 +347,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -435,38 +355,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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 @@ -474,7 +377,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -482,29 +385,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -512,14 +400,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 @@ -527,7 +413,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -537,44 +423,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' + '}', 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 + 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' - ]; - 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; - }; - - // 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(';')); - } + 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() @@ -582,11 +438,19 @@ 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); } @@ -595,7 +459,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 @@ -603,7 +466,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -613,44 +476,14 @@ 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' + '}', 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 + 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.'); } - // to determine the Content-Type header - 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; - }; - - // 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(';')); - } + 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() @@ -658,11 +491,20 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } + // 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; + }; if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -671,7 +513,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 @@ -679,7 +520,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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 4f4189c369b..ece39b793e5 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 @@ -83,7 +68,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) { @@ -98,7 +83,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) { @@ -114,7 +99,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) { @@ -130,7 +115,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) { @@ -147,33 +132,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -181,39 +149,25 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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?: 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' - ]; - - 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"]); } - 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 @@ -221,7 +175,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -229,33 +183,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -263,7 +200,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -271,27 +208,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -299,7 +221,6 @@ export class StoreService { 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 @@ -307,7 +228,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 f9cf1b9fb71..dd5cfdb4a63 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 @@ -73,6 +58,7 @@ export class UserService { return false; } + public isJsonMime(mime: string): boolean { const jsonMime: RegExp = new RegExp('^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i'); return mime != null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json'); @@ -83,7 +69,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) { @@ -99,7 +85,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) { @@ -115,7 +101,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) { @@ -131,7 +117,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) { @@ -147,7 +133,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) { @@ -164,7 +150,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) { @@ -179,7 +165,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) { @@ -196,7 +182,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) { @@ -213,27 +199,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -241,7 +212,6 @@ export class UserService { 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 @@ -249,7 +219,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -257,27 +227,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -285,7 +240,6 @@ export class UserService { 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 @@ -293,7 +247,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -301,27 +255,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -329,7 +268,6 @@ export class UserService { 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 @@ -337,7 +275,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -345,33 +283,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -379,7 +300,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -387,33 +308,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -421,7 +325,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -430,39 +334,23 @@ 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); } - if (password !== undefined) { queryParameters.set('password', password); } - - // 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(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -475,35 +363,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - 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 @@ -511,7 +384,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -520,32 +393,15 @@ 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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -553,7 +409,6 @@ export class UserService { 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 @@ -561,7 +416,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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 f8265399f42..6be4b769281 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 @@ -84,7 +69,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) { @@ -101,7 +86,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) { @@ -117,7 +102,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) { @@ -133,7 +118,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) { @@ -149,7 +134,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) { @@ -165,7 +150,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) { @@ -183,7 +168,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) { @@ -201,7 +186,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) { @@ -218,29 +203,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -248,14 +218,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 @@ -263,7 +231,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -272,34 +240,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' + '}', 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 + 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' - ]; - - 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() @@ -307,11 +258,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 @@ -319,7 +268,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -327,33 +276,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -361,7 +296,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -373,7 +307,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -381,33 +315,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -415,7 +335,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -427,7 +346,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -435,38 +354,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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 @@ -474,7 +376,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -482,29 +384,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -512,14 +399,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 @@ -527,7 +412,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -537,44 +422,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' + '}', 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 + 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' - ]; - 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; - }; - - // 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(';')); - } + 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() @@ -582,11 +437,19 @@ 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); } @@ -595,7 +458,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 @@ -603,7 +465,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -613,44 +475,14 @@ 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' + '}', 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 + 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.'); } - // to determine the Content-Type header - 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; - }; - - // 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(';')); - } + 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() @@ -658,11 +490,20 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } + // 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; + }; if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -671,7 +512,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 @@ -679,7 +519,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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 4f4189c369b..ece39b793e5 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 @@ -83,7 +68,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) { @@ -98,7 +83,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) { @@ -114,7 +99,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) { @@ -130,7 +115,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) { @@ -147,33 +132,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -181,39 +149,25 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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?: 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' - ]; - - 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"]); } - 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 @@ -221,7 +175,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -229,33 +183,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -263,7 +200,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -271,27 +208,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -299,7 +221,6 @@ export class StoreService { 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 @@ -307,7 +228,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 f9cf1b9fb71..df87073fcae 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 @@ -83,7 +68,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) { @@ -99,7 +84,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) { @@ -115,7 +100,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) { @@ -131,7 +116,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) { @@ -147,7 +132,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) { @@ -164,7 +149,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) { @@ -179,7 +164,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) { @@ -196,7 +181,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) { @@ -213,27 +198,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -241,7 +211,6 @@ export class UserService { 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 @@ -249,7 +218,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -257,27 +226,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -285,7 +239,6 @@ export class UserService { 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 @@ -293,7 +246,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -301,27 +254,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -329,7 +267,6 @@ export class UserService { 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 @@ -337,7 +274,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -345,33 +282,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -379,7 +299,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -387,33 +307,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -421,7 +324,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -430,28 +333,23 @@ 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); } - if (password !== undefined) { queryParameters.set('password', password); } + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 // to determine the Accept header let produces: string[] = [ @@ -463,7 +361,6 @@ export class UserService { headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -475,20 +372,17 @@ 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', @@ -499,11 +393,9 @@ export class UserService { headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); } - 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 @@ -511,7 +403,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -520,32 +412,15 @@ 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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -553,7 +428,6 @@ export class UserService { 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 @@ -561,7 +435,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } } 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-v2/with-interfaces/api/pet.service.ts b/samples/client/petstore/typescript-angular-v2/with-interfaces/api/pet.service.ts index 0ab81caabba..7ac0f042a05 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 @@ -85,7 +70,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) { @@ -102,7 +87,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) { @@ -118,7 +103,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) { @@ -134,7 +119,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) { @@ -150,7 +135,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) { @@ -166,7 +151,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) { @@ -184,7 +169,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) { @@ -202,7 +187,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) { @@ -219,29 +204,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -249,14 +219,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 @@ -264,7 +232,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); } /** @@ -273,34 +241,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' + '}', 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 + 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' - ]; - - 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() @@ -308,11 +259,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 @@ -320,7 +269,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -328,33 +277,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -362,7 +297,6 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -374,7 +308,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); } /** @@ -382,33 +316,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -416,7 +336,6 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -428,7 +347,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); } /** @@ -436,38 +355,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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 @@ -475,7 +377,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -483,29 +385,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -513,14 +400,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 @@ -528,7 +413,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); } /** @@ -538,44 +423,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' + '}', 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 + 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' - ]; - 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; - }; - - // 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(';')); - } + 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() @@ -583,11 +438,19 @@ 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); } @@ -596,7 +459,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 @@ -604,7 +466,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -614,44 +476,14 @@ 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' + '}', 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 + 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.'); } - // to determine the Content-Type header - 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; - }; - - // 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(';')); - } + 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() @@ -659,11 +491,20 @@ export class PetService implements PetServiceInterface { headers.set('Authorization', 'Bearer ' + accessToken); } + // 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; + }; if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -672,7 +513,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 @@ -680,7 +520,7 @@ export class PetService implements PetServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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 bc30294b63a..7979fcedac2 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 @@ -84,7 +69,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) { @@ -99,7 +84,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) { @@ -115,7 +100,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) { @@ -131,7 +116,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) { @@ -148,33 +133,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -182,39 +150,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/${encodeURIComponent(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' - ]; - - 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"]); } - 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 @@ -222,7 +176,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); } /** @@ -230,33 +184,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -264,7 +201,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/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -272,27 +209,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -300,7 +222,6 @@ export class StoreService implements StoreServiceInterface { 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 @@ -308,7 +229,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 031f886731e..956a6cb3eb1 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 @@ -84,7 +69,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) { @@ -100,7 +85,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) { @@ -116,7 +101,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) { @@ -132,7 +117,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) { @@ -148,7 +133,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) { @@ -165,7 +150,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) { @@ -180,7 +165,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) { @@ -197,7 +182,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) { @@ -214,27 +199,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -242,7 +212,6 @@ export class UserService implements UserServiceInterface { 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 @@ -250,7 +219,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); } /** @@ -258,27 +227,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -286,7 +240,6 @@ export class UserService implements UserServiceInterface { 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 @@ -294,7 +247,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); } /** @@ -302,27 +255,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -330,7 +268,6 @@ export class UserService implements UserServiceInterface { 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 @@ -338,7 +275,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); } /** @@ -346,33 +283,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -380,7 +300,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -388,33 +308,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -422,7 +325,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -431,39 +334,23 @@ 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); } - if (password !== undefined) { queryParameters.set('password', password); } - - // 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(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -476,35 +363,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - 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 @@ -512,7 +384,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); } /** @@ -521,32 +393,15 @@ 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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -554,7 +409,6 @@ export class UserService implements UserServiceInterface { 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 @@ -562,7 +416,7 @@ export class UserService implements UserServiceInterface { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } } 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..9e7e00d1e48 --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/pet.service.ts @@ -0,0 +1,319 @@ +/** + * 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 { HttpClient, HttpHeaders, HttpParams } from '@angular/common/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 = new HttpHeaders(); + public configuration = new 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; + } + } + + /** + * @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; + } + + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPet(body: Pet): Observable<{}> { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling addPet.'); + } + + 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); + } + + return this.httpClient.post(`${this.basePath}/pet`, body, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + 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 = headers.set('api_key', String(apiKey)); + } + + // 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); + } + + return this.httpClient.delete(`${this.basePath}/pet/${encodeURIComponent(petId)}`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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 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 = queryParameters.set('status', status.join(COLLECTION_FORMATS['csv'])); + } + + 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); + } + + return this.httpClient.get(`${this.basePath}/pet/findByStatus`, { + params: queryParameters, + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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 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 = queryParameters.set('tags', tags.join(COLLECTION_FORMATS['csv'])); + } + + 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); + } + + return this.httpClient.get(`${this.basePath}/pet/findByTags`, { + params: queryParameters, + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Find pet by ID + * Returns a single pet + * @param petId ID of pet to return + */ + public getPetById(petId: number): Observable { + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling getPetById.'); + } + + let headers = this.defaultHeaders; + + // authentication (api_key) required + if (this.configuration.apiKeys["api_key"]) { + headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); + } + + return this.httpClient.get(`${this.basePath}/pet/${encodeURIComponent(petId)}`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet(body: Pet): Observable<{}> { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling updatePet.'); + } + + 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); + } + + return this.httpClient.put(`${this.basePath}/pet`, body, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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): Observable<{}> { + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); + } + + 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[] = [ + '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); + } + + return this.httpClient.post(`${this.basePath}/pet/${encodeURIComponent(petId)}`, formParams, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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): 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' + ]; + 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; + }; + if (additionalMetadata !== undefined) { + formParams.set('additionalMetadata', additionalMetadata); + } + if (file !== undefined) { + formParams.set('file', file); + } + + 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 new file mode 100644 index 00000000000..e52b46095ce --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/store.service.ts @@ -0,0 +1,133 @@ +/** + * 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 { HttpClient, HttpHeaders, HttpParams } from '@angular/common/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 = new HttpHeaders(); + public configuration = new 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; + } + } + + /** + * @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; + } + + + /** + * 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 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/${encodeURIComponent(orderId)}`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventory(): Observable<{ [key: string]: number; }> { + + let headers = this.defaultHeaders; + + // authentication (api_key) required + if (this.configuration.apiKeys["api_key"]) { + headers = headers.set('api_key', this.configuration.apiKeys["api_key"]); + } + + return this.httpClient.get(`${this.basePath}/store/inventory`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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 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/${encodeURIComponent(orderId)}`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder(body: Order): Observable { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling placeOrder.'); + } + + let headers = this.defaultHeaders; + + return this.httpClient.post(`${this.basePath}/store/order`, body, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + +} diff --git a/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts new file mode 100644 index 00000000000..cc53d7367bc --- /dev/null +++ b/samples/client/petstore/typescript-angular-v4.3/npm/api/user.service.ts @@ -0,0 +1,217 @@ +/** + * 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 { HttpClient, HttpHeaders, HttpParams } from '@angular/common/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 = new HttpHeaders(); + public configuration = new 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; + } + } + + /** + * @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; + } + + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUser(body: User): Observable<{}> { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUser.'); + } + + let headers = this.defaultHeaders; + + return this.httpClient.post(`${this.basePath}/user`, body, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInput(body: Array): Observable<{}> { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); + } + + let headers = this.defaultHeaders; + + return this.httpClient.post(`${this.basePath}/user/createWithArray`, body, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInput(body: Array): Observable<{}> { + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling createUsersWithListInput.'); + } + + let headers = this.defaultHeaders; + + return this.httpClient.post(`${this.basePath}/user/createWithList`, body, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + 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/${encodeURIComponent(username)}`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + 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/${encodeURIComponent(username)}`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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): Observable { + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling loginUser.'); + } + 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 = queryParameters.set('username', username); + } + if (password !== undefined) { + queryParameters = queryParameters.set('password', password); + } + + let headers = this.defaultHeaders; + + return this.httpClient.get(`${this.basePath}/user/login`, { + params: queryParameters, + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * Logs out current logged in user session + * + */ + public logoutUser(): Observable<{}> { + + let headers = this.defaultHeaders; + + return this.httpClient.get(`${this.basePath}/user/logout`, { + headers: headers, + withCredentials: this.configuration.withCredentials, + }); + } + + /** + * 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 updateUser(username: string, body: User): Observable<{}> { + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling updateUser.'); + } + if (body === null || body === undefined) { + throw new Error('Required parameter body was null or undefined when calling updateUser.'); + } + + let headers = this.defaultHeaders; + + 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.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/api/pet.service.ts b/samples/client/petstore/typescript-angular-v4/npm/api/pet.service.ts index f8265399f42..14993bde3d5 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 @@ -84,7 +69,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) { @@ -101,7 +86,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) { @@ -117,7 +102,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) { @@ -133,7 +118,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) { @@ -149,7 +134,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) { @@ -165,7 +150,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) { @@ -183,7 +168,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) { @@ -201,7 +186,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) { @@ -218,29 +203,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -248,14 +218,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 @@ -263,7 +231,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -272,34 +240,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' + '}', 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 + 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' - ]; - - 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() @@ -311,7 +262,6 @@ export class PetService { 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 @@ -319,7 +269,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -327,33 +277,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -361,7 +297,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -373,7 +308,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByStatus`, requestOptions); } /** @@ -381,33 +316,19 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -415,7 +336,6 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } - let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, @@ -427,7 +347,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/findByTags`, requestOptions); } /** @@ -435,38 +355,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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 @@ -474,7 +377,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -482,29 +385,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } + 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() @@ -512,14 +400,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 @@ -527,7 +413,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet`, requestOptions); } /** @@ -537,44 +423,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' + '}', 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 + 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' - ]; - 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; - }; - - // 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(';')); - } + 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() @@ -582,11 +438,19 @@ 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); } @@ -595,7 +459,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 @@ -603,7 +466,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/pet/${encodeURIComponent(petId)}`, requestOptions); } /** @@ -613,44 +476,14 @@ 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' + '}', 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 + 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.'); } - // to determine the Content-Type header - 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; - }; - - // 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(';')); - } + 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() @@ -658,11 +491,20 @@ export class PetService { headers.set('Authorization', 'Bearer ' + accessToken); } + // 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; + }; if (additionalMetadata !== undefined) { formParams.set('additionalMetadata', additionalMetadata); } - if (file !== undefined) { formParams.set('file', file); } @@ -671,7 +513,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 @@ -679,7 +520,7 @@ export class PetService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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 4f4189c369b..ece39b793e5 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 @@ -83,7 +68,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) { @@ -98,7 +83,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) { @@ -114,7 +99,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) { @@ -130,7 +115,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) { @@ -147,33 +132,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -181,39 +149,25 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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?: 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' - ]; - - 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"]); } - 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 @@ -221,7 +175,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/inventory`, requestOptions); } /** @@ -229,33 +183,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -263,7 +200,7 @@ export class StoreService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/store/order/${encodeURIComponent(orderId)}`, requestOptions); } /** @@ -271,27 +208,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -299,7 +221,6 @@ export class StoreService { 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 @@ -307,7 +228,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 f9cf1b9fb71..2e9b8eb9e17 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 @@ -83,7 +68,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) { @@ -99,7 +84,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) { @@ -115,7 +100,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) { @@ -131,7 +116,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) { @@ -147,7 +132,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) { @@ -164,7 +149,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) { @@ -179,7 +164,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) { @@ -196,7 +181,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) { @@ -213,27 +198,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -241,7 +211,6 @@ export class UserService { 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 @@ -249,7 +218,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user`, requestOptions); } /** @@ -257,27 +226,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -285,7 +239,6 @@ export class UserService { 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 @@ -293,7 +246,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithArray`, requestOptions); } /** @@ -301,27 +254,12 @@ 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -329,7 +267,6 @@ export class UserService { 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 @@ -337,7 +274,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/createWithList`, requestOptions); } /** @@ -345,33 +282,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -379,7 +299,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -387,33 +307,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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + 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 @@ -421,7 +324,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/${encodeURIComponent(username)}`, requestOptions); } /** @@ -430,39 +333,23 @@ 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); } - if (password !== undefined) { queryParameters.set('password', password); } - - // 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(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, @@ -475,35 +362,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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - - 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 @@ -511,7 +383,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, requestOptions); + return this.http.request(`${this.basePath}/user/logout`, requestOptions); } /** @@ -520,32 +392,15 @@ 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' + '}', 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 + 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' - ]; - - if (produces != null && produces.length > 0) { - headers.set('Accept', produces.filter(item => this.isJsonMime(item)).join(';')); - } - + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 headers.set('Content-Type', 'application/json'); @@ -553,7 +408,6 @@ export class UserService { 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 @@ -561,7 +415,7 @@ export class UserService { requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); } - return this.http.request(path, 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 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",