Skip to content

[BUG][Rust-Axum] Sample generation overwrites handwritten tests #20416

Description

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

Generating samples for rust-axum using ./bin/generate-samples.sh bin/configs/manual/rust-axum-* leads to the manually written tests getting overridden with the default implementation.

Theoretically, this line of code should prevent this for occurring, but the tests get reverted to the default regardless.

Tests in rust need to be present on the generation template due to how cargo test checks for tests on the library, as they cannot be made independent outside the src folder unlike other forms of testing such as cargo bench.

This behaviour is problematic as it makes updating the rust-axum samples in future updates more annoying that it could be, as the tests need to be manually reverted after being overriden by the generator, not to mention the issues that could occurr if someone forgets to do so.

A curious behaviour that happens is that while the command is running, the manually made tests get formatted before getting overwritten shortly after. This may be due cargo fmt getting called multiple times while the source is still being generated, but I thought it was worth noting in case the override is done at a later stage.

openapi-generator version

This is an issue introduced on 3d65786 for 7.11.0 and it is not a regression.

OpenAPI declaration file content or URL

Any declaration will do, but currently the issue is present on the 2 tests implemented in the commit:

Generation Details

The issue is exclusive to the rust-axum generator with the default options. See the reproduction steps listed below.

Steps to reproduce

Run:

  • ./mvnw clean
  • ./bin/generate-samples.sh bin/configs/manual/rust-axum-*
  • See how both manually written tests get restored to the default tests.rs template.
Related issues/PRs

This was pointed out in a review on #20336 and a comment was left on the source code to acknowledge the issue.

Suggest a fix

I was not able to find a way to prevent this behaviour other than calling doNotOverwrite(), which is already being done and it makes no difference.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions