OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
20.82k stars 6.33k forks source link

[BUG][RUST] New AbstractRustCodegen.java not handling period-delimited model names well. #15254

Open jnicholls opened 1 year ago

jnicholls commented 1 year ago

Bug Report Checklist

Description

I am working with the Microsoft Graph API specification (although I used yq -o=json eval openapi.yaml > openapi.json to convert to a JSON spec first, since there are too many Yaml code points for swagger-parser in v6.5.0 of openapi-generator). It has models named in the following format:

etc. The Rust client generator is outputting the following warnings:

[main] WARN o.o.c.languages.AbstractRustCodegen - MicrosoftGraphFido2AuthenticationMethod cannot be used as a model name. Renamed to MicrosoftPeriodGraphPeriodFido2AuthenticationMethod

[main] WARN o.o.c.languages.AbstractRustCodegen - microsoft/graph/fido2_authentication_method cannot be used as a model file name. Renamed to microsoft_period_graph_period_fido2_authentication_method

This output is perplexing, as MicrosoftGraphFido2AuthenticationMethod post-sanitizing is completely legitimate for Rust, but it still performs another pass and adds Period in placements where . is in the original model name.

Likewise, the module file pathing microsoft/graph/fido2_authentication_method would be perfectly legitimate (assuming proper supporting mod.rs files were generated along the path) as a module path and file name. Or if not that microsoft_graph_fido2_authentication_method would be perfectly good as well, without the added _period separator in the module path name.

I realize these may be two separate issues, but since Period and _period are likely rooted with the same failing to handle . delimited model names, I bet they can be solved together.

openapi-generator version

6.5.0

OpenAPI declaration file content or url

https://raw.githubusercontent.com/microsoftgraph/msgraph-metadata/master/openapi/v1.0/openapi.yaml

converted to json with:

yq -o=json eval openapi.yaml > openapi.json
Generation Details
openapi-generator generate -g rust \
  -i openapi.json \
  -o ms-graph-rust \
  --additional-properties=useSingleRequestParameter=true \
  --skip-validate-spec
Steps to reproduce
  1. Download the openapi.yaml spec.
  2. Convert to openapi.json spec.
  3. Run the above command, see all of the WARN output.
Suggest a fix

I briefly reviewed the AbstractRustCodegen class and how its calling down into DefaultCodegen for various name sanitizing and character replacement, but didn't dig very deep. I feel like the owner of AbstractRustCodegen will know of a good way to handle this issue immediately after reading this description.

jnicholls commented 1 year ago

Tagging @jacob-pro here. Jacob, you introduced and iterated a bit on the AbstractRustCodegen implementation, so thought you might have some insights here as well as a possible workaround (other than generating an inline name map of all the models, which did cross my mind...)