diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java index b7751912c7a..6906f94a094 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptClientCodegen.java @@ -120,10 +120,12 @@ public class TypeScriptClientCodegen extends DefaultCodegen implements CodegenCo cliOptions.add(new CliOption(CodegenConstants.SUPPORTS_ES6, CodegenConstants.SUPPORTS_ES6_DESC).defaultValue("false")); // TODO: gen package.json? - //Files for building our lib + //Documentation supportingFiles.add(new SupportingFile("README.mustache", "", "README.md")); supportingFiles.add(new SupportingFile("package.mustache", "", "package.json")); supportingFiles.add(new SupportingFile("tsconfig.mustache", "", "tsconfig.json")); + supportingFiles.add(new SupportingFile(".gitignore.mustache", "", ".gitignore")); + supportingFiles.add(new SupportingFile("git_push.sh.mustache", "", "git_push.sh")); // Util supportingFiles.add(new SupportingFile("util.mustache", "", "util.ts")); diff --git a/modules/openapi-generator/src/main/resources/typescript/.gitignore.mustache b/modules/openapi-generator/src/main/resources/typescript/.gitignore.mustache new file mode 100644 index 00000000000..1521c8b7652 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript/.gitignore.mustache @@ -0,0 +1 @@ +dist diff --git a/modules/openapi-generator/src/main/resources/typescript/git_push.sh.mustache b/modules/openapi-generator/src/main/resources/typescript/git_push.sh.mustache new file mode 100755 index 00000000000..8a32e53995d --- /dev/null +++ b/modules/openapi-generator/src/main/resources/typescript/git_push.sh.mustache @@ -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 openapi-pestore-perl "minor update" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 + +if [ "$git_user_id" = "" ]; then + git_user_id="{{{gitUserId}}}" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="{{{gitRepoId}}}" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="{{{releaseNote}}}" + 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 credential 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/builds/default/apis/PetApi.ts b/samples/client/petstore/typescript/builds/default/apis/PetApi.ts index f23e9a96426..83904063a7d 100644 --- a/samples/client/petstore/typescript/builds/default/apis/PetApi.ts +++ b/samples/client/petstore/typescript/builds/default/apis/PetApi.ts @@ -17,14 +17,14 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory { /** * Add a new pet to the store - * @param pet Pet object that needs to be added to the store + * @param body Pet object that needs to be added to the store */ - public addPet(pet: Pet, options?: Configuration): RequestContext { + public addPet(body: Pet, options?: Configuration): RequestContext { let config = options || this.configuration; - // verify required parameter 'pet' is not null or undefined - if (pet === null || pet === undefined) { - throw new RequiredError('Required parameter pet was null or undefined when calling addPet.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling addPet.'); } @@ -46,7 +46,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(pet || {}) : (pet.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); let authMethod = null; @@ -231,14 +231,14 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory { /** * Update an existing pet - * @param pet Pet object that needs to be added to the store + * @param body Pet object that needs to be added to the store */ - public updatePet(pet: Pet, options?: Configuration): RequestContext { + public updatePet(body: Pet, options?: Configuration): RequestContext { let config = options || this.configuration; - // verify required parameter 'pet' is not null or undefined - if (pet === null || pet === undefined) { - throw new RequiredError('Required parameter pet was null or undefined when calling updatePet.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling updatePet.'); } @@ -260,7 +260,7 @@ export class PetApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("Pet" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(pet || {}) : (pet.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); let authMethod = null; diff --git a/samples/client/petstore/typescript/builds/default/apis/StoreApi.ts b/samples/client/petstore/typescript/builds/default/apis/StoreApi.ts index 9eac5d5d939..55769fdc249 100644 --- a/samples/client/petstore/typescript/builds/default/apis/StoreApi.ts +++ b/samples/client/petstore/typescript/builds/default/apis/StoreApi.ts @@ -121,14 +121,14 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory { /** * Place an order for a pet - * @param order order placed for purchasing the pet + * @param body order placed for purchasing the pet */ - public placeOrder(order: Order, options?: Configuration): RequestContext { + public placeOrder(body: Order, options?: Configuration): RequestContext { let config = options || this.configuration; - // verify required parameter 'order' is not null or undefined - if (order === null || order === undefined) { - throw new RequiredError('Required parameter order was null or undefined when calling placeOrder.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling placeOrder.'); } @@ -150,7 +150,7 @@ export class StoreApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("Order" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(order || {}) : (order.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); // Apply auth methods diff --git a/samples/client/petstore/typescript/builds/default/apis/UserApi.ts b/samples/client/petstore/typescript/builds/default/apis/UserApi.ts index e0b7317d69a..b3040726a8f 100644 --- a/samples/client/petstore/typescript/builds/default/apis/UserApi.ts +++ b/samples/client/petstore/typescript/builds/default/apis/UserApi.ts @@ -17,14 +17,14 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { /** * This can only be done by the logged in user. * Create user - * @param user Created user object + * @param body Created user object */ - public createUser(user: User, options?: Configuration): RequestContext { + public createUser(body: User, options?: Configuration): RequestContext { let config = options || this.configuration; - // verify required parameter 'user' is not null or undefined - if (user === null || user === undefined) { - throw new RequiredError('Required parameter user was null or undefined when calling createUser.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling createUser.'); } @@ -46,7 +46,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(user || {}) : (user.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); // Apply auth methods @@ -56,14 +56,14 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { /** * Creates list of users with given input array - * @param user List of user object + * @param body List of user object */ - public createUsersWithArrayInput(user: Array, options?: Configuration): RequestContext { + public createUsersWithArrayInput(body: Array, options?: Configuration): RequestContext { let config = options || this.configuration; - // verify required parameter 'user' is not null or undefined - if (user === null || user === undefined) { - throw new RequiredError('Required parameter user was null or undefined when calling createUsersWithArrayInput.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling createUsersWithArrayInput.'); } @@ -85,7 +85,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("Array<User>" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(user || {}) : (user.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); // Apply auth methods @@ -95,14 +95,14 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { /** * Creates list of users with given input array - * @param user List of user object + * @param body List of user object */ - public createUsersWithListInput(user: Array, options?: Configuration): RequestContext { + public createUsersWithListInput(body: Array, options?: Configuration): RequestContext { let config = options || this.configuration; - // verify required parameter 'user' is not null or undefined - if (user === null || user === undefined) { - throw new RequiredError('Required parameter user was null or undefined when calling createUsersWithListInput.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling createUsersWithListInput.'); } @@ -124,7 +124,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("Array<User>" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(user || {}) : (user.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); // Apply auth methods @@ -281,9 +281,9 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { * This can only be done by the logged in user. * Updated user * @param username name that need to be deleted - * @param user Updated user object + * @param body Updated user object */ - public updateUser(username: string, user: User, options?: Configuration): RequestContext { + public updateUser(username: string, body: User, options?: Configuration): RequestContext { let config = options || this.configuration; // verify required parameter 'username' is not null or undefined @@ -292,9 +292,9 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { } - // verify required parameter 'user' is not null or undefined - if (user === null || user === undefined) { - throw new RequiredError('Required parameter user was null or undefined when calling updateUser.'); + // verify required parameter 'body' is not null or undefined + if (body === null || body === undefined) { + throw new RequiredError('Required parameter body was null or undefined when calling updateUser.'); } @@ -317,7 +317,7 @@ export class UserApiRequestFactory extends BaseAPIRequestFactory { requestContext.setHeaderParam("Content-Type", "application/json"); // TODO: Should this be handled by ObjectSerializer? imo yes => confidential information included in local object should not be sent const needsSerialization = ("User" !== "string") || requestContext.getHeaders()['Content-Type'] === 'application/json'; - const serializedBody = needsSerialization ? JSON.stringify(user || {}) : (user.toString() || ""); // TODO: `toString` call is unnecessary + const serializedBody = needsSerialization ? JSON.stringify(body || {}) : (body.toString() || ""); // TODO: `toString` call is unnecessary requestContext.setBody(serializedBody); // Apply auth methods diff --git a/samples/client/petstore/typescript/builds/default/git_push.sh b/samples/client/petstore/typescript/builds/default/git_push.sh new file mode 100644 index 00000000000..8442b80bb44 --- /dev/null +++ b/samples/client/petstore/typescript/builds/default/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 openapi-pestore-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 credential 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/builds/default/types/ObservableAPI.ts b/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts index f005b321a37..079853bb913 100644 --- a/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts +++ b/samples/client/petstore/typescript/builds/default/types/ObservableAPI.ts @@ -25,10 +25,10 @@ export class ObservablePetApi { /** * Add a new pet to the store - * @param pet Pet object that needs to be added to the store + * @param body Pet object that needs to be added to the store */ - public addPet(pet: Pet, options?: Configuration): Observable { - const requestContext = this.requestFactory.addPet(pet, options); + public addPet(body: Pet, options?: Configuration): Observable { + const requestContext = this.requestFactory.addPet(body, options); // build promise chain let middlewarePreObservable = of(requestContext); @@ -144,10 +144,10 @@ export class ObservablePetApi { /** * Update an existing pet - * @param pet Pet object that needs to be added to the store + * @param body Pet object that needs to be added to the store */ - public updatePet(pet: Pet, options?: Configuration): Observable { - const requestContext = this.requestFactory.updatePet(pet, options); + public updatePet(body: Pet, options?: Configuration): Observable { + const requestContext = this.requestFactory.updatePet(body, options); // build promise chain let middlewarePreObservable = of(requestContext); @@ -306,10 +306,10 @@ export class ObservableStoreApi { /** * Place an order for a pet - * @param order order placed for purchasing the pet + * @param body order placed for purchasing the pet */ - public placeOrder(order: Order, options?: Configuration): Observable { - const requestContext = this.requestFactory.placeOrder(order, options); + public placeOrder(body: Order, options?: Configuration): Observable { + const requestContext = this.requestFactory.placeOrder(body, options); // build promise chain let middlewarePreObservable = of(requestContext); @@ -348,10 +348,10 @@ export class ObservableUserApi { /** * This can only be done by the logged in user. * Create user - * @param user Created user object + * @param body Created user object */ - public createUser(user: User, options?: Configuration): Observable { - const requestContext = this.requestFactory.createUser(user, options); + public createUser(body: User, options?: Configuration): Observable { + const requestContext = this.requestFactory.createUser(body, options); // build promise chain let middlewarePreObservable = of(requestContext); @@ -371,10 +371,10 @@ export class ObservableUserApi { /** * Creates list of users with given input array - * @param user List of user object + * @param body List of user object */ - public createUsersWithArrayInput(user: Array, options?: Configuration): Observable { - const requestContext = this.requestFactory.createUsersWithArrayInput(user, options); + public createUsersWithArrayInput(body: Array, options?: Configuration): Observable { + const requestContext = this.requestFactory.createUsersWithArrayInput(body, options); // build promise chain let middlewarePreObservable = of(requestContext); @@ -394,10 +394,10 @@ export class ObservableUserApi { /** * Creates list of users with given input array - * @param user List of user object + * @param body List of user object */ - public createUsersWithListInput(user: Array, options?: Configuration): Observable { - const requestContext = this.requestFactory.createUsersWithListInput(user, options); + public createUsersWithListInput(body: Array, options?: Configuration): Observable { + const requestContext = this.requestFactory.createUsersWithListInput(body, options); // build promise chain let middlewarePreObservable = of(requestContext); @@ -512,10 +512,10 @@ export class ObservableUserApi { * This can only be done by the logged in user. * Updated user * @param username name that need to be deleted - * @param user Updated user object + * @param body Updated user object */ - public updateUser(username: string, user: User, options?: Configuration): Observable { - const requestContext = this.requestFactory.updateUser(username, user, options); + public updateUser(username: string, body: User, options?: Configuration): Observable { + const requestContext = this.requestFactory.updateUser(username, body, options); // build promise chain let middlewarePreObservable = of(requestContext); diff --git a/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts b/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts index 9c6c49ae8d7..9aabd247268 100644 --- a/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts +++ b/samples/client/petstore/typescript/builds/default/types/PromiseAPI.ts @@ -21,10 +21,10 @@ export class PromisePetApi { /** * Add a new pet to the store - * @param pet Pet object that needs to be added to the store + * @param body Pet object that needs to be added to the store */ - public addPet(pet: Pet, options?: Configuration): Promise { - const result = this.api.addPet(pet, options); + public addPet(body: Pet, options?: Configuration): Promise { + const result = this.api.addPet(body, options); return result.toPromise(); } @@ -70,10 +70,10 @@ export class PromisePetApi { /** * Update an existing pet - * @param pet Pet object that needs to be added to the store + * @param body Pet object that needs to be added to the store */ - public updatePet(pet: Pet, options?: Configuration): Promise { - const result = this.api.updatePet(pet, options); + public updatePet(body: Pet, options?: Configuration): Promise { + const result = this.api.updatePet(body, options); return result.toPromise(); } @@ -146,10 +146,10 @@ export class PromiseStoreApi { /** * Place an order for a pet - * @param order order placed for purchasing the pet + * @param body order placed for purchasing the pet */ - public placeOrder(order: Order, options?: Configuration): Promise { - const result = this.api.placeOrder(order, options); + public placeOrder(body: Order, options?: Configuration): Promise { + const result = this.api.placeOrder(body, options); return result.toPromise(); } @@ -172,28 +172,28 @@ export class PromiseUserApi { /** * This can only be done by the logged in user. * Create user - * @param user Created user object + * @param body Created user object */ - public createUser(user: User, options?: Configuration): Promise { - const result = this.api.createUser(user, options); + public createUser(body: User, options?: Configuration): Promise { + const result = this.api.createUser(body, options); return result.toPromise(); } /** * Creates list of users with given input array - * @param user List of user object + * @param body List of user object */ - public createUsersWithArrayInput(user: Array, options?: Configuration): Promise { - const result = this.api.createUsersWithArrayInput(user, options); + public createUsersWithArrayInput(body: Array, options?: Configuration): Promise { + const result = this.api.createUsersWithArrayInput(body, options); return result.toPromise(); } /** * Creates list of users with given input array - * @param user List of user object + * @param body List of user object */ - public createUsersWithListInput(user: Array, options?: Configuration): Promise { - const result = this.api.createUsersWithListInput(user, options); + public createUsersWithListInput(body: Array, options?: Configuration): Promise { + const result = this.api.createUsersWithListInput(body, options); return result.toPromise(); } @@ -238,10 +238,10 @@ export class PromiseUserApi { * This can only be done by the logged in user. * Updated user * @param username name that need to be deleted - * @param user Updated user object + * @param body Updated user object */ - public updateUser(username: string, user: User, options?: Configuration): Promise { - const result = this.api.updateUser(username, user, options); + public updateUser(username: string, body: User, options?: Configuration): Promise { + const result = this.api.updateUser(username, body, options); return result.toPromise(); }