Add a header parameter in Swagger UI documentation with Springfox

后端 未结 3 1211
梦毁少年i
梦毁少年i 2020-12-19 02:26

I want to add a header parameter field in the auto-generated swagger ui documentation of my rest service. I use Spring and Springfox.

public ResponseEntity&l         


        
3条回答
  •  时光说笑
    2020-12-19 02:42

    I just added @RequestHeader(value="myHeader") String headerStr :

    public ResponseEntity saveNewUser(
            @RequestHeader(value="myHeader") String headerStr,
            @ApiParam(value = "the user to create", required = true) @RequestBody User user) throws RestServiceException {
    
        userService.save(user);
        return new ResponseEntity(user, HttpStatus.OK);
    }
    

    (import org.springframework.web.bind.annotation.RequestHeader;)

    You can also add a global header on every service in your documentation with the solution described here : Spring + Springfox + Header Parameters

提交回复
热议问题