OpenAPITools / OpenAPITools/openapi-generator

[BUG] [rust-server] Multipart requestBody camelCase property names are mangled to snake_case

Open
#13,308 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

Multipart requestBody property names that are in camelCase are mangled so that the generated server expects the snake_case version in requests.

openapi-generator version

6.0.1

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: TestAPI
  version: 1.0.0
paths:
  /the/endpoint:
    post:
      operationId: testOp
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              required:
              - camelCase
              - file
              properties:
                camelCase:
                  type: string
                file:
                  type: string
                  format: binary
            encoding:
              camelCase:
                contentType: text/plain
              file:
                contentType: image/png
        required: true
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: string
Command line used for generation

openapi-generator generate -g rust-server --enable-post-process-file --generate-alias-as-model

Steps to reproduce
  1. cargo run --example server
  2. curl -v -F camelCase=test -F file=@<test file> http://127.0.0.1:8080/the/endpoint
Suggest a fix/enhancement

Generated code works if the generated if "camel_case" is replaced by "camelCase" in the the line

let field_camel_case = entries.fields.remove("camel_case");

but the mangled name also occurs in generated error messages.

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

Generate the rust-server example from the supplied OpenAPI declaration and run cargo run --example server, then reproduce the request with the documented curl command. Start at the generated let field_camel_case = entries.fields.remove("camel_case"); line and trace the related error messages; done means multipart requests use the declared camelCase property name throughout.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rust
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.