Skip to content

[BUG][RUST_SERVER] Integration test fails because of clippy lint #18572

@myz-dev

Description

@myz-dev

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?
Expected output

Integration test passes

Actual output

Integration test fails

  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The integration test for the rust-server generator fails. The reason for this is that the Rust linter clippy is configured to run as the last step of the test, but a lint is given out for the generated code.
Here is the definition within samples/server/petstore/rust-server/pom.xml:

<execution>
    <id>clippy</id>
    <phase>integration-test</phase>
    <goals>
        <goal>exec</goal>
    </goals>
    <configuration>
        <executable>cargo</executable>
        <arguments>
            <argument>clippy</argument>
        </arguments>
    </configuration>
</execution>

Running the integration test produces output like this:

error: in a `match` scrutinee, avoid complex blocks or closures with blocks; instead, move the block or closure higher and bind it with a `let`
    --> output/petstore-with-fake-endpoints-models-for-testing/src/server/mod.rs:2930:91
     |
2930 |   ...                   match serde_ignored::deserialize(deserializer, |path| {
     |  _____________________________________________________________________________^
2931 | | ...                           warn!("Ignoring unknown field in body: {}", path);
2932 | | ...                           unused_elements.push(path.to_string());
2933 | | ...                   }) {
     | |_______________________^
     |
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_conditions

error: could not compile `petstore-with-fake-endpoints-models-for-testing` (lib) due to 16 previous errors
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  43.002 s
[INFO] Finished at: 2024-05-05T15:08:26+02:00
[INFO] ------------------------------------------------------------------------
[INFO] 4 goals, 4 executed
[INFO] Cleaning up the local build cache...
[INFO] Deleted 0 unused files from the local build cache in 0.025s
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:exec (clippy) on project RustServerTests: Command execution failed.: Process exited with an error: 101 (Exit value: 101) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
openapi-generator version 7.6.0-SNAPSHOT
OpenAPI declaration file content or url

This happens for different samples, the most simple one is modules/openapi-generator/src/test/resources/3_0/rust-server/no-example-v3.yaml

Generation Details + Steps to reproduce

./bin/generate-samples.sh ./bin/configs/rust-server-*
mvn integration-test -f samples/server/petstore/rust-server/pom.xml

Suggest a fix

I see two ways to fix this. Depending on the way the project wants to move forwards I can provide the fix

  1. Fix the code generation to respect the clippy lint.
    This would mean the code within modules/openapi-generator/src/main/resources/rust-server/server-operation.mustache should change from
    let mut unused_elements = Vec::new();
    match serde_ignored::deserialize(deserializer, |path| {
          warn!("Ignoring unknown field in body: {}", path);
          unused_elements.push(path.to_string());
    }) {...}
    to something like:
    let record_unused =  |path: serde_ignored::Path<'_>| {
        warn!("Ignoring unknown field in body: {}", path);
        unused_elements.push(path.to_string());
        };
    match serde_ignored::deserialize(deserializer, record_unused)  {...}
  2. We could also just configure clippy to not output an error on this specific lint

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions