OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
[x] Have you provided a full/minimal spec to reproduce the issue?
[x] Have you validated the input using an OpenAPI validator (example)?
[x] What's the version of OpenAPI Generator used?
[x] Have you search for related issues/PRs?
[x] What's the actual output vs expected output?
[ ] [Optional] Bounty to sponsor the fix (example)
Description
When generating a Go client that has a multipart/form-data requestBody state under components/requestBodies the generator puts the object described in the schema as postBody in the request, fails to parse it and returns the following error while trying to call the generated function:
Invalid body type multipart/form-data
This happens both if the parameters of the form-data requestBody are required or not.
This does not happen when the multipart/form-data requestBody is stated under the paths: property.
openapi: 3.0.0
servers:
- url: http://petstore.swagger.io/v2
info:
description: 'This is a sample server Petstore server. You can find out more about
Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For
this sample, you can use the api key `special-key` to test the authorization filters.'
version: 1.0.0
title: Swagger Petstore
paths:
"/user/createWithArray":
post:
tags:
- user
summary: Creates list of users with given input array
description: ''
operationId: createUsersWithArrayInput
responses:
default:
description: successful operation
requestBody:
"$ref": "#/components/requestBodies/UserArray"
components:
schemas:
User:
type: object
properties:
id:
type: integer
format: int64
username:
type: string
UserPayload:
type: object
properties:
foo:
type: string
bar:
type: array
items:
"$ref": "#/components/schemas/User"
requestBodies:
UserArray:
content:
multipart/form-data:
schema:
"$ref": "#/components/schemas/UserPayload"
description: List of user object
required: true
Use the above command to generate a client passing the above YAML as input.
Related issues/PRs
3043
Suggest a fix
This case should be treated exactly as if the multipart/form-data requestBody was stated under the paths: property. So the data should be inserted in the localVarFormParams variable and not in postBody.
Bug Report Checklist
Description
When generating a Go client that has a
multipart/form-data
requestBody state undercomponents/requestBodies
the generator puts the object described in the schema aspostBody
in the request, fails to parse it and returns the following error while trying to call the generated function:This happens both if the parameters of the form-data requestBody are required or not. This does not happen when the
multipart/form-data
requestBody is stated under thepaths:
property.Actual Output
Expected Output (optional parameters example)
openapi-generator version
4.0.1-SNAPSHOT
OpenAPI declaration file content or url
Command line used for generation
I'm using the docker generator:
Steps to reproduce
Use the above command to generate a client passing the above YAML as input.
Related issues/PRs
3043
Suggest a fix
This case should be treated exactly as if the
multipart/form-data
requestBody was stated under thepaths:
property. So the data should be inserted in thelocalVarFormParams
variable and not inpostBody
.