[BUG][Rust] Optional query parameters are always sent
Created by: jonahgeorge
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
What's the version of OpenAPI Generator used? -
Have you search for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Bounty to sponsor the fix (example)
Description
When generating a Rust client with the Reqwest library, optional query parameters are not generated as Option<T>
and are always sent in the request.
This is an issue for APIs which treat an empty string differently from presence of field.
openapi-generator version
4.0.0
OpenAPI declaration file content or url
---
openapi: 3.0.0
info:
title: Bug Example
version: 1.0.0
paths:
/users:
get:
parameters:
- in: query
name: given_name
schema:
type: string
- in: query
name: family_name
required: true
schema:
type: string
responses:
"200":
description: ""
content:
application/json:
schema:
type: object
Command line used for generation
openapi-generator generate -g rust -i openapi.yaml --library reqwest -o actual/
Expected Output
impl DefaultApi for DefaultApiClient {
fn users_get(&self, family_name: &str, given_name: Option<&str>) -> Result<Value, Error> {
let configuration: &configuration::Configuration = self.configuration.borrow();
let client = &configuration.client;
let uri_str = format!("{}/users", configuration.base_path);
let mut req_builder = client.get(uri_str.as_str());
if let Some(ref s) = given_name {
req_builder = req_builder.query(&[("given_name", &s.to_string())]);
}
req_builder = req_builder.query(&[("family_name", &family_name.to_string())]);
Actual Output
impl DefaultApi for DefaultApiClient {
fn users_get(&self, family_name: &str, given_name: &str) -> Result<Value, Error> {
let configuration: &configuration::Configuration = self.configuration.borrow();
let client = &configuration.client;
let uri_str = format!("{}/users", configuration.base_path);
let mut req_builder = client.get(uri_str.as_str());
req_builder = req_builder.query(&[("given_name", &given_name.to_string())]);
req_builder = req_builder.query(&[("family_name", &family_name.to_string())]);
Suggest a fix
#3053