* BAEL-3617 - @ApiParam and @ApiModelProperty examples

* file formatted
This commit is contained in:
vatsalgosar 2020-02-24 00:35:16 +05:30 committed by GitHub
parent e673011d6b
commit f9d902c07b
3 changed files with 73 additions and 5 deletions

View File

@ -16,11 +16,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
public class Swagger2Config {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.baeldung.swagger2boot.controller"))
.paths(PathSelectors.regex("/.*"))
.build()
.apiInfo(apiEndPointsInfo());
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.apiInfo(apiEndPointsInfo());
}
private ApiInfo apiEndPointsInfo() {

View File

@ -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;
}
}

View File

@ -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;
}
}