[Rust] various enhancements#6411
Conversation
|
@ahmedcharles thanks for the PR. cc @frol @farcaller |
|
LGTM. |
| } | ||
|
|
||
| {{#vars}} | ||
| #[allow(non_snake_case)] |
There was a problem hiding this comment.
@wing328 Can we avoid this? I know that other Codegen languages transform names according to the guidelines of the target programming language.
There was a problem hiding this comment.
I agree, I'm just new to swagger-codegen and wasn't sure how to get names exactly right.
In this case, I need two versions of the name, one with a leading underscore and one without, because the warning is due to having two underscores in a row. Do you know how to create two mustache variables, one with a leading underscore for reserved names and one without?
There was a problem hiding this comment.
@frol Is there any lib in Rust that can handle JSON (de)serialization?
@ahmedcharles please share the spec of the model.
There was a problem hiding this comment.
@wing328 Serde is used here for JSON (de)serialization.
@ahmedcharles You can just use _{{ var_name }} in the template if you need a leading underscore.
There was a problem hiding this comment.
@frol I had a look at https://serde.rs/examples.html but couldn't an example how to provide a 1-1 mapping for attribute name (similar to what've done for Java, C#, etc). Do you know how we can map attribute name with Serde?
There was a problem hiding this comment.
@frol The issue with the warning is that type is a reserved word, so the {{name}} is _type, which when combined with with_{{name}} becomes with__type, which is what creates the warning. What I need is {{name}} = _type and {{rawName}} = type, so then I can do fn {{name}}(...) and fn with_{{rawName}}(...) and never have it generate names with two underscores in a row.
@wing328 Isn't that what #[serde(rename = "jsonName")] rust_name: String; does?
| Client::configure().connector(HttpConnector::new(4, &handle)).build(&handle))); | ||
|
|
||
| let work = apicli.pet_api().add_pet(&new_pet) | ||
| let work = apicli.pet_api().AddPet(new_pet) |
There was a problem hiding this comment.
It seems to be not the change this PR introduced, but it would be great if the naming conventions are aligned according to the recommendations instead of putting #[allow(non_snake_case)] everywhere.
There was a problem hiding this comment.
Yeah, the python generator uses add_pet, though I didn't look at the Java code. Do you know how to change the Java code to get this to be the different style?
There was a problem hiding this comment.
…6421) * Revert "Make the Rust codegen compile. (#6411)" This reverts commit 60766c6. * Revert "[Kotlin] Fix model enum generation (#6383)" This reverts commit adf5d64. * Revert "Global namespaces for ruby basic types (#6418)" This reverts commit 070894d. * Revert "add ehyche to swift tech comm" This reverts commit 5c62ba1. * Revert "[python-client] Thread pool fix (#6396)" This reverts commit a28ce0b. * Revert "update retrofit2 petstore samples" This reverts commit 0f1a61d. * Revert "Retrofit2: Return ResponseBody if response if file. (#6407)" This reverts commit 481c040.
|
@ahmedcharles FYI, it seems that the PR was merged by mistake and it was reverted... Could you, please, continue your work on the better variable naming? |
|
Hmm, well... I have just noticed that the naming conventions are fine! Great job! @wing328 Why did you revert the PR? |
No description provided.