Skip to content

[BUG] Headers don't return #17209

Open
Open
@TijsBaeyens

Description

@TijsBaeyens

[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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions