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

[BUG] Using model-name-prefix with rust-axum results in uncompilable code due to adding the prefix twice in server/mod.rs #19632

Closed
5 of 6 tasks
jdanton-believer opened this issue Sep 20, 2024 · 4 comments · Fixed by #19922

Comments

@jdanton-believer
Copy link

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Using -g rust-axum in conjunction with --model-name-prefix=Foo results in models::FooFoo{Object} in generated server/mod.rd and uncompilable code.

openapi-generator version

openapi-generator-cli 7.9.0-SNAPSHOT
commit : eebecc8

OpenAPI declaration file content or url

You can use the provided test petstore spec (https://raw.githubusercontent.com/openapitools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml)

Generation Details
openapitools/openapi-generator-cli help generate \
    -i petstore.yaml \
    -g rust-axum \
    -o /local/out \
    --model-name-prefix=Foo
Steps to reproduce
  • Run the provided generation command.
  • Try to compile.
  • Look at line 73 in server/mod.rs
Related issues/PRs
Suggest a fix

I am guessing it is connected to

which means dataType is getting the prefix added twice.

@linxGnu
Copy link
Contributor

linxGnu commented Oct 20, 2024

Hello @jdanton-believer

Thank you for reporting the issue.

There is a bug in AbstractRustCodegen which is shared between RustAxumServer, RustClient, RustServer: here

datatype = toModelName(ModelUtils.getSimpleRef(p.get$ref()));
datatype = "models::" + toModelName(datatype);

Should change to:

datatype = "models::" + toModelName(ModelUtils.getSimpleRef(p.get$ref()));

How do you think @wing328 I can make a PR to fix the issue. Calling toModelName twice is a bug imho!

@linxGnu
Copy link
Contributor

linxGnu commented Oct 20, 2024

Noted: tried to fix that at my local, generated code worked perfectly (ran integration test as well)

@GeorgeFkd
Copy link
Contributor

Trying to create the echo_api(more advanced api integration test) sample i also came across this and can confirm(i reached the same conclusion that something is happening there), this is also happening for the rust-reqwest generator, even without the model-name-prefix parameter.

@linxGnu when you submit your PR ping me so i can take a look at it.

@linxGnu
Copy link
Contributor

linxGnu commented Oct 20, 2024

@GeorgeFkd
PTAL: #19922

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants