Created by: jacob-pro
Please review when you have chance: @wing328 @spacether @richardwhiuk @paladinzh
This creates an AbstractRustCodegen (and unit tests)
The primary benefit is that identifier handling has been made more reliable, fixing various inconsistencies, as well as removing about 200 lines code duplication. This will also be useful in future if we want to add support for additional Rust code generators / frameworks.
I have put in a lot of time and effort to make the effects of this change as small as possible.
However there are a few subtle breaking changes to identifier naming:
- Reserved words are escaped differently (closes https://github.com/OpenAPITools/openapi-generator/issues/13171)
- Enum variants are now converted to camel case instead of uppercase (as per guidelines https://rust-lang.github.io/api-guidelines/naming.html)
- More special characters are now mapped e.g.
$$
becomesDollarDollar
(see https://github.com/OpenAPITools/openapi-generator/pull/10521#issuecomment-941949318)
If any of those changes are going to be an issue for either of the generators let me know and I will add in specific overrides to cancel them out?
Thanks in advance for your time reviewing :)
(See also slack thread about creating this abstract class)
Example log output:
[main] WARN org.openapitools.codegen.languages.AbstractRustCodegen - 1Pending cannot be used as a enum variant name. Renamed to Variant1Pending
[main] WARN org.openapitools.codegen.languages.AbstractRustCodegen - 1_pet_summary cannot be used as a model file name. Renamed to model_1_pet_summary
[main] WARN org.openapitools.codegen.languages.AbstractRustCodegen - 1PetSummary cannot be used as a model name. Renamed to Model1PetSummary
[main] WARN org.openapitools.codegen.languages.AbstractRustCodegen - 1_create_pet cannot be used as a method name. Renamed to call_1_create_pet
[main] WARN org.openapitools.codegen.languages.AbstractRustCodegen - 1_pet_name cannot be used as a parameter name. Renamed to param_1_pet_name
[main] WARN org.openapitools.codegen.languages.AbstractRustCodegen - 1_pet_name cannot be used as a field/variable name. Renamed to param_1_pet_name