[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
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by generating the client from the supplied spec.yaml with the shown OpenAPI Generator command, then run cargo check and inspect src/apis/default_api.rs. Trace the Rust generator templates for query parameters, multipart fields, model qualification, and parameter naming. Done means the four reduced cases generate compiling Rust without the reported errors.
由索引模型根据 Issue 内容生成。
描述
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: created
Generation 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=short
Steps 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.
- 主要语言
- Java
- 星标
- 26.9k
- 派生
- 7.8k
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 180
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
OpenAPITools/openapi-generator 的其他 Issue
-
Issue: Bug
难度 2/5 1-3 小时 新手友好度 80/100
OpenAPITools/openapi-generator#25643 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
OpenAPITools/openapi-generator#25640 ·
维护者通常 1 天内回复
-
[BUG][JAVA] Deprecated properties only get @Deprecated on the getter (base, feign, native, microprofile)可能已有人在做 @Inf1mum 于 2 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 82/100
OpenAPITools/openapi-generator#25567 ·
维护者通常 1 天内回复
-
[BUG][KOTLIN-SERVER] typeInfoAnnotation.mustache uses As.PROPERTY → discriminator property serialized twice可能已有人在做 @Inf1mum 于 9 天前认领。 未关闭Issue: Bug
难度 2/5 1-3 小时 新手友好度 62/100
OpenAPITools/openapi-generator#25524 · 1 条评论 ·
维护者通常 1 天内回复
-
[REQ][JAVA][resteasy] Support for Jackson 3 / useJackson3可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭Enhancement: Feature
难度 2/5 1-3 小时 新手友好度 78/100
OpenAPITools/openapi-generator#25364 ·
维护者通常 1 天内回复
查看 OpenAPITools/openapi-generator 的全部 Issue
相似的 Issue
-
bug emitter:client:csharp
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/typespec#12572 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
GCC 15.2: -Wcast-qual warning - cast discards const qualifier from pointer target type (H5trace.c)未关闭
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
[Bug] RemotingHelper.connect swaps the socket send and receive buffer configuration可能已有人在做 @amalsaidov 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
needs-area-label
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
area/ai area/backend component/zeebe kind/task
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复