-
Notifications
You must be signed in to change notification settings - Fork 6k
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] Fix #2121, generated method names don't follow coding convention #2125
Conversation
2172677
to
686ea61
Compare
Thanks for the PR. Instead of introducing Please update the ObjC sample as mentioned in https://github.com/swagger-api/swagger-codegen/blob/master/CONTRIBUTING.md To run the integration test, please do
|
@wing328 Ah, now I see what you meant. Thank you! UPDATE: I figured out the answer to the following question: I'm working on @Override
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
if (operations != null) {
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
for (CodegenOperation operation : ops) {
if (!operation.allParams.isEmpty()) {
String firstParamName = operation.allParams.get(0).paramName;
******.put("firstParamAltName", camelize(firstParamName));
}
}
}
return objs;
} Thank you in advance! |
686ea61
to
1227eec
Compare
@wing328 I'm working on updating the Petstore sample and encountering an issue regarding It looks that the latest "schema": {
"type": "string",
"format": "binary"
} For such endpoints, the current Obj-C codegen generates code like the following: //
///
/// Fake endpoint to test byte array return by 'Find pet by ID'
/// Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions
///
/// @param petId ID of pet that needs to be fetched
///
///
/// @return SWGBinary*
-(NSNumber*) getPetByIdWithByteArrayWithPetId: (NSNumber*) petId
completionHandler: (void (^)(SWGBinary* output, NSError* error)) handler; where |
bad7e35
to
62c9417
Compare
@wing328 thanks! I've updated the sample and the test files too. The updated tests run fine on my local machine. While updating, I noticed an inconvenience of this PR's new method name generation proposal. [api getPetByIdWithPetId:[pet _id] completionHandler:^(SWGPet *output, NSError *error) { FYI, it previously was: [api getPetByIdWithCompletionBlock:[pet _id] completionHandler:^(SWGPet *output, NSError *error) { This may be a limitation of mechanically generating method names from |
if(error) { | ||
XCTFail(@"got error %@", error); | ||
} | ||
else { | ||
[api getPetByIdWithCompletionBlock:[NSString stringWithFormat:@"%@",[pet _id]] completionHandler:^(SWGPet *output, NSError *error) { | ||
[api getPetByIdWithPetId:[pet _id] completionHandler:^(SWGPet *output, NSError *error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why the conversion of [pet _id]
to NSString
was needed in the original code...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe _id was an integer/long before...
@hideya there's no way we can perfectly auto generate the method name to conform's to every language's style. Personally I'm ok with your current approach. Would it meet the requirement for your use case? I mean do you have |
@wing328 Yeah, I also found similar cases like |
For perfection, we can introduce a vendor extension tag (e.g. x-objc-operationId) to use the value specified in x-objc-operationId if it's defined. I'll leave it up to you to implement it or not. |
If you are fine with the current PR, then I'm fine too. If you'd rather like to have x-objc-operationId introduced, I'm happy to do that. Please let me know. |
If you've time, please kindly work on it as this can serve as a workaround to use the "old" method name in Objc API client after upgrading to the latest version that includes your proposed change. In other words, this can make the upgrade backward compatible. |
Sure thing! Would you point me an example code of vendor extension tag introduction in the codebase? |
I think you can use it directly in the mustache template, e.g https://github.com/swagger-api/swagger-codegen/blob/ece56af43c2559c933a2e95bc283078c1ce88f91/modules/swagger-codegen/src/main/resources/Java/libraries/feign/api.mustache |
62c9417
to
753499e
Compare
I've updated this PR to support
Does this sound right? If so, I think this PR is ready for re-review and for possible merge. |
Hi, this sounds good, but I would make sure that the java code will set the |
@fehguy thanks for the comment. Yes, the |
so there should be no impact to other API clients. |
@hideya The change looks very good to me. Thanks for the contribution. |
[ObjC] Fix #2121, generated method names don't follow coding convention
Fixes #2121
Since I needed to reference both the untouched and the camelize names of the first argument in the mustache files,
CodegenOperation.firstParamAltName
has been introduced.Now generated method names look like the following, e.g.:
instead of:
Note that the argument variable name for
completionHandler
has also been updated fromcompletionBlock
tohandler
, following the signature of a popular method ofModalWindowController
:Also, the name of
-[ApiClient requestWithCompletionBlock:...]
too has been updated to-[ApiClient requestWithPath:...]
to follow the convention.@wing328 I have tested the changes against my test cases but haven't made any changes in the test cases and the samples. Would you please tell me what I need to do for those?