openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][Rust] format! syntax error for path parameters with dashes in them

Open valpackett opened this issue 1 year ago • 1 comments

Description

The Rust generator generates syntax errors when URI templates have parameter names with - dashes in them.

openapi-generator version

0e05cf2

OpenAPI declaration file content or url
openapi: '3.0.0'
info:
  version: 1.0.0
  title: test
paths:
  /test/{uwu-owo}:
    get:
      summary: sample
      parameters:
      - name: uwu-owo
        in: path
        required: true
        schema:
          type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  hello:
                    type: string
Generation Details
java -jar /home/val/.m2/repository/org/openapitools/openapi-generator-cli/7.6.0-SNAPSHOT/openapi-generator-cli-7.6.0-SNAPSHOT.jar generate -i dash.yaml -o rsbug/ -g rust
Steps to reproduce

generate the above, try to build, get syntax error:

error: invalid format string: expected `'}'`, found `'-'`
  --> src/apis/default_api.rs:31:50
   |
31 |     let local_var_uri_str = format!("{}/test/{uwu-owo}", local_var_configuration.base_path, uwu-owo=crate::api...
   |                                              -   ^ expected `'}'` in format string
   |                                              |
   |                                              because of this opening brace
   |
   = note: if you intended to print `{`, you can escape it using `{{`
Related issues/PRs

:woman_shrugging:

Suggest a fix

Add dash replacement for format! key names

valpackett avatar May 14 '24 05:05 valpackett

Looks like the problem is caused by this line: https://github.com/OpenAPITools/openapi-generator/blob/01fec76ab1cb1c76b8e6e85d19abbdaae1081678/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache#L99 Arguments {{path}} and {{baseName}} are used which are not sanitized for Rust.

For a workaround it is possible to use hyper library instead of reqwest.

Fefer-Ivan avatar Jun 14 '24 19:06 Fefer-Ivan