Skip to content

[Objective-C] Code generator is not creating enums #1167

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

Open
MrMatthewDavis opened this issue Aug 31, 2015 · 16 comments
Open

[Objective-C] Code generator is not creating enums #1167

MrMatthewDavis opened this issue Aug 31, 2015 · 16 comments

Comments

@MrMatthewDavis
Copy link
Contributor

Enums defined in json models get codegen'd as NSString properties, and no enums are created. This can be observed in the petstore example, which has enum properties but don't get translated in the objective-c codegen.

@wing328
Copy link
Contributor

wing328 commented Sep 2, 2015

@mad102190 yes, enum is not supported in ObjC at the moment. Do you have cycle to help implement it for ObjC client? You can find enum-related mustache tag in https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/Java/enumClass.mustache (Java client).

@wing328
Copy link
Contributor

wing328 commented Sep 2, 2015

@mad102190 by the way, for #971 if you need help with the rebase or the integration test with the ObjC client, please let me know (and thanks again for the PR to add the support of status code and HTTP response header)

FYI. We (the community) have implemented similar feature via #1127 for Java and C# client.

@MrMatthewDavis
Copy link
Contributor Author

@wing328 I've submitted a PR that enables support for enums in Objective-C, so we can close this issue once the PR is merged in. As for #971, did we not determine that there could be possible concurrency issues with the responseHeaders property if running on multiple threads? If that's not a problem, I can rebase and re-open the PR. Let me know. I'll take a look at the C# and Java implementation and see how the thread concurrency issue was addressed there.

@wing328
Copy link
Contributor

wing328 commented Sep 3, 2015

@mad102190 it would be a problem if the developer is using the same ApiClient across all threads. The recommended way is to use an instance of ApiClient per thread (same for C# and Java)

@MrMatthewDavis
Copy link
Contributor Author

That makes perfect sense. I'll work on rebasing that today.

On Sep 3, 2015, at 7:45 AM, wing328 [email protected] wrote:

@mad102190 it would be a problem if the developer is using the same ApiClient across all threads. The recommended way is to use an instance of ApiClient per thread (same for C# and Java)


Reply to this email directly or view it on GitHub.

@wing328
Copy link
Contributor

wing328 commented Sep 3, 2015

@mad102190 take your time. Once again appreciate your contribution to the project.

@MrMatthewDavis
Copy link
Contributor Author

@wing328 No problem, thank you for being so helpful! I've created a brand new PR for the response headers. Please see #1189.

@fehguy
Copy link
Contributor

fehguy commented Dec 18, 2015

I think that what we want is different from enum types. If you take an example like such:

definitions:
  Example:
    type: string
    enum:
      - First
      - Second

We could easily create an enum class:

typedef NS_ENUM(NSInteger, Example) {
    First, Second
};

But what we really want is a NSString which has the acceptable values of First, Second. Thus creating an enum class is actually a bit odd for the codegen. If you, for example, referenced the enum in another model:

  Example2:
    # references an enum class
    type: object
    properties:
      status:
        $ref: '#/definitions/Example'

What would you expect the payload to be? I'm thinking this:

{
  "status": "First"
}

Am I missing something?

@wing328 wing328 modified the milestones: v2.1.6, v2.1.5 Jan 19, 2016
@wing328 wing328 modified the milestones: Future, v2.1.6 Mar 16, 2016
@ClayAtWork
Copy link
Contributor

Has this been worked on by anyone?

@wing328
Copy link
Contributor

wing328 commented Oct 26, 2016

@ClayAtWork I don't think so.

If you've time to work on this, I can show you some good starting points.

@wing328 wing328 modified the milestones: v2.2.2, Future Oct 26, 2016
@sharonjl
Copy link

sharonjl commented Dec 9, 2016

@wing328 I'll take a look. Since I am new to the codegen any pointers would be helpful!

@wing328
Copy link
Contributor

wing328 commented Dec 12, 2016

@sharonjl thanks for offering help on this. I should have something ready for your review by coming Wed. Will keep you posted.

@wing328 wing328 modified the milestones: Future, v2.2.2 Feb 15, 2017
@ryanackley
Copy link

Is there a config option that affects this? because enums are appearing as useless types which are blocking me from using the generated client NOT NSStrings. Am I missing something? or is this new?

original swagger definition:

"AccountType": {
            "type": "string",
            "x-enumNames": [
                "Checking",
                "Savings"
            ],
            "enum": [
                "Checking",
                "Savings"
            ],
            "description": ""
        }

Generates this objective c

@protocol ACHAccountType
@end

@interface ACHAccountType : ACHObject


@end
#import "ACHAccountType.h"

@implementation ACHAccountType

- (instancetype)init {
  self = [super init];
  if (self) {
    // initialize property's default value, if any
    
  }
  return self;
}


/**
 * Maps json key to property name.
 * This method is used by `JSONModel`.
 */
+ (JSONKeyMapper *)keyMapper {
  return [[JSONKeyMapper alloc] initWithDictionary:@{  }];
}

/**
 * Indicates whether the property with the given name is optional.
 * If `propertyName` is optional, then return `YES`, otherwise return `NO`.
 * This method is used by `JSONModel`.
 */
+ (BOOL)propertyIsOptional:(NSString *)propertyName {

  NSArray *optionalProperties = @[];
  return [optionalProperties containsObject:propertyName];
}

@end

@Xzya
Copy link

Xzya commented Nov 10, 2017

Any update on this?

@wing328
Copy link
Contributor

wing328 commented Nov 13, 2017

@Xzya I don't think anyone is working on it. Do you want to give it a try?

@wing328 wing328 removed the P3 label Feb 1, 2018
@MelanyG
Copy link

MelanyG commented Mar 15, 2021

Are there any changes for Objc enums?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants