Skip to content
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

Objc header param with hyphen generates broken methods #633

Closed
hyeghiazaryan opened this issue Apr 14, 2015 · 3 comments
Closed

Objc header param with hyphen generates broken methods #633

hyeghiazaryan opened this issue Apr 14, 2015 · 3 comments
Milestone

Comments

@hyeghiazaryan
Copy link
Contributor

This fragment of config

parameters: [
  {
    name: "custom-header",
    in: "header",
    required: true,
    type: "string"
  }
]

Generates this code in .h file

-(NSNumber*) deleteEntityWithCompletionBlock :(NSString*) entity custom-header:(NSString*) custom-header completionHandler: (void (^)(SWGOperationResult* output, NSError* error))completionBlock;

Note hyphens in method signature.

@fehguy
Copy link
Contributor

fehguy commented Apr 14, 2015

That's a bug, easy to fix. I suggest adding this to the languages/ObjClientCodegen.java:

  @Override
  public String toVarName(String name) {
    // replace - with _ e.g. created-at => created_at
    name = name.replaceAll("-", "_");

    // if it's all uppper case, do nothing
    if (name.matches("^[A-Z_]*$"))
      return name;

    // camelize (lower first character) the variable name
    // pet_id => petId
    name = camelize(name, true);

    // for reserved word or word starting with number, append _
    if(reservedWords.contains(name) || name.matches("^\\d.*"))
      name = escapeReservedWord(name);

    return name;
  }

And report back.

@hyeghiazaryan
Copy link
Contributor Author

toVarName override already exists in languages/ObjClientCodegen.java, toParamName was the one missing.

@webron
Copy link
Contributor

webron commented May 4, 2015

This is resolved in develop_2.0.

@webron webron closed this as completed May 4, 2015
@webron webron added this to the v2.1.0 milestone May 4, 2015
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

3 participants