Skip to content

[BUG] [rust-axum] In PUT requests with arrays, a body type string fails to fulfil Validate trait in generated server code #21143

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

Open
5 of 6 tasks
Chrystalkey opened this issue Apr 25, 2025 · 0 comments

Comments

@Chrystalkey
Copy link

Chrystalkey commented Apr 25, 2025

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

With this spec
The generation of the client with openapi-generator-cli (OPENAPI_GENERATOR_VERSION=7.12.0) succeeds, but compilation with cargo build (rustc 1.85, 2024 edition) fails due to:

error[E0599]: the method `validate` exists for reference `&&Vec<String>`, but its trait bounds were not satisfied
    --> oapicode\src\server\mod.rs:1508:14
     |
1508 |     #[derive(validator::Validate)]
     |              ^^^^^^^^^^^^^^^^^^^
     |
    ::: C:\Users\Benedikt\.rustup\toolchains\stable-x86_64-pc-windows-gnu\lib/rustlib/src/rust\library\alloc\src\vec\mod.rs:397:1
     |
397  | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
     | ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<std::string::String>: Validate`
     |
    ::: C:\Users\Benedikt\.rustup\toolchains\stable-x86_64-pc-windows-gnu\lib/rustlib/src/rust\library\alloc\src\string.rs:362:1
     |
362  | pub struct String {
     | ----------------- doesn't satisfy `std::string::String: Validate`
     |
     = note: the following trait bounds were not satisfied:
             `Vec<std::string::String>: Validate`
             which is required by `&Vec<std::string::String>: Validate`
             `&Vec<std::string::String>: Validate`
             which is required by `&&Vec<std::string::String>: Validate`
             `std::string::String: Validate`
             which is required by `Vec<std::string::String>: Validate`
             `std::string::String: Validate`
             which is required by `[std::string::String]: Validate`
     = note: this error originates in the derive macro `validator::Validate` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0599`.
error: could not compile `openapi` (lib) due to 1 previous error
openapi-generator version

7.12.0

OpenAPI declaration file content or url

With Error
https://raw.githubusercontent.com/Chrystalkey/landtagszusammenfasser/refs/tags/rust-axum-plain-string/docs/specs/openapi.yml
Without Error
https://github.com/Chrystalkey/landtagszusammenfasser/blob/rust-axum-body-wrapped/docs/specs/openapi.yml

Generation Details

with OPENAPI_GENERATOR_VERSION=7.12.0 set:

java -jar "./oapi-generator/openapi-generator-cli.jar" generate -g rust-axum -i "$(Get-Location)/openapi.yml" -o "$(Get-Location)/oapicode"
(on linux replace $(Get-Location) by $(pwd))
Steps to reproduce

with OPENAPI_GENERATOR_VERSION=7.12.0 set:

& Invoke-WebRequest -OutFile openapi-generator-cli.jar https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.12.0/openapi-generator-cli-7.12.0.jar
& Invoke-WebRequest -OutFile openapi.yml https://raw.githubusercontent.com/Chrystalkey/landtagszusammenfasser/refs/tags/rust-axum-plain-string/docs/specs/openapi.yml
java -jar "./oapi-generator/openapi-generator-cli.jar" generate -g rust-axum -i "$(Get-Location)/openapi.yml" -o "$(Get-Location)/oapicode"
cd oapicode
& cargo build

(on linux replace $(Get-Location) by $(pwd))

Related issues/PRs

This is a bug that happens after the generic arguments in oapicode/src/server/mod are grep-replaced:
"<I, A, E>" -> "<I, A, E, C>"
There is a seperate issue for that, #21144

Suggest a fix

This is worked around (not fixed!) when wrapping the body of operationId: enum_put into an object:

type: object
properties:
  entry:
    type: string

as was done in this version

However I still think this is an issue and should be possible just using plain strings.

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

No branches or pull requests

1 participant