Springfox - PR review fix

This commit is contained in:
Anshul BANSAL 2019-11-28 17:14:05 +02:00
parent 7fefb0ff18
commit 3b4e9585d5
3 changed files with 15 additions and 31 deletions

View File

@ -12,7 +12,9 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import com.baeldung.springfox.plugin.EmailAnnotationPlugin; import com.baeldung.springfox.plugin.EmailAnnotationPlugin;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.service.ApiInfo; import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType; import springfox.documentation.spi.DocumentationType;
@ -36,11 +38,11 @@ public class SpringfoxApplication {
@Bean @Bean
public Docket springfoxAppInfo() { public Docket springfoxAppInfo() {
return new Docket(DocumentationType.SWAGGER_2) return new Docket(DocumentationType.SWAGGER_2)
.groupName("baeldung-springfox-api") .groupName("baeldung-springfox-api")
.select() .select()
.paths(paths()) .paths(paths())
.build() .build()
.apiInfo(apiInfo()); .apiInfo(apiInfo());
} }
private Predicate<String> paths() { private Predicate<String> paths() {
@ -48,13 +50,8 @@ public class SpringfoxApplication {
} }
private ApiInfo apiInfo() { private ApiInfo apiInfo() {
return new ApiInfo( return new ApiInfo("Springfox API specification", "User REST and Spring Data APIs",
"Springfox API specification", "", "", null, "License of API", "API license URL", Collections.emptyList());
"User REST and Spring Data APIs",
"",
"",
null,
"License of API", "API license URL", Collections.emptyList());
} }
@Bean @Bean

View File

@ -1,8 +1,5 @@
package com.baeldung.springfox.controller; package com.baeldung.springfox.controller;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;
import java.util.Optional; import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -10,6 +7,8 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@ -25,16 +24,14 @@ public class UserController {
@Autowired @Autowired
private UserRepository userRepository; private UserRepository userRepository;
@RequestMapping(method = POST) @PostMapping
@ResponseBody public @ResponseBody ResponseEntity<User> createUser(@RequestBody User user) {
public ResponseEntity<User> createUser(@RequestBody User user) {
userRepository.save(user); userRepository.save(user);
return new ResponseEntity<>(user, HttpStatus.OK); return new ResponseEntity<>(user, HttpStatus.OK);
} }
@RequestMapping(method = GET) @GetMapping
@ResponseBody public @ResponseBody ResponseEntity<User> getUser(@RequestParam Long id) {
public ResponseEntity<User> getUser(@RequestParam Long id) {
Optional<User> user = userRepository.findById(id); Optional<User> user = userRepository.findById(id);
return new ResponseEntity<>(user.get(), HttpStatus.OK); return new ResponseEntity<>(user.get(), HttpStatus.OK);
} }

View File

@ -16,8 +16,6 @@ public class User{
@NotNull(message = "First Name cannot be null") @NotNull(message = "First Name cannot be null")
private String firstName; private String firstName;
private String lastName;
@Min(value = 15, message = "Age should not be less than 15") @Min(value = 15, message = "Age should not be less than 15")
@Max(value = 65, message = "Age should not be greater than 65") @Max(value = 65, message = "Age should not be greater than 65")
private int age; private int age;
@ -41,14 +39,6 @@ public class User{
this.firstName = firstName; this.firstName = firstName;
} }
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() { public String getEmail() {
return email; return email;
} }