Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Response code in Response Entity ignored #822

@jfearon

Description

@jfearon

I've setup a endpoint that takes a POST, and returns a 201. If you set this up as:

@ApiOperation(value = "Create a new thing",
        notes = "Insert a new thing into the system"
)
@ApiResponses(value = {
        @ApiResponse(code = 400, message = "Thing failed validation", response = ValidationException.class)})
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Thing> newThing(@RequestBody Thing thing) {

    Thing insertedThing = thingService.insertThing(thing);
    return new ResponseEntity<Thing>(thing, HttpStatus.CREATED);

}

Then this generates as returning a 200 status code:

"responses":{"200":{"description":"OK","schema":{"$ref":"#/definitions/Thing"}}

By contrast this:

@ApiOperation(value = "Create a new thing",
        notes = "Insert a new thing into the system"
)
@ApiResponses(value = {
        @ApiResponse(code = 400, message = "Thing failed validation", response = ValidationException.class)})
@RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value= HttpStatus.CREATED)
public Thing newThing(@RequestBody Thing thing) {

    Thing insertedThing = thingService.insertThing(thing);
    return insertedThing;

}

Seems to work fine. Should the ResponseEntity parameter be picked up?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions