Swagger UI : how to create a resource multi-part with file and json doc in the parameters

43 views
Skip to first unread message

Clément P

unread,
Jun 22, 2017, 11:55:40 AM6/22/17
to Swagger
Hello, 

I have a problem to define a resource multipart/form-data with swagger ui. I would like to define a resource with 2 parameters : a file and a json document

This is my resource definition : 

    /documents/claims:
      post:
        tags:
          - documents
        summary: '...'
        description: ...
        produces:
          - application/json
        consumes:
          - multipart/form-data
        parameters:
          - in: formData
            name: file
            type: file
            description: the file to upload
            required: true
          - in: formData
            name: documentInformation
            required: true
            description: all information about the document
            schema:
              $ref: '#/definitions/DocumentInformation'
        responses:
          '200':
            description: successful operation
            schema:
              $ref: '#/definitions/Response'
    
    definitions:
      Document:
        type: object
        properties:
          index_date:
            type: string
            format: date-time
            description: ...
          external_reference:
            type: string
            description: ...

And I don't know why but the swagger gives me this error : 

    Details
      Object
        code:  "ONE_OF_MISSING"
        params: Array [0]
        message:  "Not a valid parameter definition"
        path: Array [5]
        schemaId:  "http://swagger.io/v2/schema.json#"
        inner: Array [2]
          0: Object
            code:  "ONE_OF_MISSING"
            params: Array [0]
            message:  "Data does not match any schemas from 'oneOf'"
            path: Array [5]
            inner: Array [2]
          1: Object
            code:  "OBJECT_MISSING_REQUIRED_PROPERTY"
            params: Array [1]
            message:  "Missing required property: $ref"
           path: Array [5]
         level: 900
         type:  "Swagger Error"
         description:  "Not a valid parameter definition"

If I remove the schema of the 2nd parameter documentInformation and I replace it by a simple type like string, the error disappears.

Could you help me please? How can I do to send a file and a json object with a multi-part resource?

Thank you in advance for your help.

Ron Ratovsky

unread,
Jun 22, 2017, 2:02:12 PM6/22/17
to swagger-sw...@googlegroups.com

You can’t do that with Swagger 2. FormData parameters do not support complex types. You can either define both as files, or one as a file and the other as a string, without the ability to define the json structure.

 

The next version of the spec, coming out in a couple of months, adds support to this use case.

--
You received this message because you are subscribed to the Google Groups "Swagger" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swagger-swaggers...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages