From d869051fb84e1e72325751593e05e1bb05d49433 Mon Sep 17 00:00:00 2001 From: manuc66 Date: Sun, 23 Apr 2017 12:10:25 +0200 Subject: [PATCH 1/2] Fix Possible null pointer dereference (#5370) --- .../io/swagger/codegen/DefaultCodegen.java | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java index a67cd98cfdc..dee8caaadd3 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultCodegen.java @@ -1831,7 +1831,7 @@ public class DefaultCodegen { currentProperty = currentProperty.items; } - return currentProperty.isEnum; + return currentProperty == null ? false : currentProperty.isEnum; } protected Map getInnerEnumAllowableValues(CodegenProperty property) { @@ -1841,7 +1841,7 @@ public class DefaultCodegen { currentProperty = currentProperty.items; } - return currentProperty.allowableValues; + return currentProperty == null ? new HashMap() : currentProperty.allowableValues; } @@ -1855,16 +1855,18 @@ public class DefaultCodegen { || Boolean.TRUE.equals(baseItem.isListContainer))) { baseItem = baseItem.items; } - // set both datatype and datetypeWithEnum as only the inner type is enum - property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem)); + if (baseItem != null) { + // set both datatype and datetypeWithEnum as only the inner type is enum + property.datatypeWithEnum = property.datatypeWithEnum.replace(baseItem.baseType, toEnumName(baseItem)); - // naming the enum with respect to the language enum naming convention - // e.g. remove [], {} from array/map of enum - property.enumName = toEnumName(property); + // naming the enum with respect to the language enum naming convention + // e.g. remove [], {} from array/map of enum + property.enumName = toEnumName(property); - // set default value for variable with inner enum - if (property.defaultValue != null) { - property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem)); + // set default value for variable with inner enum + if (property.defaultValue != null) { + property.defaultValue = property.defaultValue.replace(baseItem.baseType, toEnumName(baseItem)); + } } } @@ -1878,16 +1880,19 @@ public class DefaultCodegen { || Boolean.TRUE.equals(baseItem.isListContainer))) { baseItem = baseItem.items; } - // set both datatype and datetypeWithEnum as only the inner type is enum - property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem)); - // naming the enum with respect to the language enum naming convention - // e.g. remove [], {} from array/map of enum - property.enumName = toEnumName(property); + if (baseItem != null) { + // set both datatype and datetypeWithEnum as only the inner type is enum + property.datatypeWithEnum = property.datatypeWithEnum.replace(", " + baseItem.baseType, ", " + toEnumName(baseItem)); - // set default value for variable with inner enum - if (property.defaultValue != null) { - property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items)); + // naming the enum with respect to the language enum naming convention + // e.g. remove [], {} from array/map of enum + property.enumName = toEnumName(property); + + // set default value for variable with inner enum + if (property.defaultValue != null) { + property.defaultValue = property.defaultValue.replace(", " + property.items.baseType, ", " + toEnumName(property.items)); + } } } From c3d51357a84ed3aa3a9b2a19d63c6574eb516289 Mon Sep 17 00:00:00 2001 From: Xin Meng Date: Sun, 23 Apr 2017 11:31:00 +0100 Subject: [PATCH 2/2] fix the typescript angular 2 http request option issue #5374 (#5380) * fix the typescript angular 2 http request option issue #5374 https://github.com/swagger-api/swagger-codegen/issues/5374 add `withCredentials:true` to the request option * run ./bin/typescript-angular2-petstore-all.sh to update Petstore samples --- .../typescript-angular2/api.mustache | 3 ++- .../typescript-angular2/default/api/PetApi.ts | 24 ++++++++++++------- .../default/api/StoreApi.ts | 12 ++++++---- .../default/api/UserApi.ts | 24 ++++++++++++------- .../typescript-angular2/npm/api/PetApi.ts | 24 ++++++++++++------- .../typescript-angular2/npm/api/StoreApi.ts | 12 ++++++---- .../typescript-angular2/npm/api/UserApi.ts | 24 ++++++++++++------- 7 files changed, 82 insertions(+), 41 deletions(-) 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 91de00670c5..b9047381190 100644 --- a/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache +++ b/modules/swagger-codegen/src/main/resources/typescript-angular2/api.mustache @@ -204,7 +204,8 @@ export class {{classname}} { {{#hasFormParams}} body: formParams.toString(), {{/hasFormParams}} - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular2/default/api/PetApi.ts b/samples/client/petstore/typescript-angular2/default/api/PetApi.ts index 26ee01017f7..92c4da44669 100644 --- a/samples/client/petstore/typescript-angular2/default/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular2/default/api/PetApi.ts @@ -211,7 +211,8 @@ export class PetApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -262,7 +263,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -311,7 +313,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -360,7 +363,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -413,7 +417,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -461,7 +466,8 @@ export class PetApi { method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -525,7 +531,8 @@ export class PetApi { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -589,7 +596,8 @@ export class PetApi { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts index b84d8f6a4f8..b58d06865ed 100644 --- a/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular2/default/api/StoreApi.ts @@ -132,7 +132,8 @@ export class StoreApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -170,7 +171,8 @@ export class StoreApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -209,7 +211,8 @@ export class StoreApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -246,7 +249,8 @@ export class StoreApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular2/default/api/UserApi.ts b/samples/client/petstore/typescript-angular2/default/api/UserApi.ts index 50db16eee43..8027ce31ae1 100644 --- a/samples/client/petstore/typescript-angular2/default/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular2/default/api/UserApi.ts @@ -196,7 +196,8 @@ export class UserApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -233,7 +234,8 @@ export class UserApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -270,7 +272,8 @@ export class UserApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -309,7 +312,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -348,7 +352,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -391,7 +396,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -424,7 +430,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -467,7 +474,8 @@ export class UserApi { method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts b/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts index 26ee01017f7..92c4da44669 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/PetApi.ts @@ -211,7 +211,8 @@ export class PetApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -262,7 +263,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -311,7 +313,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -360,7 +363,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -413,7 +417,8 @@ export class PetApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -461,7 +466,8 @@ export class PetApi { method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -525,7 +531,8 @@ export class PetApi { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -589,7 +596,8 @@ export class PetApi { method: RequestMethod.Post, headers: headers, body: formParams.toString(), - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts b/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts index b84d8f6a4f8..b58d06865ed 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/StoreApi.ts @@ -132,7 +132,8 @@ export class StoreApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -170,7 +171,8 @@ export class StoreApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -209,7 +211,8 @@ export class StoreApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -246,7 +249,8 @@ export class StoreApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 diff --git a/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts b/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts index 50db16eee43..8027ce31ae1 100644 --- a/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts +++ b/samples/client/petstore/typescript-angular2/npm/api/UserApi.ts @@ -196,7 +196,8 @@ export class UserApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -233,7 +234,8 @@ export class UserApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -270,7 +272,8 @@ export class UserApi { method: RequestMethod.Post, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -309,7 +312,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Delete, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -348,7 +352,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -391,7 +396,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -424,7 +430,8 @@ export class UserApi { let requestOptions: RequestOptionsArgs = new RequestOptions({ method: RequestMethod.Get, headers: headers, - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037 @@ -467,7 +474,8 @@ export class UserApi { method: RequestMethod.Put, headers: headers, body: body == null ? '' : JSON.stringify(body), // https://github.com/angular/angular/issues/10612 - search: queryParameters + search: queryParameters, + withCredentials:true }); // https://github.com/swagger-api/swagger-codegen/issues/4037