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

Open
@Chrystalkey

Description

@Chrystalkey

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.

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