Create a Node.js function for an HTTP PUT request for a Swagger API

Will Button
InstructorWill Button

Share this video with your friends

Send Tweet

This lesson will teach you how to update a Todo item in Elasticsearch when received from an HTTP PUT method in your API server built with Swagger.

Victor Hazbun
Victor Hazbun
~ 4 years ago

I got this when trying to do a PUT request to the API, I already installed and setup cors. Can you please help me getting this working? TY.

{"message":"Response validation failed: void does not allow a value","code":"INVALID_TYPE","failedValidation":true,"path":["paths","/todo/{id}","put","responses","200"],"originalResponse":"{}"}
Alberto
Alberto
~ 4 years ago

I was not able to end the response with res.end(). I got a JSON parsing error. So I sent back the response. Then I got Victor Alonso's error. I changed the swagger specs to:

       responses:
         200:
           description: "Todo updated"
           schema:
              title: reset
              properties:
                message:
                  type: string
        400:
           description: "Yikes! An error!"
  x-swagger-router-controller: "UpdateTodoById"

as indicated at http://stackoverflow.com/questions/34226739/implementing-a-void-in-swagger-documentation

What exactly am I doing??? Not clear :-(