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

Delete Request not working from swagger UI #340

Closed
infyravi opened this issue Nov 6, 2013 · 19 comments
Closed

Delete Request not working from swagger UI #340

infyravi opened this issue Nov 6, 2013 · 19 comments

Comments

@infyravi
Copy link

infyravi commented Nov 6, 2013

While performing DELETE Operation from swagger UI in playframework,Delete operation is not working.It is expecting json but the delete method is defined for Long datatype as input parameter.we are using Play 2.1.3.When we enter id of the Entity to delete ,getting the error message as message": "400 Error Invalid Json

@fehguy
Copy link
Contributor

fehguy commented Nov 6, 2013

the problem is the UI is asking for JSON and you're sending back an invalid json. You'll need to figure tell swagger that the response type is text if it's not truly json.

@infyravi
Copy link
Author

infyravi commented Nov 7, 2013

Hi fehguy,

Thanks for responding!!!!!.the controller method which we are using is

@DELETE
@ApiOperation(value = "Delete Player by ID")
@ApiErrors(value = { @ApiError(code = 400, reason = "Failed to set Player header") })
public static Result deletePlayer (
        @ApiParam(value = "ID of Player that needs to be deleted", required = true) @PathParam("id") Long id) {
    here goes the buisness logic related to Player
}

entry in the Routes file

DELETE /Players/:id controllers.Application.deletePlayer(id: Long)

we have another similar method which takes Id as input which works fine.Code of this method as shown below
@get
@ApiOperation(value = "Get Player by ID", responseClass = "models.Player ")
@ApiErrors(value = { @ApiError(code = 400, reason = "Invalid ID supplied") })
public static Result getPlayer (
@ApiParam(value = "ID of Player that needs to be fetched", required = true) @PathParam("id") Long id) {

Thanks in Advance

@infyravi
Copy link
Author

infyravi commented Nov 7, 2013

we have tried the following options also
@ApiOperation(value = "Delete Player by ID", responseClass="void")

but we are getting the same issue

@valdemon
Copy link
Contributor

valdemon commented Nov 7, 2013

Hi,
I haven't worked with the play framework, but it looks like you're using the javax.ws.rs.* annotations in your resources methods, so maybe the @produces(...) annotation with proper MediaType could help here.

@Chitra1986
Copy link

Hi,
By setting up requestContentType = "multipart/form-data"; for "DELETE" in swagger.js , this issue can be resolved.

@ludofischer
Copy link

For me the problem using Play 2.1.3 and Swagger UI is that Swagger UI sets the DELETE request content type to application/json, but since the body of the DELETE request is empty, Play considers that the request is not valid application/json and therefore sends a Bad Request response.

@valdemon
Copy link
Contributor

Then it should be resolved by the @consumes(MediaType.MULTIPART_FORM_DATA) annotation at the DELETE method.

@ludofischer
Copy link

@valdemon Good point. We are using a custom Swagger library for Play 2 instead of the Wordnik one, so we will probably need to develop a way to declare the request content type in our implementation.

@fehguy
Copy link
Contributor

fehguy commented Dec 2, 2013

@ludovicofischer @valdemon it seems that most frameworks are OK with Application/XML as the content type being sent when there is no data.

@dvic
Copy link

dvic commented Mar 18, 2014

Would it hurt to change the requests from an empty body to "{}"? (I applied this in my swagger-ui installation)

@fehguy
Copy link
Contributor

fehguy commented Mar 19, 2014

Yes, I think that'd cause some servers to throw-up.

@giuseppegreco
Copy link

I think this issue is back with the latest version...

Whenever I try to DELETE a resource I always get the following error [Bad request]:

For request 'DELETE /auth/users/5392238c1e04001e04b384b4/avatar' [Invalid Json]

I haven't modified my source code and if I rollback to the previous version of Swagger it works correctly. Am I missing something?

@giuseppegreco
Copy link

Just for info... Here's my annotations (I use scala):

@ApiOperation(
httpMethod = "DELETE",
nickname = "delete",
value = "Deletes an user",
response = classOf[Void])
@ApiResponses(Array(
new ApiResponse(code = 400, message = "Invalid user id"),
new ApiResponse(code = 401, message = "Request not authorized"),
new ApiResponse(code = 403, message = "User does not have required privileges"),
new ApiResponse(code = 404, message = "User not found"),
new ApiResponse(code = 412, message = "Authentication precondition failed"),
new ApiResponse(code = 500, message = "Error processing delete user request")))
def delete(
@ApiParam(
name = "userId",
value = "The id of the user to delete",
required = true)
@PathParam("userId")
userId: String) = SecuredAction.async { implicit request =>
....
}

@fehguy fehguy closed this as completed in 011f709 Jul 11, 2014
@fehguy
Copy link
Contributor

fehguy commented Jul 11, 2014

@giuseppegreco please master a shot

shelbys added a commit to shelbys/swagger-ui that referenced this issue Jul 11, 2014
* upstream/master:
  fixed swagger-api#340 with empty body, updated swagger-js
  updated to support explicit keys
@sschwell
Copy link

DELETE's still have no content. swagger.js:1119 does not allow DELETE to have a body.

The fix that worked for me was to change line 1119 of swagger.js to:
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {

Alexgalinier pushed a commit to INTENT-TECHNOLOGIES/swagger-ui that referenced this issue Nov 17, 2014
@alphaadidas
Copy link

for delete methods, best to use : Action.async(parse.empty)

@bytesandwich
Copy link

@alphaadidas thanks that's super helpful!

@cnmuc
Copy link

cnmuc commented Apr 18, 2016

@alphaadidas tx, empty body parser worked for me

Jonahss pushed a commit to eaze/swagger-ui that referenced this issue Aug 12, 2016
vincent-zurczak pushed a commit to roboconf/swagger-ui that referenced this issue Aug 18, 2016
@00bharat7
Copy link

@alphaadidas - This saved my precious time. thanks a lot 👍

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

No branches or pull requests