Merge pull request #8248 from SmartyAnsh/BAEL-3456_Springfox
Bael 3456 springfox
This commit is contained in:
commit
7a749a5e88
@ -14,6 +14,15 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<repositories>
|
||||
<!-- Snapshot repository location -->
|
||||
<repository>
|
||||
<id>jcenter-snapshots</id>
|
||||
<name>jcenter</name>
|
||||
<url>http://oss.jfrog.org/artifactory/oss-snapshot-local/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@ -34,7 +43,14 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--JSF -->
|
||||
<dependency>
|
||||
@ -82,6 +98,18 @@
|
||||
<artifactId>springfox-swagger-ui</artifactId>
|
||||
<version>${spring.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-data-rest</artifactId>
|
||||
<version>${spring.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.springfox</groupId>
|
||||
<artifactId>springfox-bean-validators</artifactId>
|
||||
<version>${spring.fox.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.tomcat.embed</groupId>
|
||||
@ -117,7 +145,7 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring.fox.version>2.9.2</spring.fox.version>
|
||||
<spring.fox.version>3.0.0-SNAPSHOT</spring.fox.version>
|
||||
<!-- ROME for RSS -->
|
||||
<rome.version>1.10.0</rome.version>
|
||||
<javax.faces.version>2.3.7</javax.faces.version>
|
||||
|
@ -1,22 +1,29 @@
|
||||
package com.baeldung.swagger2boot.configuration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import com.baeldung.swagger2boot.plugin.EmailAnnotationPlugin;
|
||||
|
||||
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.service.Contact;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.data.rest.configuration.SpringDataRestConfiguration;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
import springfox.documentation.swagger.web.*;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2;
|
||||
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@Configuration
|
||||
@EnableSwagger2
|
||||
@ComponentScan("com.baeldung.swaggerboot.controller")
|
||||
@EnableSwagger2WebMvc
|
||||
@Import({SpringDataRestConfiguration.class, BeanValidatorPluginsConfiguration.class})
|
||||
public class SpringFoxConfig {
|
||||
|
||||
private ApiInfo apiInfo() {
|
||||
@ -65,4 +72,8 @@ public class SpringFoxConfig {
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EmailAnnotationPlugin emailPlugin() {
|
||||
return new EmailAnnotationPlugin();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.baeldung.swagger2boot.model;
|
||||
|
||||
import javax.persistence.Id;
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.Max;
|
||||
import javax.validation.constraints.Min;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.persistence.Entity;
|
||||
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@NotNull(message = "First Name cannot be null")
|
||||
private String firstName;
|
||||
|
||||
@Min(value = 15, message = "Age should not be less than 15")
|
||||
@Max(value = 65, message = "Age should not be greater than 65")
|
||||
private int age;
|
||||
|
||||
@Email(regexp=".@.\\..*", message = "Email should be valid")
|
||||
private String email;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package com.baeldung.swagger2boot.plugin;
|
||||
|
||||
import static springfox.bean.validators.plugins.Validators.annotationFromBean;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import springfox.bean.validators.plugins.Validators;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spi.schema.ModelPropertyBuilderPlugin;
|
||||
import springfox.documentation.spi.schema.contexts.ModelPropertyContext;
|
||||
|
||||
@Component
|
||||
@Order(Validators.BEAN_VALIDATOR_PLUGIN_ORDER)
|
||||
public class EmailAnnotationPlugin implements ModelPropertyBuilderPlugin {
|
||||
|
||||
@Override
|
||||
public boolean supports(DocumentationType delimiter) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* read Email annotation
|
||||
*/
|
||||
@Override
|
||||
public void apply(ModelPropertyContext context) {
|
||||
Optional<Email> email = annotationFromBean(context, Email.class);
|
||||
if (email.isPresent()) {
|
||||
context.getBuilder().pattern(email.get().regexp());
|
||||
context.getBuilder().example("email@email.com");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.baeldung.swagger2boot.repository;
|
||||
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.baeldung.swagger2boot.model.User;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends CrudRepository<User, Long> {
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user