OpenAPITools / OpenAPITools/openapi-generator

[BUG] PHP client is not sending multipart request unless a file is part of the schema

Open
#5,536 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix
Description

I noticed that even if the OpenAPI3 definition says it consumes multipart/form-data the generated client is not sending multipart request. It only sends multipart requests if a property of the type string and format binary is defined and used in the request (definition only is not changing anything). In my point of view the client should send what the server api has defined to be consumed.

openapi-generator version

4.2.3, 4.3.0 and 5.0.0

OpenAPI declaration file content or url

https://gist.github.com/reeperbahnause/07fc91a8c276e7479c270b8353eb45d9#file-openapi-generator-php-client-multipart-json

Command line used for generation

java -jar openapi-generator-cli-4.2.3.jar generate -i apitestminimal.json -g php -o apitestdir

Steps to reproduce

Generate the php client api send a request and check the request on the server side. It wont be a multipart/form-data request.

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/pull/3750

Suggest a fix

If the parameter is not a file, it might still be a multipart-form-data message, but it's not set to true?
I think, this is the spot to look at:
https://github.com/OpenAPITools/openapi-generator/blob/3588990a4f9f7e7d3e3ae8e2dda59206f57bf676/modules/openapi-generator/src/main/resources/php/api.mustache#L533-L541

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

Start with the PHP template at modules/openapi-generator/src/main/resources/php/api.mustache around lines 533-541, then reproduce the request using the command and OpenAPI declaration linked in the issue. Review related PR #3750 and trace how multipart handling is selected when the schema has no binary property. Done means the generated PHP client sends multipart/form-data for the described multipart endpoint.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, tooling
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.