Skip to content

[BUG] std::option::Option<&str> cannot be formatted with the default formatter #20145

@mickvangelderen

Description

@mickvangelderen

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

I'm using the rust generator to generate a client for our kubernetes API server.

The generated client code fails to compile with:

error[E0277]: `std::option::Option<&str>` doesn't implement `std::fmt::Display`
    --> kubernetes-client/src/apis/core_v1_api.rs:3872:67
     |
3872 |     let local_var_uri_str = format!("{}/api/v1/nodes/{name}/proxy/{path}", local_var_configuration.base_path, name=crate::apis::urlencode(name));
     |                                                                   ^^^^^^ `std::option::Option<&str>` cannot be formatted with the default formatter

The generated code:

/// connect POST requests to proxy of Node
pub async fn connect_core_v1_post_node_proxy_with_path(configuration: &configuration::Configuration, name: &str, path: Option<&str>) -> Result<String, Error<ConnectCoreV1PostNodeProxyWithPathError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/api/v1/nodes/{name}/proxy/{path}", local_var_configuration.base_path, name=crate::apis::urlencode(name));
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
   
    // ...
}
openapi-generator version

Happens on:

  • 7.10.0
  • 7.11.0-SNAPSHOT
OpenAPI declaration file content or url

Can't share but it is a Kubernetes OpenAPI V2 spec.

Generation Details
docker run --rm --network=host -v ${PWD}:/local openapitools/openapi-generator-cli \
    generate \
    -i https://apiserver/openapi/v2 \
    -g rust \
    -o /local \
    --additional-properties=packageName=kubernetes-client,packageVersion=0.1.0
Steps to reproduce
Related issues/PRs
Suggest a fix

Perhaps the last part of the URL /{path} or just {path} (not the slash) should be left off if path is None.

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