Skip to content

Support for exploded query parameters #27

Description

@jon-smith

Hello, I've been using this library for rust code generation and I've found it much better than the alternatives.

However, I've ran into an issue with some openapi specs I'm using that have exploded query parameters. Is there a plan to support these?

Currently exploded query parameters map to Option<impl AsRef<str>>, with the string being added to the query directly (not 'exploded').

Here's a minimal example:

{
  "openapi": "3.0.3",
  "info": {
    "title": "Exploded Query Param Repro",
    "version": "1.0.0"
  },
  "paths": {
    "/widgets": {
      "get": {
        "operationId": "findWidgets",
        "parameters": [
          {
            "name": "filter",
            "in": "query",
            "style": "form",
            "explode": true,
            "schema": {
              "type": "object",
              "properties": {
                "color": {
                  "type": "string"
                }
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}

This creates the rust code below:

impl HttpClient {
    /// `GET /widgets`
    pub async fn find_widgets(
        &self,
        filter: Option<impl AsRef<str>>,
    ) -> Result<(), ApiOpError<serde_json::Value>> {
        let request_url = format!("{}{}", self.base_url, "/widgets");
        let mut req = self.http_client.get(request_url);
        {
            let mut query_params: Vec<(&str, String)> = Vec::new();
            if let Some(v) = filter {
                query_params.push(("filter", v.as_ref().to_string()));
            }
            if !query_params.is_empty() {
                req = req.query(&query_params);
            }
        }
        ...

This gives a request like GET /widgets?filter=<whatever-string-the-caller-passed>, where I would expect the form GET /widgets?color=red.

With support, the generated function could be:

 pub async fn find_widgets(
        &self,
        filter:  Option<Filter>, // generated struct for the inline object schema
    ) 

or

 pub async fn find_widgets(
        &self,
        color:  Option<String>, 
        // Other params in the filter
    ) 

If this is of interest and not planned I could make a PR.

Thanks

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions