Skip to content

[ObjC] fix NPE when getting swagger type #6465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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