Skip to content

Commit

Permalink
[ObjC] fix NPE when getting swagger type (#6465)
Browse files Browse the repository at this point in the history
* fix npe in swagger type (objc)

* remove trailing spaces
  • Loading branch information
wing328 authored Sep 11, 2017
1 parent a6d6432 commit 9e0911b
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
public static final String GIT_REPO_URL = "gitRepoURL";
public static final String DEFAULT_LICENSE = "Proprietary";
public static final String CORE_DATA = "coreData";

protected Set<String> foundationClasses = new HashSet<String>();
protected String podName = "SwaggerClient";
protected String podVersion = "1.0.0";
Expand All @@ -41,7 +41,7 @@ public class ObjcClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String apiFilesPath = "Api/";

protected boolean generateCoreData = false;

protected Set<String> advancedMapingTypes = new HashSet<String>();

public ObjcClientCodegen() {
Expand Down Expand Up @@ -255,7 +255,7 @@ public void processOpts() {
supportingFiles.add(new SupportingFile("Object-body.mustache", coreFileFolder(), classPrefix + "Object.m"));
supportingFiles.add(new SupportingFile("QueryParamCollection-header.mustache", coreFileFolder(), classPrefix + "QueryParamCollection.h"));
supportingFiles.add(new SupportingFile("QueryParamCollection-body.mustache", coreFileFolder(), classPrefix + "QueryParamCollection.m"));
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", coreFileFolder(), classPrefix + "ApiClient.h"));
supportingFiles.add(new SupportingFile("ApiClient-header.mustache", coreFileFolder(), classPrefix + "ApiClient.h"));
supportingFiles.add(new SupportingFile("ApiClient-body.mustache", coreFileFolder(), classPrefix + "ApiClient.m"));
supportingFiles.add(new SupportingFile("JSONRequestSerializer-body.mustache", coreFileFolder(), classPrefix + "JSONRequestSerializer.m"));
supportingFiles.add(new SupportingFile("JSONRequestSerializer-header.mustache", coreFileFolder(), classPrefix + "JSONRequestSerializer.h"));
Expand Down Expand Up @@ -308,6 +308,12 @@ public String getTypeDeclaration(String name) {
public String getSwaggerType(Property p) {
String swaggerType = super.getSwaggerType(p);
String type = null;

if (swaggerType == null) {
swaggerType = ""; // set swagger type to empty string if null
}

// TODO avoid using toLowerCase as typeMapping should be case-sensitive
if (typeMapping.containsKey(swaggerType.toLowerCase())) {
type = typeMapping.get(swaggerType.toLowerCase());
if (languageSpecificPrimitives.contains(type) && !foundationClasses.contains(type)) {
Expand Down Expand Up @@ -348,7 +354,7 @@ public String getTypeDeclaration(Property p) {
Property inner = mp.getAdditionalProperties();

String innerTypeDeclaration = getTypeDeclaration(inner);

if (innerTypeDeclaration.endsWith("*")) {
innerTypeDeclaration = innerTypeDeclaration.substring(0, innerTypeDeclaration.length() - 1);
}
Expand Down Expand Up @@ -464,17 +470,17 @@ public String toModelImport(String name) {
public String apiDocFileFolder() {
return (outputFolder + "/" + apiDocPath).replace("/", File.separator);
}

@Override
public String modelDocFileFolder() {
return (outputFolder + "/" + modelDocPath).replace("/", File.separator);
}

@Override
public String toModelDocFilename(String name) {
return toModelName(name);
}

@Override
public String toApiDocFilename(String name) {
return toApiName(name);
Expand Down Expand Up @@ -544,9 +550,9 @@ public String toParamName(String name) {
* those terms here. This logic is only called if a variable matches the reserved words
*
* @return the escaped term
*/
*/
@Override
public String escapeReservedWord(String name) {
public String escapeReservedWord(String name) {
if(this.reservedWordsMappings().containsKey(name)) {
return this.reservedWordsMappings().get(name);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:405 message:"Invalid input"
///
/// @return
/// @return void
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -43,7 +43,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:400 message:"Invalid pet value"
///
/// @return
/// @return void
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler;
Expand Down Expand Up @@ -98,7 +98,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:404 message:"Pet not found",
/// code:405 message:"Validation exception"
///
/// @return
/// @return void
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -112,7 +112,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:405 message:"Invalid input"
///
/// @return
/// @return void
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
Expand All @@ -128,7 +128,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:400 message:"Invalid ID supplied",
/// code:404 message:"Order not found"
///
/// @return
/// @return void
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -42,7 +42,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -54,7 +54,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -67,7 +67,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:400 message:"Invalid username supplied",
/// code:404 message:"User not found"
///
/// @return
/// @return void
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler;

Expand Down Expand Up @@ -107,7 +107,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler;

Expand All @@ -121,7 +121,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:400 message:"Invalid user supplied",
/// code:404 message:"User not found"
///
/// @return
/// @return void
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:405 message:"Invalid input"
///
/// @return
/// @return void
-(NSURLSessionTask*) addPetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -43,7 +43,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:400 message:"Invalid pet value"
///
/// @return
/// @return void
-(NSURLSessionTask*) deletePetWithPetId: (NSNumber*) petId
apiKey: (NSString*) apiKey
completionHandler: (void (^)(NSError* error)) handler;
Expand Down Expand Up @@ -98,7 +98,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
/// code:404 message:"Pet not found",
/// code:405 message:"Validation exception"
///
/// @return
/// @return void
-(NSURLSessionTask*) updatePetWithBody: (SWGPet*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -112,7 +112,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:405 message:"Invalid input"
///
/// @return
/// @return void
-(NSURLSessionTask*) updatePetWithFormWithPetId: (NSString*) petId
name: (NSString*) name
status: (NSString*) status
Expand All @@ -128,7 +128,7 @@ extern NSInteger kSWGPetApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) uploadFileWithPetId: (NSNumber*) petId
additionalMetadata: (NSString*) additionalMetadata
file: (NSURL*) file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern NSInteger kSWGStoreApiMissingParamErrorCode;
/// code:400 message:"Invalid ID supplied",
/// code:404 message:"Order not found"
///
/// @return
/// @return void
-(NSURLSessionTask*) deleteOrderWithOrderId: (NSString*) orderId
completionHandler: (void (^)(NSError* error)) handler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) createUserWithBody: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -42,7 +42,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) createUsersWithArrayInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -54,7 +54,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) createUsersWithListInputWithBody: (NSArray<SWGUser>*) body
completionHandler: (void (^)(NSError* error)) handler;

Expand All @@ -67,7 +67,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:400 message:"Invalid username supplied",
/// code:404 message:"User not found"
///
/// @return
/// @return void
-(NSURLSessionTask*) deleteUserWithUsername: (NSString*) username
completionHandler: (void (^)(NSError* error)) handler;

Expand Down Expand Up @@ -107,7 +107,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
///
/// code:0 message:"successful operation"
///
/// @return
/// @return void
-(NSURLSessionTask*) logoutUserWithCompletionHandler:
(void (^)(NSError* error)) handler;

Expand All @@ -121,7 +121,7 @@ extern NSInteger kSWGUserApiMissingParamErrorCode;
/// code:400 message:"Invalid user supplied",
/// code:404 message:"User not found"
///
/// @return
/// @return void
-(NSURLSessionTask*) updateUserWithUsername: (NSString*) username
body: (SWGUser*) body
completionHandler: (void (^)(NSError* error)) handler;
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/objc/default/docs/SWGStoreApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ This endpoint does not need any parameter.
### Return type
[**NSDictionary<NSString*, NSNumber*>***](NSDictionary.md)
**NSDictionary<NSString*, NSNumber*>***
### Authorization
Expand Down

0 comments on commit 9e0911b

Please sign in to comment.