Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi part issue #26

Merged
merged 3 commits into from
May 20, 2019
Merged

Conversation

macisamuele
Copy link
Collaborator

The goal of this PR is to address an issue related to file uploads.
The issue was identified internally and ticketed on COREMOBAPI-1461

The issue could be summarised as: we're generating incorrect code in case of file parameters

Assuming a simple endpoint

"/send/file": {
    "post": {
        "consumes": ["multipart/form-data"],
        "parameters": [
            {
                "in": "formData",
                "type": "file",
                "name": "file",
                "required": true
            }
        ],
        "responses": {
            "200": {
                "description": "fafa"
            }
        }
    }
}

The generated code should look like

@JvmSuppressWildcards
interface DefaultApi {
  @retrofit2.http.Multipart    // <- different
  @Headers(
    "X-Operation-ID: "
  )
  @POST("/send/file")
  fun sendFilePost(
    @retrofit2.http.Part(    // <- different
      "file\"; filename=\"file") file:  RequestBody): Completable
}

while the following code is the currently generated content

@JvmSuppressWildcards
interface DefaultApi {
  @retrofit2.http.FormUrlEncoded
  @Headers(
    "X-Operation-ID: "
  )
  @POST("/send/file")
  fun sendFilePost(@retrofit2.http.Field("file\"; filename=\"file") file:  RequestBody): Completable
}

The issue is caused by the fact that swagger-codegen does not keep in consideration the operation level consumes key to properly set isMultipart attribute of Operation object.

@macisamuele macisamuele requested a review from cortinico May 8, 2019 15:50
Copy link
Collaborator

@cortinico cortinico left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the small change, looks fine to me.

plugin/src/main/java/com/yelp/codegen/SharedCodegen.kt Outdated Show resolved Hide resolved
@cortinico cortinico merged commit 67ba99a into Yelp:master May 20, 2019
@cortinico cortinico added this to the 1.1.0 milestone Jun 13, 2019
@macisamuele macisamuele deleted the maci-fix-multi-part-issue branch March 5, 2020 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants