[BUG][Rust] reqwest client does not compile for required nullable params, free-form object query params, inline object form fields and a param named configuration
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- 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?
Description
The rust generator (default reqwest library) emits code that doesn't compile for four parameter shapes. They came up generating a client for GitLab's description (doc/api/openapi/openapi_v3.yaml, 19.5), where they account for 214 of the 219 compile errors. Four more come from path parameters GitLab uses without declaring, and one from .to_string() on an array-of-objects form field, which I haven't reduced. The spec below reduces the four to three operations.
- A parameter that is required and
nullable: truegets anOptiontype, but the template takes the required branch and uses it as a plain value. For a query array it iterates theOptionand calls.to_string()on the wholeVec<String>; for a multipart file it passesOption<PathBuf>toTokioFile::open. This is 158 of GitLab's errors. - A free-form object query parameter (
type: object, no properties) is typedmodels::serde_json::Value. - An inline object form field is typed
models::models::CreateImportRequestConfiguration. Together with 2, that's 48 errors on GitLab. - A form field named
configurationbecomes a second parameter namedconfiguration, next to the&configuration::Configurationargument, and the rest of the function then fails to type-check (8 errors on GitLab).
openapi-generator version
7.25.0.
OpenAPI declaration file content or url
openapi: 3.0.3
info:
title: rust reqwest compile errors
version: "1"
paths:
/variables:
delete:
operationId: deleteVariables
parameters:
- name: filter
in: query
schema:
type: object
nullable: true
- name: paths
in: query
required: true
schema:
type: array
nullable: true
items:
type: string
responses:
"204":
description: deleted
/imports:
post:
operationId: createImport
requestBody:
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
configuration:
type: object
properties:
url:
type: string
responses:
"201":
description: created
/uploads:
post:
operationId: upload
requestBody:
content:
multipart/form-data:
schema:
type: object
required:
- file
properties:
file:
type: string
format: binary
nullable: true
responses:
"201":
description: createdGeneration Details
java -jar openapi-generator-cli-7.25.0.jar generate -g rust -i spec.yaml -o out --additional-properties=packageName=repro
cd out && cargo check --message-format=shortSteps to reproduce
src/apis/default_api.rs:42:74 error[E0415]: identifier `configuration` is bound more than once in this parameter list
src/apis/default_api.rs:42:104 error[E0433]: cannot find `models` in `models`
src/apis/default_api.rs:72:128 error[E0433]: cannot find `serde_json` in `models`
src/apis/default_api.rs:84:96 error[E0599]: `Vec<std::string::String>` doesn't implement `std::fmt::Display`
src/apis/default_api.rs:116:16 error[E0277]: the trait bound `std::option::Option<PathBuf>: AsRef<Path>` is not satisfied
src/apis/default_api.rs:118:33 error[E0599]: no method named `file_name` found for enum `std::option::Option<T>`(plus follow-on errors from the duplicate configuration). The generated lines:
pub async fn create_import(configuration: &configuration::Configuration, configuration: Option<models::models::CreateImportRequestConfiguration>) -> Result<(), Error<CreateImportError>> {
pub async fn delete_variables(configuration: &configuration::Configuration, paths: Option<Vec<String>>, filter: Option<models::serde_json::Value>) -> Result<(), Error<DeleteVariablesError>> {
"multi" => req_builder.query(&p_query_paths.into_iter().map(|p| ("paths".to_owned(), p.to_string())).collect::<Vec<(std::string::String, std::string::String)>>()),
let file = TokioFile::open(&p_form_file).await?;Suggest a fix
Treat required nullable parameters like optional ones in the query and multipart templates, keep serde_json::Value and already-qualified model types free of the extra models:: prefix, and escape a parameter named configuration the way other colliding names are escaped.
Source: OpenAPITools/openapi-generator