From e12b22d5ce59151d99000dcebb45a2d2be06f044 Mon Sep 17 00:00:00 2001 From: kirpit Date: Tue, 23 May 2017 23:40:21 +1000 Subject: [PATCH] Implement generating interfaces option for api resources, closes #5453. (#5519) * Implement generating interfaces option for api resources, closes swagger-api/swagger-codegen#5453. This commit introduces another _system property_ for typescript-angular2, called `withInterfaces` that is default to `false`. You can activate this flag by: ``` java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \ -i http://petstore.swagger.io/v2/swagger.json \ -l typescript-angular2 -o samples/server/petstore/springboot/typescript-angular2 \ -D withInterfaces=true ``` If set to `true`, generated api resource classes will be implemented with their interfaces in separate files. This change should not break and change the behaviour even though `withInterfaces` flag set to `true`. You are also welcome to create your own custom resource class by implementing those generated interfaces as they support defining new attributes with `[others: string]: any;` signature. * Fix unit test for typescript/angular2 client options for "withInterfaces" * Use double quote to follow coding standard * Respect interface naming convention for typescript/angular2 Create respectful interface names that ends with `Interface` suffix, instead of prefixing with `I` according to typescript naming convention. This is also consistent with their file names that also ends with `Interface.ts`. Also fixes the merge conflicts. * Have better explanation for the `withInterfaces` system config --- bin/typescript-angular2-petstore-all.sh | 4 + ...typescript-angular2-petstore-interfaces.sh | 31 + .../TypeScriptAngular2ClientCodegen.java | 9 + .../typescript-angular2/api.mustache | 9 + .../typescript-angular2/apiInterface.mustache | 31 + ...peScriptAngular2ClientOptionsProvider.java | 1 + .../with-interfaces/.gitignore | 4 + .../with-interfaces/.swagger-codegen-ignore | 23 + .../with-interfaces/api/PetApi.ts | 605 ++++++++++++++++++ .../with-interfaces/api/PetApiInterface.ts | 87 +++ .../with-interfaces/api/StoreApi.ts | 262 ++++++++ .../with-interfaces/api/StoreApiInterface.ts | 53 ++ .../with-interfaces/api/UserApi.ts | 483 ++++++++++++++ .../with-interfaces/api/UserApiInterface.ts | 83 +++ .../with-interfaces/api/api.ts | 7 + .../with-interfaces/configuration.ts | 7 + .../with-interfaces/git_push.sh | 52 ++ .../with-interfaces/index.ts | 4 + .../with-interfaces/model/Category.ts | 20 + .../with-interfaces/model/Order.ts | 38 ++ .../with-interfaces/model/Pet.ts | 38 ++ .../with-interfaces/model/Tag.ts | 20 + .../with-interfaces/model/User.ts | 35 + .../with-interfaces/model/models.ts | 5 + .../with-interfaces/variables.ts | 9 + 25 files changed, 1920 insertions(+) create mode 100755 bin/typescript-angular2-petstore-interfaces.sh create mode 100644 modules/swagger-codegen/src/main/resources/typescript-angular2/apiInterface.mustache create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/.gitignore create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/.swagger-codegen-ignore create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/PetApiInterface.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApiInterface.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/UserApiInterface.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/api/api.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/configuration.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/git_push.sh create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/index.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/model/Category.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/model/Order.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/model/Pet.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/model/Tag.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/model/User.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/model/models.ts create mode 100644 samples/client/petstore/typescript-angular2/with-interfaces/variables.ts diff --git a/bin/typescript-angular2-petstore-all.sh b/bin/typescript-angular2-petstore-all.sh index 4932e26bda4..0a4ee7080d5 100755 --- a/bin/typescript-angular2-petstore-all.sh +++ b/bin/typescript-angular2-petstore-all.sh @@ -34,3 +34,7 @@ java $JAVA_OPTS -jar $executable $ags echo "Typescript Petstore API client (npm setting)" ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.yaml -l typescript-angular2 -c bin/typescript-petstore-npm.json -o samples/client/petstore/typescript-angular2/npm" java $JAVA_OPTS -jar $executable $ags + +echo "Typescript Petstore API client (with interfaces generated)" +ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l typescript-angular2 -o samples/client/petstore/typescript-angular2/with-interfaces -D withInterfaces=true" +java $JAVA_OPTS -jar $executable $ags diff --git a/bin/typescript-angular2-petstore-interfaces.sh b/bin/typescript-angular2-petstore-interfaces.sh new file mode 100755 index 00000000000..12b3228a619 --- /dev/null +++ b/bin/typescript-angular2-petstore-interfaces.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.json -l typescript-angular2 -o samples/client/petstore/typescript-angular2/with-interfaces -D withInterfaces=true" + +java $JAVA_OPTS -jar $executable $ags diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java index 78413f94b78..afcf3bdaadc 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/TypeScriptAngular2ClientCodegen.java @@ -28,6 +28,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod public static final String SNAPSHOT = "snapshot"; public static final String USE_OPAQUE_TOKEN = "useOpaqueToken"; public static final String INJECTION_TOKEN = "injectionToken"; + public static final String WITH_INTERFACES = "withInterfaces"; protected String npmName = null; protected String npmVersion = "1.0.0"; @@ -51,6 +52,7 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod 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(USE_OPAQUE_TOKEN, "When setting this property to true, OpaqueToken is used instead of InjectionToken", 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())); } @Override @@ -88,6 +90,13 @@ public class TypeScriptAngular2ClientCodegen extends AbstractTypeScriptClientCod this.setOpaqueToken(); } additionalProperties.put(INJECTION_TOKEN, this.injectionToken); + + if(additionalProperties.containsKey(WITH_INTERFACES)) { + boolean withInterfaces = Boolean.parseBoolean(additionalProperties.get(WITH_INTERFACES).toString()); + if (withInterfaces) { + apiTemplateFiles.put("apiInterface.mustache", "Interface.ts"); + } + } } private void addNpmPackageGeneration() { diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache index b132afff8be..76682a0b9e9 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -10,6 +10,9 @@ import 'rxjs/add/operator/map'; import * as models from '../model/models'; import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; import { Configuration } from '../configuration'; +{{#withInterfaces}} +import { {{classname}}Interface } from './{{classname}}Interface'; +{{/withInterfaces}} /* tslint:disable:no-unused-variable member-ordering */ @@ -21,7 +24,13 @@ import { Configuration } from '../configurat */ {{/description}} @Injectable() +{{#withInterfaces}} +export class {{classname}} implements {{classname}}Interface { +{{/withInterfaces}} +{{^withInterfaces}} export class {{classname}} { +{{/withInterfaces}} + protected basePath = '{{{basePath}}}'; public defaultHeaders: Headers = new Headers(); public configuration: Configuration = new Configuration(); diff --git a/modules/swagger-codegen/src/main/resources/typescript-angular2/apiInterface.mustache b/modules/swagger-codegen/src/main/resources/typescript-angular2/apiInterface.mustache new file mode 100644 index 00000000000..1acd887ce5d --- /dev/null +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/apiInterface.mustache @@ -0,0 +1,31 @@ +{{>licenseInfo}} +import { Headers } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; + +import * as models from '../model/models'; +import { Configuration } from '../configuration'; + +{{#operations}} + +{{#description}} + /** + * {{&description}} + */ +{{/description}} +export interface {{classname}}Interface { + defaultHeaders: Headers; + configuration: Configuration; + [others: string]: any; + +{{#operation}} + /** + * {{summary}} + * {{notes}} + {{#allParams}}* @param {{paramName}} {{description}} + {{/allParams}}*/ + {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}extraHttpRequestParams?: any): Observable<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}{}{{/returnType}}>; + +{{/operation}} +} +{{/operations}} diff --git a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java index d8abde864ba..f7d430c1f4c 100644 --- a/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java +++ b/modules/swagger-codegen/src/test/java/io/swagger/codegen/options/TypeScriptAngular2ClientOptionsProvider.java @@ -33,6 +33,7 @@ public class TypeScriptAngular2ClientOptionsProvider implements OptionsProvider .put(TypeScriptAngular2ClientCodegen.NPM_NAME, NMP_NAME) .put(TypeScriptAngular2ClientCodegen.NPM_VERSION, NMP_VERSION) .put(TypeScriptAngular2ClientCodegen.SNAPSHOT, Boolean.FALSE.toString()) + .put(TypeScriptAngular2ClientCodegen.WITH_INTERFACES, Boolean.FALSE.toString()) .put(TypeScriptAngular2ClientCodegen.NPM_REPOSITORY, NPM_REPOSITORY) .put(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, ALLOW_UNICODE_IDENTIFIERS_VALUE) .put(TypeScriptAngular2ClientCodegen.USE_OPAQUE_TOKEN, Boolean.FALSE.toString()) diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/.gitignore b/samples/client/petstore/typescript-angular2/with-interfaces/.gitignore new file mode 100644 index 00000000000..149b5765472 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/.gitignore @@ -0,0 +1,4 @@ +wwwroot/*.js +node_modules +typings +dist diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/.swagger-codegen-ignore b/samples/client/petstore/typescript-angular2/with-interfaces/.swagger-codegen-ignore new file mode 100644 index 00000000000..c5fa491b4c5 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/.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-angular2/with-interfaces/api/PetApi.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts new file mode 100644 index 00000000000..77197bdbc06 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApi.ts @@ -0,0 +1,605 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 { Inject, Injectable, Optional } from '@angular/core'; +import { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; + +import * as models from '../model/models'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { PetApiInterface } from './PetApiInterface'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +@Injectable() +export class PetApi implements PetApiInterface { + + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPet(body?: models.Pet, extraHttpRequestParams?: any): Observable<{}> { + return this.addPetWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + public deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}> { + return this.deletePetWithHttpInfo(petId, apiKey, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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, extraHttpRequestParams?: any): Observable> { + return this.findPetsByStatusWithHttpInfo(status, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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, extraHttpRequestParams?: any): Observable> { + return this.findPetsByTagsWithHttpInfo(tags, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + */ + public getPetById(petId: number, extraHttpRequestParams?: any): Observable { + return this.getPetByIdWithHttpInfo(petId, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePet(body?: models.Pet, extraHttpRequestParams?: any): Observable<{}> { + return this.updatePetWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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: string, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}> { + return this.updatePetWithFormWithHttpInfo(petId, name, status, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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?: any, extraHttpRequestParams?: any): Observable<{}> { + return this.uploadFileWithHttpInfo(petId, additionalMetadata, file, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + public addPetWithHttpInfo(body?: models.Pet, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + 'application/xml' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + public deletePetWithHttpInfo(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling deletePet.'); + } + headers.set('api_key', String(apiKey)); + + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma separated strings + * @param status Status values that need to be considered for filter + */ + public findPetsByStatusWithHttpInfo(status?: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/findByStatus'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (status) { + status.forEach((element) => { + queryParameters.append('status', element); + }) + } + + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * @param tags Tags to filter by + */ + public findPetsByTagsWithHttpInfo(tags?: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/findByTags'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (tags) { + tags.forEach((element) => { + queryParameters.append('tags', element); + }) + } + + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + */ + public getPetByIdWithHttpInfo(petId: number, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling getPetById.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (api_key) required + if (this.configuration.apiKey) { + headers.set('api_key', this.configuration.apiKey); + } + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + public updatePetWithHttpInfo(body?: models.Pet, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + 'application/json', + 'application/xml' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Updates a pet in the store with form data + * + * @param petId ID of pet that needs to be updated + * @param name Updated name of the pet + * @param status Updated status of the pet + */ + public updatePetWithFormWithHttpInfo(petId: string, name?: string, status?: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let formParams = new URLSearchParams(); + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling updatePetWithForm.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + 'application/x-www-form-urlencoded' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + headers.set('Content-Type', 'application/x-www-form-urlencoded'); + + if (name !== undefined) { + formParams.set('name', name); + } + + if (status !== undefined) { + formParams.set('status', status); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + public uploadFileWithHttpInfo(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/pet/${petId}/uploadImage' + .replace('${' + 'petId' + '}', String(petId)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + let formParams = new URLSearchParams(); + + // verify required parameter 'petId' is not null or undefined + if (petId === null || petId === undefined) { + throw new Error('Required parameter petId was null or undefined when calling uploadFile.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + 'multipart/form-data' + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (petstore_auth) required + // oauth required + if (this.configuration.accessToken) { + let accessToken = typeof this.configuration.accessToken === 'function' + ? this.configuration.accessToken() + : this.configuration.accessToken; + headers.set('Authorization', 'Bearer ' + accessToken); + } + + headers.set('Content-Type', 'application/x-www-form-urlencoded'); + + if (additionalMetadata !== undefined) { + formParams.set('additionalMetadata', additionalMetadata); + } + + if (file !== undefined) { + formParams.set('file', file); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: formParams.toString(), + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApiInterface.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApiInterface.ts new file mode 100644 index 00000000000..d41a6388274 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/PetApiInterface.ts @@ -0,0 +1,87 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 { Headers } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; + +import * as models from '../model/models'; +import { Configuration } from '../configuration'; + + +export interface PetApiInterface { + defaultHeaders: Headers; + configuration: Configuration; + [others: string]: any; + + /** + * Add a new pet to the store + * + * @param body Pet object that needs to be added to the store + */ + addPet(body?: models.Pet, extraHttpRequestParams?: any): Observable<{}>; + + /** + * Deletes a pet + * + * @param petId Pet id to delete + * @param apiKey + */ + deletePet(petId: number, apiKey?: string, extraHttpRequestParams?: any): Observable<{}>; + + /** + * 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 + */ + findPetsByStatus(status?: Array, extraHttpRequestParams?: any): Observable>; + + /** + * 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 + */ + findPetsByTags(tags?: Array, extraHttpRequestParams?: any): Observable>; + + /** + * Find pet by ID + * Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + * @param petId ID of pet that needs to be fetched + */ + getPetById(petId: number, extraHttpRequestParams?: any): Observable; + + /** + * Update an existing pet + * + * @param body Pet object that needs to be added to the store + */ + updatePet(body?: models.Pet, extraHttpRequestParams?: any): Observable<{}>; + + /** + * 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 + */ + updatePetWithForm(petId: string, name?: string, status?: string, extraHttpRequestParams?: any): Observable<{}>; + + /** + * uploads an image + * + * @param petId ID of pet to update + * @param additionalMetadata Additional data to pass to server + * @param file file to upload + */ + uploadFile(petId: number, additionalMetadata?: string, file?: any, extraHttpRequestParams?: any): Observable<{}>; + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts new file mode 100644 index 00000000000..ecc6cb80eae --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApi.ts @@ -0,0 +1,262 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 { Inject, Injectable, Optional } from '@angular/core'; +import { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; + +import * as models from '../model/models'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { StoreApiInterface } from './StoreApiInterface'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +@Injectable() +export class StoreApi implements StoreApiInterface { + + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + /** + * 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, extraHttpRequestParams?: any): Observable<{}> { + return this.deleteOrderWithHttpInfo(orderId, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }> { + return this.getInventoryWithHttpInfo(extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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: string, extraHttpRequestParams?: any): Observable { + return this.getOrderByIdWithHttpInfo(orderId, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrder(body?: models.Order, extraHttpRequestParams?: any): Observable { + return this.placeOrderWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * Delete purchase order by ID + * For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + * @param orderId ID of the order that needs to be deleted + */ + public deleteOrderWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/order/${orderId}' + .replace('${' + 'orderId' + '}', String(orderId)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling deleteOrder.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + public getInventoryWithHttpInfo(extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/inventory'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + // authentication (api_key) required + if (this.configuration.apiKey) { + headers.set('api_key', this.configuration.apiKey); + } + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Find purchase order by ID + * For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + * @param orderId ID of pet that needs to be fetched + */ + public getOrderByIdWithHttpInfo(orderId: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/order/${orderId}' + .replace('${' + 'orderId' + '}', String(orderId)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'orderId' is not null or undefined + if (orderId === null || orderId === undefined) { + throw new Error('Required parameter orderId was null or undefined when calling getOrderById.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + public placeOrderWithHttpInfo(body?: models.Order, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/store/order'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApiInterface.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApiInterface.ts new file mode 100644 index 00000000000..e8fe0eb9a82 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/StoreApiInterface.ts @@ -0,0 +1,53 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 { Headers } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; + +import * as models from '../model/models'; +import { Configuration } from '../configuration'; + + +export interface StoreApiInterface { + defaultHeaders: Headers; + configuration: Configuration; + [others: string]: any; + + /** + * 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 + */ + deleteOrder(orderId: string, extraHttpRequestParams?: any): Observable<{}>; + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + */ + getInventory(extraHttpRequestParams?: any): Observable<{ [key: string]: number; }>; + + /** + * 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 + */ + getOrderById(orderId: string, extraHttpRequestParams?: any): Observable; + + /** + * Place an order for a pet + * + * @param body order placed for purchasing the pet + */ + placeOrder(body?: models.Order, extraHttpRequestParams?: any): Observable; + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts new file mode 100644 index 00000000000..dfd8ac54d7a --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApi.ts @@ -0,0 +1,483 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 { Inject, Injectable, Optional } from '@angular/core'; +import { Http, Headers, URLSearchParams } from '@angular/http'; +import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http'; +import { Response, ResponseContentType } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/map'; + +import * as models from '../model/models'; +import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; +import { Configuration } from '../configuration'; +import { UserApiInterface } from './UserApiInterface'; + +/* tslint:disable:no-unused-variable member-ordering */ + + +@Injectable() +export class UserApi implements UserApiInterface { + + protected basePath = 'http://petstore.swagger.io/v2'; + public defaultHeaders: Headers = new Headers(); + public configuration: Configuration = new Configuration(); + + constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) { + if (basePath) { + this.basePath = basePath; + } + if (configuration) { + this.configuration = configuration; + } + } + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUser(body?: models.User, extraHttpRequestParams?: any): Observable<{}> { + return this.createUserWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInput(body?: Array, extraHttpRequestParams?: any): Observable<{}> { + return this.createUsersWithArrayInputWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInput(body?: Array, extraHttpRequestParams?: any): Observable<{}> { + return this.createUsersWithListInputWithHttpInfo(body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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, extraHttpRequestParams?: any): Observable<{}> { + return this.deleteUserWithHttpInfo(username, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByName(username: string, extraHttpRequestParams?: any): Observable { + return this.getUserByNameWithHttpInfo(username, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUser(username?: string, password?: string, extraHttpRequestParams?: any): Observable { + return this.loginUserWithHttpInfo(username, password, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * Logs out current logged in user session + * + */ + public logoutUser(extraHttpRequestParams?: any): Observable<{}> { + return this.logoutUserWithHttpInfo(extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + /** + * 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?: models.User, extraHttpRequestParams?: any): Observable<{}> { + return this.updateUserWithHttpInfo(username, body, extraHttpRequestParams) + .map((response: Response) => { + if (response.status === 204) { + return undefined; + } else { + return response.json() || {}; + } + }); + } + + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + public createUserWithHttpInfo(body?: models.User, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithArrayInputWithHttpInfo(body?: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/createWithArray'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + public createUsersWithListInputWithHttpInfo(body?: Array, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/createWithList'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Post, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + public deleteUserWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/${username}' + .replace('${' + 'username' + '}', String(username)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling deleteUser.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Delete, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + public getUserByNameWithHttpInfo(username: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/${username}' + .replace('${' + 'username' + '}', String(username)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling getUserByName.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + public loginUserWithHttpInfo(username?: string, password?: string, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/login'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + if (username !== undefined) { + queryParameters.set('username', username); + } + + if (password !== undefined) { + queryParameters.set('password', password); + } + + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Logs out current logged in user session + * + */ + public logoutUserWithHttpInfo(extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/logout'; + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Get, + headers: headers, + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + + /** + * Updated user + * This can only be done by the logged in user. + * @param username name that need to be deleted + * @param body Updated user object + */ + public updateUserWithHttpInfo(username: string, body?: models.User, extraHttpRequestParams?: any): Observable { + const path = this.basePath + '/user/${username}' + .replace('${' + 'username' + '}', String(username)); + + let queryParameters = new URLSearchParams(); + let headers = new Headers(this.defaultHeaders.toJSON()); // https://github.com/angular/angular/issues/6845 + // verify required parameter 'username' is not null or undefined + if (username === null || username === undefined) { + throw new Error('Required parameter username was null or undefined when calling updateUser.'); + } + // to determine the Content-Type header + let consumes: string[] = [ + ]; + + // to determine the Accept header + let produces: string[] = [ + 'application/json', + 'application/xml' + ]; + + headers.set('Content-Type', 'application/json'); + + let requestOptions: RequestOptionsArgs = new RequestOptions({ + method: RequestMethod.Put, + headers: headers, + body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 + search: queryParameters, + withCredentials:this.configuration.withCredentials + }); + // https://github.com/swagger-api/swagger-codegen/issues/4037 + if (extraHttpRequestParams) { + requestOptions = (Object).assign(requestOptions, extraHttpRequestParams); + } + + return this.http.request(path, requestOptions); + } + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApiInterface.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApiInterface.ts new file mode 100644 index 00000000000..c882866c1c1 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/UserApiInterface.ts @@ -0,0 +1,83 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 { Headers } from '@angular/http'; + +import { Observable } from 'rxjs/Observable'; + +import * as models from '../model/models'; +import { Configuration } from '../configuration'; + + +export interface UserApiInterface { + defaultHeaders: Headers; + configuration: Configuration; + [others: string]: any; + + /** + * Create user + * This can only be done by the logged in user. + * @param body Created user object + */ + createUser(body?: models.User, extraHttpRequestParams?: any): Observable<{}>; + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + createUsersWithArrayInput(body?: Array, extraHttpRequestParams?: any): Observable<{}>; + + /** + * Creates list of users with given input array + * + * @param body List of user object + */ + createUsersWithListInput(body?: Array, extraHttpRequestParams?: any): Observable<{}>; + + /** + * Delete user + * This can only be done by the logged in user. + * @param username The name that needs to be deleted + */ + deleteUser(username: string, extraHttpRequestParams?: any): Observable<{}>; + + /** + * Get user by user name + * + * @param username The name that needs to be fetched. Use user1 for testing. + */ + getUserByName(username: string, extraHttpRequestParams?: any): Observable; + + /** + * Logs user into the system + * + * @param username The user name for login + * @param password The password for login in clear text + */ + loginUser(username?: string, password?: string, extraHttpRequestParams?: any): Observable; + + /** + * Logs out current logged in user session + * + */ + logoutUser(extraHttpRequestParams?: any): Observable<{}>; + + /** + * 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 + */ + updateUser(username: string, body?: models.User, extraHttpRequestParams?: any): Observable<{}>; + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/api/api.ts b/samples/client/petstore/typescript-angular2/with-interfaces/api/api.ts new file mode 100644 index 00000000000..4ddd9e29663 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/api/api.ts @@ -0,0 +1,7 @@ +export * from './PetApi'; +import { PetApi } from './PetApi'; +export * from './StoreApi'; +import { StoreApi } from './StoreApi'; +export * from './UserApi'; +import { UserApi } from './UserApi'; +export const APIS = [PetApi, StoreApi, UserApi]; diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/configuration.ts b/samples/client/petstore/typescript-angular2/with-interfaces/configuration.ts new file mode 100644 index 00000000000..c94aa4cbce9 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/configuration.ts @@ -0,0 +1,7 @@ +export class Configuration { + apiKey: string; + username: string; + password: string; + accessToken: string | (() => string); + withCredentials: boolean; +} \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/git_push.sh b/samples/client/petstore/typescript-angular2/with-interfaces/git_push.sh new file mode 100644 index 00000000000..ed374619b13 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/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-angular2/with-interfaces/index.ts b/samples/client/petstore/typescript-angular2/with-interfaces/index.ts new file mode 100644 index 00000000000..d097c728017 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/index.ts @@ -0,0 +1,4 @@ +export * from './api/api'; +export * from './model/models'; +export * from './variables'; +export * from './configuration'; \ No newline at end of file diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/model/Category.ts b/samples/client/petstore/typescript-angular2/with-interfaces/model/Category.ts new file mode 100644 index 00000000000..ffdacd4f707 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/model/Category.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 * as models from './models'; + +export interface Category { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/model/Order.ts b/samples/client/petstore/typescript-angular2/with-interfaces/model/Order.ts new file mode 100644 index 00000000000..9c47071c5b6 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/model/Order.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 or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 * as models from './models'; + +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-angular2/with-interfaces/model/Pet.ts b/samples/client/petstore/typescript-angular2/with-interfaces/model/Pet.ts new file mode 100644 index 00000000000..d64dc809e53 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/model/Pet.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 or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 * as models from './models'; + +export interface Pet { + id?: number; + + category?: models.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-angular2/with-interfaces/model/Tag.ts b/samples/client/petstore/typescript-angular2/with-interfaces/model/Tag.ts new file mode 100644 index 00000000000..8a3b99ae9ca --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/model/Tag.ts @@ -0,0 +1,20 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 * as models from './models'; + +export interface Tag { + id?: number; + + name?: string; + +} diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/model/User.ts b/samples/client/petstore/typescript-angular2/with-interfaces/model/User.ts new file mode 100644 index 00000000000..43d00f7b318 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/model/User.ts @@ -0,0 +1,35 @@ +/** + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at http://swagger.io or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters + * + * OpenAPI spec version: 1.0.0 + * Contact: apiteam@wordnik.com + * + * 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 * as models from './models'; + +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-angular2/with-interfaces/model/models.ts b/samples/client/petstore/typescript-angular2/with-interfaces/model/models.ts new file mode 100644 index 00000000000..92dac02846c --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/model/models.ts @@ -0,0 +1,5 @@ +export * from './Category'; +export * from './Order'; +export * from './Pet'; +export * from './Tag'; +export * from './User'; diff --git a/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts b/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts new file mode 100644 index 00000000000..944e688f1b1 --- /dev/null +++ b/samples/client/petstore/typescript-angular2/with-interfaces/variables.ts @@ -0,0 +1,9 @@ +import { OpaqueToken } from '@angular/core'; + +export const BASE_PATH = new OpaqueToken('basePath'); +export const COLLECTION_FORMATS = { + 'csv': ',', + 'tsv': ' ', + 'ssv': ' ', + 'pipes': '|' +} \ No newline at end of file