Skip to content

Commit f36b834

Browse files
committed
fix #22492 [BUG][JAVA][MAVEN] Lombok @Getter disables validation and #19743 #18794 #17793 #17606
1 parent ece9cfe commit f36b834

24 files changed

Lines changed: 1507 additions & 128 deletions

bin/configs/spring-boot-lombok-data.yaml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,3 @@ additionalProperties:
99
additionalModelTypeAnnotations: "@lombok.Data;@lombok.Builder;@lombok.NoArgsConstructor;@lombok.AllArgsConstructor"
1010
generateConstructorWithAllArgs: true
1111
generateBuilders: true
12-
useSpringBoot3: true
13-
skipDefaultInterface: true
14-
interfaceOnly: true
15-
performBeanValidation: true
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
README.md
22
pom.xml
3+
src/main/java/org/openapitools/OpenApiGeneratorApplication.java
4+
src/main/java/org/openapitools/RFC3339DateFormat.java
35
src/main/java/org/openapitools/api/ApiUtil.java
46
src/main/java/org/openapitools/api/PetApi.java
7+
src/main/java/org/openapitools/api/PetApiController.java
58
src/main/java/org/openapitools/api/StoreApi.java
9+
src/main/java/org/openapitools/api/StoreApiController.java
610
src/main/java/org/openapitools/api/UserApi.java
11+
src/main/java/org/openapitools/api/UserApiController.java
12+
src/main/java/org/openapitools/configuration/HomeController.java
13+
src/main/java/org/openapitools/configuration/SpringDocConfiguration.java
714
src/main/java/org/openapitools/model/Category.java
815
src/main/java/org/openapitools/model/ModelApiResponse.java
916
src/main/java/org/openapitools/model/Order.java
1017
src/main/java/org/openapitools/model/Pet.java
1118
src/main/java/org/openapitools/model/Tag.java
1219
src/main/java/org/openapitools/model/User.java
20+
src/main/resources/application.properties
21+
src/main/resources/openapi.yaml
22+
src/test/java/org/openapitools/OpenApiGeneratorApplicationTests.java
Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
1+
# OpenAPI generated server
12

2-
# OpenAPI generated API stub
3+
Spring Boot Server
34

4-
Spring Framework stub
5+
## Overview
6+
This server was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
7+
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate a server stub.
8+
This is an example of building a OpenAPI-enabled server in Java using the SpringBoot framework.
59

610

