Skip to content

[BUG][Rust] Request trait library does not compile with keyword parameters  #20329

Closed
@ranger-ross

Description

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Function parameters are properly escaped with r# but with the new reqwest-trait client we introduced lifetime parameters that reused to the parameter name.
# is not valid in lifetime names.

Error

115 |     async fn find_pets_by_status<'r#type>(&self, r#type: Option<&'r#type str>) -> Result<Vec<models::Pet>, Error<FindPetsByStatusError>> {
    |                                    ^ expected one of `,`, `:`, or `>`
openapi-generator version

build from source Git Hash cc40f40

OpenAPI declaration file content or url
# ...
  /pet/findByStatus:
    get:
      tags:
        - pet
      summary: Finds Pets by status
      description: Multiple status values can be provided with comma separated strings
      operationId: findPetsByStatus
      parameters:
        - name: type # <------- This is a Rust keyword
          in: query
          description: Status values that need to be considered for filter
          required: false
          explode: true
          schema:
            type: string
            default: available
            enum:
              - available
              - pending
              - sold
# ...
Generation Details
generatorName: rust
library: reqwest-trait
additionalProperties:
  supportMiddleware: true
  preferUnsignedInt: true
  topLevelApiClient: true
  useBonBuilder: true
  mockall: true
Steps to reproduce
  1. Create an openapi spec with query param with the name of any Rust keyword
  2. Generate the client with the config above
  3. Run cargo build
Related issues/PRs
Suggest a fix

This can be fixed by simply replacing the r# with a r_ as that is a valid lifetime name.

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