swagger-api / swagger-api/swagger-codegen
Content-type "multipart/form-data" generates actions with individual parameters, not single object like "application/json"
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
content-type multipart/form-data and application/json generate different action signatures.
Swagger-codegen version
Used online version at https://editor.swagger.io/
Swagger declaration file content or url
The following example generates a DefaultApi class that takes individual parameters:
openapi: 3.0.3
info:
title: 'Test API'
description: 'Test v3 API'
termsOfService: 'https://www.example.com/terms'
contact:
email: apisupport@example.com
license:
name: MIT
url: 'https://opensource.org/licenses/MIT'
version: 3.0.0
servers:
-
url: 'https://api.example.com/v3'
paths:
/pets:
patch:
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/Dog'
responses:
'200':
description: Updated
components:
schemas:
Dog:
type: object
properties:
bark:
type: boolean
breed:
type: string
enum: [Dingo, Husky, Retriever, Shepherd]
This is the generated DefaultApi::petsPatch() method:
/**
* Operation petsPatch
*
* @param bool $bark bark (optional)
* @param string $breed breed (optional)
*
* @throws \Swagger\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function petsPatch($bark = null, $breed = null)
{
$this->petsPatchWithHttpInfo($bark, $breed);
}
However, changing multipart/form-data to application/json produces the following DefaultApi::petsPatch() method:
/**
* Operation petsPatch
*
* @param \Swagger\Client\Model\Dog $body body (optional)
*
* @throws \Swagger\Client\ApiException on non-2xx response
* @throws \InvalidArgumentException
* @return void
*/
public function petsPatch($body = null)
{
$this->petsPatchWithHttpInfo($body);
}
Note that both examples generate a \Swagger\Client\Model\Dog class, but only the application/json example uses this class.
Suggest a fix/enhancement
A flag should be accepted by swagger-codegen that forces the use of created object in relevant action methods.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the online editor using the supplied OpenAPI 3.0.3 document and compare the generated PHP DefaultApi::petsPatch() signatures for multipart/form-data and application/json. Trace the requestBody handling and Mustache-generated PHP output; done means multipart/form-data uses the generated Dog model consistently, with the relevant behavior covered by a regression check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, php
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100