7-
## Overview
8-
This code was generated by the [OpenAPI Generator](https://openapi-generator.tech) project.
9-
By using the [OpenAPI-Spec](https://openapis.org), you can easily generate an API stub.
10-
This is an example of building API stub interfaces in Java using the Spring framework.
11+
The underlying library integrating OpenAPI to Spring Boot is [springdoc](https://springdoc.org).
12+
Springdoc will generate an OpenAPI v3 specification based on the generated Controller and Model classes.
13+
The specification is available to download using the following url:
14+
http://localhost:8080/v3/api-docs/
1115

12-
The stubs generated can be used in your existing Spring-MVC or Spring-Boot application to create controller endpoints
13-
by adding ```@Controller``` classes that implement the interface. Eg:
14-
```java
15-
@Controller
16-
public class PetController implements PetApi {
17-
// implement all PetApi methods
18-
}
19-
```
16+
Start your server as a simple java application
2017

21-
You can also use the interface to create [Spring-Cloud Feign clients](http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-inheritance).Eg:
22-
```java
23-
@FeignClient(name="pet", url="http://petstore.swagger.io/v2")
24-
public interface PetClient extends PetApi {
18+
You can view the api documentation in swagger-ui by pointing to
19+
http://localhost:8080/swagger-ui.html
2520

26-
}
27-
```
21+
Change default port value in application.properties

samples/server/petstore/springboot-lombok-data/pom.xml

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,33 @@
66
<name>springboot-lombok-data</name>
77
<version>1.0.0</version>
88
<properties>
9-
<java.version>17</java.version>
9+
<java.version>1.8</java.version>
1010
<maven.compiler.source>${java.version}</maven.compiler.source>
1111
<maven.compiler.target>${java.version}</maven.compiler.target>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<springdoc.version>2.6.0</springdoc.version>
14-
<swagger-ui.version>5.17.14</swagger-ui.version>
13+
<springdoc.version>1.6.14</springdoc.version>
14+
<swagger-ui.version>5.3.1</swagger-ui.version>
1515
</properties>
1616
<parent>
1717
<groupId>org.springframework.boot</groupId>
1818
<artifactId>spring-boot-starter-parent</artifactId>
19-
<version>3.1.3</version>
19+
<version>2.7.15</version>
2020
<relativePath/> <!-- lookup parent from repository -->
2121
</parent>
22-
23-
<repositories>
24-
<repository>
25-
<id>repository.spring.milestone</id>
26-
<name>Spring Milestone Repository</name>
27-
<url>https://repo.spring.io/milestone</url>
28-
</repository>
29-
</repositories>
30-
<pluginRepositories>
31-
<pluginRepository>
32-
<id>spring-milestones</id>
33-
<url>https://repo.spring.io/milestone</url>
34-
</pluginRepository>
35-
</pluginRepositories>
36-
3722
<build>
3823
<sourceDirectory>src/main/java</sourceDirectory>
3924
<plugins>
4025
<plugin>
41-
<groupId>org.apache.maven.plugins</groupId>
42-
<artifactId>maven-source-plugin</artifactId>
43-
<executions>
44-
<execution>
45-
<id>attach-sources</id>
46-
<goals>
47-
<goal>jar</goal>
48-
</goals>
49-
</execution>
50-
</executions>
26+
<groupId>org.springframework.boot</groupId>
27+
<artifactId>spring-boot-maven-plugin</artifactId>
28+
<configuration>
29+
<excludes>
30+
<exclude>
31+
<groupId>org.projectlombok</groupId>
32+
<artifactId>lombok</artifactId>
33+
</exclude>
34+
</excludes>
35+
</configuration>
5136
</plugin>
5237
</plugins>
5338
</build>
@@ -63,7 +48,7 @@
6348
<!--SpringDoc dependencies -->
6449
<dependency>
6550
<groupId>org.springdoc</groupId>
66-
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
51+
<artifactId>springdoc-openapi-ui</artifactId>
6752
<version>${springdoc.version}</version>
6853
</dependency>
6954
<!-- @Nullable annotation -->
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.openapitools;
2+
3+
import com.fasterxml.jackson.databind.Module;
4+
import org.openapitools.jackson.nullable.JsonNullableModule;
5+
import org.springframework.boot.SpringApplication;
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.context.annotation.Bean;
8+
import org.springframework.context.annotation.ComponentScan;
9+
import org.springframework.context.annotation.FilterType;
10+
import org.springframework.context.annotation.FullyQualifiedAnnotationBeanNameGenerator;
11+
12+
@SpringBootApplication(
13+
nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class
14+
)
15+
@ComponentScan(
16+
basePackages = {"org.openapitools", "org.openapitools.api" , "org.openapitools.configuration"},
17+
nameGenerator = FullyQualifiedAnnotationBeanNameGenerator.class
18+
)
19+
public class OpenApiGeneratorApplication {
20+
21+
public static void main(String[] args) {
22+
SpringApplication.run(OpenApiGeneratorApplication.class, args);
23+
}
24+
25+
@Bean(name = "org.openapitools.OpenApiGeneratorApplication.jsonNullableModule")
26+
public Module jsonNullableModule() {
27+
return new JsonNullableModule();
28+
}
29+
30+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.openapitools;
2+
3+
import com.fasterxml.jackson.databind.util.StdDateFormat;
4+
5+
import java.text.DateFormat;
6+
import java.text.FieldPosition;
7+
import java.text.ParsePosition;
8+
import java.util.Date;
9+
import java.util.GregorianCalendar;
10+
import java.util.TimeZone;
11+
12+
public class RFC3339DateFormat extends DateFormat {
13+
private static final long serialVersionUID = 1L;
14+
private static final TimeZone TIMEZONE_Z = TimeZone.getTimeZone("UTC");
15+
16+
private final StdDateFormat fmt = new StdDateFormat()
17+
.withTimeZone(TIMEZONE_Z)
18+
.withColonInTimeZone(true);
19+
20+
public RFC3339DateFormat() {
21+
this.calendar = new GregorianCalendar();
22+
}
23+
24+
@Override
25+
public Date parse(String source, ParsePosition pos) {
26+
return fmt.parse(source, pos);
27+
}
28+
29+
@Override
30+
public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) {
31+
return fmt.format(date, toAppendTo, fieldPosition);
32+
}
33+
34+
@Override
35+
public Object clone() {
36+
return this;
37+
}
38+
}

samples/server/petstore/springboot-lombok-data/src/main/java/org/openapitools/api/ApiUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import org.springframework.web.context.request.NativeWebRequest;
44

5-
import jakarta.servlet.http.HttpServletResponse;
5+
import javax.servlet.http.HttpServletResponse;
66
import java.io.IOException;
77

88
public class ApiUtil {

0 commit comments

Comments
 (0)