Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #3052
Closed
Open
Issue created Jun 01, 2019 by Administrator@rootContributor5 of 6 checklist items completed5/6 checklist items

[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

Assignee
Assign to
Time tracking