OpenAPITools / OpenAPITools/openapi-generator

[BUG] Headers don't return

Open
#17,209 2 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Rust Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

[BUG] Headers don't return

Hello everyone,
I got an issue with the openAPI generator for rust. Specifically with headers in the generator.

When I call this command on the file api.json, it does generate the files it should generate, but there is a problem with the headers from my login function.

Description

The return should also give the header.

openapi-generator version
6.2.0
Generation Details
Command
openapi-generator-cli generate -i api.json -g rust -o file_system_cli/file_system_lib 
Login function in api.json:
"/api/v1/organisations/login": {
      "post": {
        "tags": [
          "Organisations"
        ],
        "operationId": "login",
        "requestBody": {
          "description": "",
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "$ref": "#/components/schemas/EmailAndPassword"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Successfully authenticated. The session ID is returned in a cookie named `id`. You need to include this cookie in subsequent requests.",
            "headers": {
              "Set-Cookie": {
                "schema": {
                  "type": "string"
                },
                "description": "Session cookie"
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "description": "Success message"
                    },
                    "sessionId": {
                      "type": "string",
                      "description": "Session ID"
                    },
                    "Set-Cookie": {
                      "type": "string",
                      "description": "Session cookie"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Something went wrong",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Response"
                }
              }
            }
          }
        }
      }
    },
Generated code
pub async fn login(configuration: &configuration::Configuration, email: &str, password: &str) -> Result<crate::models::Login200Response, Error<LoginError>> {
    let local_var_configuration = configuration;

    let local_var_client = &local_var_configuration.client;

    let local_var_uri_str = format!("{}/api/v1/organisations/login", local_var_configuration.base_path);
    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
    }
    let mut local_var_form_params = std::collections::HashMap::new();
    local_var_form_params.insert("email", email.to_string());
    local_var_form_params.insert("password", password.to_string());
    local_var_req_builder = local_var_req_builder.form(&local_var_form_params);

    let local_var_req = local_var_req_builder.build()?;
    let local_var_resp = local_var_client.execute(local_var_req).await?;

    let local_var_status = local_var_resp.status();
    let local_var_content = local_var_resp.text().await?;

    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
        serde_json::from_str(&local_var_content).map_err(Error::from)
    } else {
        let local_var_entity: Option<LoginError> = serde_json::from_str(&local_var_content).ok();
        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
        Err(Error::ResponseError(local_var_error))
    }
}
The problem

The problem is that when I try to get the results from this generated function, it doesn't return the header (which I need for a cookie).

I know I could just change the code up a bit, but everytime I rerun the command I would have to change the code again.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with api.json and the generated Rust login function produced by the shown openapi-generator-cli command. Trace how the 200 response is represented and verify that the generated result exposes the Set-Cookie header; done means rerunning generation preserves access to that header without manual edits.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.