Monday, 15 May 2017

Swagger Error with parameters in a multipart post request

I'm trying to document an existing API, built in Node, but it keeps giving me the following error:

"Schema error at paths./upload/Rate.post.parameters[0]
is not exactly one from <#/definitions/parameter>,<#/definitions/jsonReference>"

This error appears in 3 places of my code paths./upload/Rate.post.parameters[0], paths./upload/Rate.post.parameters[1] and paths./users/register.post.parameters[0]

I've searched quite a bit, but, for example, this link did not solved my problem although it's the same error:

Swagger parameter error "is not exactly one from <#/definitions/parameter>"?

Maybe it's something I've missed, maybe I'm just too tired of browsing for an answer over the last few days but I couldn't understand how to solve this. I've added the /users/login path, for example this path works properly, even if it's similar with the /users/register... how come the register gives out an error but the login one does not?

/users/login:
    post:
      tags:
      - "users"
      description: Allows an user to login in the Server
      produces:
        - application/json
      parameters:
        - in: body
          name: body
          description: JSON Object with information for a Login request from an User
          required: false
          schema:
            type: object
            required:   
              - username
              - password
            properties:
              username:
                type: string
              password:
                type: string
                format: password
      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Login successful
          schema:
            type: string

 /users/register:
    post:
      tags:
      - "users"
      description: Allows an user to register at the Server
      produces:
        - application/json
      parameters:
        - name: body
          in: body
          description: JSON Object with information for a Register request from an User
          schema: 
            type: object
            required:
              - username
              - password
              - weight
              - height
              - gender
              - restRate
              - age
            properties:
              username:
                type: string
              password:
                type:
                format: password
              weight:
                type: integer
              height:
                type: integer
              gender:
                type: string
              restHR:
                type: integer
              age: 
                type: integer
      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Register successful
          schema:
            type: string

/upload/Rate:
    post:
      tags:
      - "upload"
      description: Allows an user to upload a file into the server
      produces:
        - application/json
      consumes: 
        - multipart/form-data
      parameters:
        - name: body
          in: formData
          description: JSON Object with information for an upload request from an User
          required: false
          schema:
            type: object
            required:   
              - user
              - overlap
              - window 
              - latitude
              - longitude
              - time
              - date
            properties:
              user:
                type: string
              overlap:
                type: string
              window:
                type: string
              latitude:
                type: string
              longitude:
                type: string
              time:
                type: string
              date:
                type: string
        - name: files 
          in: formData
          description: File with the corresponding Rate
          required: false
          schema:
            type: object
            required:
              - rate
            properties:
              rate:
                type: file
      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Login successful
          schema:
            type: string

The text got poorly formatted when I copy paste'd it into the website, I believe everything is ok with my indentation(I understand Swagger is sensible about it)

Maybe this will help, but the post route (upload/Rate) should receive a request that will be something like this, once I've parsed it's parameters:

user = req.body.user;
rr = req.files.rate;
overlap = req.body.overlap;
windowT= req.body.window;
latitude= req.body.latitude;
longitude= req.body.longitude;
time= req.body.time;
date= req.body.date;

Thanks for any help anyone can provide.



via D. Nunes

No comments:

Post a Comment