BAEL 3617 (#8510)
* BAEL-3617 - @ApiParam and @ApiModelProperty examples * file formatted
This commit is contained in:
parent
e673011d6b
commit
f9d902c07b
@ -16,9 +16,10 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
|||||||
public class Swagger2Config {
|
public class Swagger2Config {
|
||||||
@Bean
|
@Bean
|
||||||
public Docket api() {
|
public Docket api() {
|
||||||
return new Docket(DocumentationType.SWAGGER_2).select()
|
return new Docket(DocumentationType.SWAGGER_2)
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.baeldung.swagger2boot.controller"))
|
.select()
|
||||||
.paths(PathSelectors.regex("/.*"))
|
.apis(RequestHandlerSelectors.any())
|
||||||
|
.paths(PathSelectors.any())
|
||||||
.build()
|
.build()
|
||||||
.apiInfo(apiEndPointsInfo());
|
.apiInfo(apiEndPointsInfo());
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.baeldung.swagger2boot.controller;
|
||||||
|
|
||||||
|
import com.baeldung.swagger2boot.model.Foo;
|
||||||
|
import com.baeldung.swagger2boot.model.User;
|
||||||
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import io.swagger.annotations.ApiParam;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import javax.websocket.server.PathParam;
|
||||||
|
|
||||||
|
import static org.apache.commons.lang3.RandomStringUtils.randomNumeric;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
public UserController() {
|
||||||
|
super();
|
||||||
|
} //@formatter:off
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = "/createUser", produces = "application/json; charset=UTF-8")
|
||||||
|
@ResponseStatus(HttpStatus.CREATED)
|
||||||
|
@ResponseBody
|
||||||
|
@ApiOperation(value = "Create user",
|
||||||
|
notes = "This method creates a new user")
|
||||||
|
public User createUser(@ApiParam(
|
||||||
|
name = "firstName",
|
||||||
|
type = "String",
|
||||||
|
value = "First Name of the user",
|
||||||
|
example = "Vatsal",
|
||||||
|
required = true) @RequestParam String firstName) { //@formatter:on
|
||||||
|
User user = new User(firstName);
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
package com.baeldung.swagger2boot.model;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
@ApiModel
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "first name of the user", name = "firstName", dataType = "String", example = "Vatsal")
|
||||||
|
String firstName;
|
||||||
|
|
||||||
|
public User() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public User(final String firstName) {
|
||||||
|
super();
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String firstName) {
|
||||||
|
this.firstName = firstName;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user