You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I've been generating a C# SDK client which uses multipart/form-data requests in a few places, but ran into trouble when the method had no file parameters, which works in tools like Swashbuckle.
The C# generator produces code which sends the following payload when calling the operation in the example YAML:
This is not valid multipart/form-data and the server refuses to parse it. A valid payload would be:
POST /api/v1/post HTTP/1.1
Host: localhost:8080
User-Agent: OpenAPI-Generator%2F1.0.0%2Fcsharp
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
Accept-Encoding: gzip, deflate, br
Content-Type: multipart/form-data; boundary="28018ef9-0d90-4a6d-9c1b-d53979972be9"
Content-Length: 211
--28018ef9-0d90-4a6d-9c1b-d53979972be9
Content-Type: text/plain; charset=utf-8
Content-Disposition: form-data; name=content
Hello, world! This is an example post.
--28018ef9-0d90-4a6d-9c1b-d53979972be9--
openapi-generator version
7.9.0
OpenAPI declaration file content or url
openapi: 3.0.1info:
title: Post APIversion: '1.0'paths:
/api/v1/post:
post:
operationId: addPostrequestBody:
content:
multipart/form-data:
schema:
required:
- contenttype: objectproperties:
content:
type: objectdescription: "This field contains the content of your post."example: |- Hello, world! This is an example post.encoding:
content:
style: formcontentType: text/plainresponses:
'201':
description: Created
Generation Details
Save example YAML to Post.yml
Generate with openapi-generator-cli generate -i Post.yml -g csharp and no additional options
Steps to reproduce
Call AddPost to some endpoint, capturing the request (through Wireshark or server)
varapi=newDefaultApi(newConfiguration{BasePath="http://localhost:8080"});api.AddPost("Hello, world! This is an example post.");
Observe the body of the request, it a regular POST form with parameters and not multipart
Suggest a fix
If Content-Type is multipart/form-data then AlwaysMultipartFormData should be set to true on the RestRequest. Also, the parameters should not be serialized in multipart/form-data requests as this will cause issues. See #20351.
The text was updated successfully, but these errors were encountered:
Bug Report Checklist
Description
I've been generating a C# SDK client which uses multipart/form-data requests in a few places, but ran into trouble when the method had no file parameters, which works in tools like Swashbuckle.
The C# generator produces code which sends the following payload when calling the operation in the example YAML:
This is not valid multipart/form-data and the server refuses to parse it. A valid payload would be:
openapi-generator version
7.9.0
OpenAPI declaration file content or url
Generation Details
Post.yml
openapi-generator-cli generate -i Post.yml -g csharp
and no additional optionsSteps to reproduce
AddPost
to some endpoint, capturing the request (through Wireshark or server)Suggest a fix
If
Content-Type
ismultipart/form-data
thenAlwaysMultipartFormData
should be set totrue
on theRestRequest
. Also, the parameters should not be serialized inmultipart/form-data
requests as this will cause issues. See #20351.The text was updated successfully, but these errors were encountered: