question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated Swagger Files Missing FormData Parameters

See original GitHub issue

I am using version 3.1.3 of the Swagger-Maven-Plugin to generate a yaml file from my api annotations, however the FormData parameters are not being generated and an incorrect body is.

Here are the annotations:

@POST 
    @Produces({ "application/json", "application/xml", "application/avro" })
    @Consumes({"multipart/form-data"})
    @io.swagger.annotations.ApiOperation(value = "Upload plugin", notes = "This can only be done by the logged in user.", response = void.class, tags={ "plugin", })
    @io.swagger.annotations.ApiResponses(value = { 
        @io.swagger.annotations.ApiResponse(code = 200, message = "successful operation", response = void.class) })
    public Response createPlugin(@ApiParam(value = "Json string containing plugin information", required=true)
            @FormDataParam("json")  String pluginJson,
            @FormDataParam("jarfile") InputStream jarInputStream,
            @FormDataParam("jarfile") FormDataContentDisposition jarFileDetail,
            @FormDataParam("configfile") InputStream configInputStream,
            @FormDataParam("configfile") FormDataContentDisposition configFileDetail,@Context SecurityContext securityContext)
    throws NotFoundException {
        return delegate.createPlugin(pluginJson, jarInputStream, jarFileDetail, configInputStream, configFileDetail,securityContext);
    }

Here is the corresponding section of the generated yaml file:


paths:
  /plugin:
    post:
      tags:
      - "plugin"
      summary: "Upload plugin"
      description: "This can only be done by the logged in user."
      operationId: "createPlugin"
      consumes:
      - "multipart/form-data"
      produces:
      - "application/json"
      - "application/xml"
      - "application/avro"
      parameters:
      - in: "body"
        name: "body"
        description: "Json string containing plugin information"
        required: true
      responses:
        200:
          description: "successful operation"

It should be:

paths:
  /plugin:
    post:
      tags:
        - plugin
      summary: Upload plugin
      description: This can only be done by the logged in user.
      operationId: createPlugin
      consumes:
      - "multipart/form-data"
      produces:
        - application/json
        - application/xml
        - application/avro
      parameters:
        - in: formData
          name: json
          description: Json string containing plugin information
          required: true
          type: string
        - in: formData
          name: jarFile
          description: Jar File to upload
          required: true
          type: file
        - in: formData
          name: configFile
          description: config File to upload
          required: true
          type: file
      responses:
        200:
          description: successful operation

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:14

github_iconTop GitHub Comments

2reactions
philipdnicholscommented, Sep 1, 2016

@jencodingatwork Sure - We use the @FormDataParam(“file”) annotation on the InputStream and FormDataContentDisposition method parameters (“file” is the name of the multipart that contains the file. We then annotate the method with @ApiImplicitParams({}) which takes an array of @ApiImplicitParam. For the @ApiImplicitParam, we pass it the values name=“file”, paramType=“form” and dataType=“file”.

Let me know if you have any other questions.

1reaction
jencodingatworkcommented, Oct 7, 2016

In case anyone else tries to use the work around with the swagger ui, you can’t use the dataType=“file” there is an issue with it discussed here: https://github.com/swagger-api/swagger-core/issues/1319. The work around is to use java.io.File instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Generated Swagger Files Missing FormData Parameters
I am using version 3.1.3 of the Swagger-Maven-Plugin to generate a yaml file from my api annotations, however the FormData parameters are not...
Read more >
How to pass formData for POST request in swagger.json?
In OpenAPI 3.0, request body (including form data) is defined using the requestBody keyword instead of in: formData parameters.
Read more >
Multipart Requests - Swagger
Multipart requests combine one or more sets of data into a single body, separated by boundaries. You typically use these requests for file...
Read more >
Parameters cannot have both a "in: body" and "in: formData ...
I'm using 5.1.0 to generate our API. A customer has tried to import the resulting openapi.json file into Swagger Editor and has come...
Read more >
OpenAPI Specification v3.1.0 | Introduction, Definitions, & More
Note: While APIs may be defined by OpenAPI documents in either YAML or JSON ... parameter values of type array or object generate...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found