Open Smootium opened 4 years ago
Not sure if this fixes your issue entirely but the following is of note:
consumes is 2.0, 3.0 defines a requestBody
post:
requestBody:
content:
multipart/form-data:
.....
Not sure if this fixes your issue entirely but the following is of note:
consumes is 2.0, 3.0 defines a requestBody
post: requestBody: content: multipart/form-data: .....
@chris-allnutt Hi. I was including the Swagger 2 definition in the issue for comparison reasons. However, I think it doesn't add anything to the issue and might be confusing, so I removed it. The YAML I link to in the issue does define the upload according to OAS 3 specs.
This seems to affect all AspNetCore versions, not just 2.2.
I am also seeing issues with content type of 'application/x-www-form-urlencoded'
It is strange that the problem still exists. I created a support ticket, but there is no hope for a quick fix.
Description When trying to describe a File Upload action in OAS 3 YAML using
multipart/form-data
content (as described in OAS 3.0.1 specs), the generatedaspnetcore
code contains NO controller method at all. (aspnetcore 2.2)Swagger-codegen version
3.0.18
(using the "3rd Gen" online generator (https://generator3.swagger.io/index.html))Declaration File In the RestApi-multipart-formdata.yml, there is one path describing a
POST
action using themultipart/form-data
content.Options used for generation (note: not including the
spec
object, for simplicity; see subsequent note in Repro Steps)Steps to reproduce ❗️ For simplicity sake, I'm listing the easiest way to reproduce the issue. This is not the process we use "in real life" (but the results are the same).
Generate Server
drop-down menu.aspnetcore
.Open the downloaded generated server content (zip file):
Open the
src\IO.Swagger\Controllers
folderInspect the
CalcSessionsApi.cs
file. ℹ️ I copied the contents of the CalcSessionsApi.cs file into a gist, for easier inspection.Notice there is no method generated.
Related issues/PRs I was not able to find any related/similar issues already posted.
Additional Details On a whim, I tried
multipart\form-data
(instead ofmultipart/form-data
, as it's written in the OAS 3 spec) and at least something gets generated:Body.cs
:HOWEVER, if the above is an example of what will be produced, then there are additional issues that should be fixed (noted in Requested Fix(es) / Expected Results section).
Requested Fix(es) / Expected Results
multipart/form-data
) is specified in the Swagger declaration file.multipart/form-data
schema
only declares oneFile
property (usingtype: string
andformat: binary
orformat: base64
), the method signature for the generated method should be (or very similar to) what it was in Swagger 2.0 (e.g.)type: string
andformat: binary
orformat: base64
) declared in themultipart/form-data
schema
, a new model (type) is generated for that property, which is unnecessary complexity and results in an incorrect method signature (the parameter is marked[FromBody]
when it should be[FromForm]
)