Skip to content

Commit b11dff7

Browse files
authored
Use Spring Boot 3.x by default (useSpringBoot3=true) (#23318)
* set useSpringBoot3 to true by default * add tests for usespringboot3 set to false * update workflow to use jdk 11 * use jdk 17 * update * fix tests * update * update camel to test with spring boot 2.x * update samples * remove check
1 parent fd0d43f commit b11dff7

File tree

1,565 files changed

+5005
-5121
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,565 files changed

+5005
-5121
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Samples Java Spring (JDK11)
2+
3+
on:
4+
push:
5+
paths:
6+
# servers
7+
- samples/server/petstore/springboot-implicitHeaders/**
8+
- samples/server/petstore/springboot-implicitHeaders-annotationLibrary/**
9+
pull_request:
10+
paths:
11+
# servers
12+
- samples/server/petstore/springboot-implicitHeaders/**
13+
- samples/server/petstore/springboot-implicitHeaders-annotationLibrary/**
14+
jobs:
15+
build:
16+
name: Build
17+
runs-on: ubuntu-latest
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
sample:
22+
# servers
23+
- samples/server/petstore/springboot-implicitHeaders
24+
- samples/server/petstore/springboot-implicitHeaders-annotationLibrary
25+
steps:
26+
- uses: actions/checkout@v5
27+
- uses: actions/setup-java@v5
28+
with:
29+
distribution: 'temurin'
30+
java-version: 11
31+
- name: Cache maven dependencies
32+
uses: actions/cache@v5
33+
env:
34+
cache-name: maven-repository
35+
with:
36+
path: |
37+
~/.m2
38+
key: ${{ runner.os }}-${{ github.job }}-${{ env.cache-name }}-${{ hashFiles('**/pom.xml') }}
39+
- name: Build
40+
working-directory: ${{ matrix.sample }}
41+
run: mvn clean package --no-transfer-progress

.github/workflows/samples-spring.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
- uses: actions/setup-java@v5
6868
with:
6969
distribution: 'temurin'
70-
java-version: 8
70+
java-version: 17
7171
- name: Cache maven dependencies
7272
uses: actions/cache@v5
7373
env:

bin/configs/java-camel-petstore-new.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ additionalProperties:
1414
camelRestClientRequestValidation: true
1515
camelSecurityDefinitions: true
1616
implicitHeaders: true
17+
useSpringBoot3: false

bin/configs/spring-boot-implicitHeaders-annotationLibrary.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ additionalProperties:
88
annotationLibrary: none
99
hideGenerationTimestamp: "true"
1010
implicitHeadersRegex: .*
11+
useSpringBoot3: false

bin/configs/spring-boot-implicitHeaders.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ additionalProperties:
66
artifactId: springboot-implicitHeaders
77
documentationProvider: springdoc
88
hideGenerationTimestamp: "true"
9+
useSpringBoot3: false
910
implicitHeadersRegex: .*

docs/generators/java-camel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
116116
|useOptional|Use Optional container for optional parameters| |false|
117117
|useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true|
118118
|useSealed|Whether to generate sealed model interfaces and classes| |false|
119-
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot ≥ 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
119+
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot ≥ 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |true|
120120
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
121121
|useSpringBuiltInValidation|Disable `@Validated` at the class level when using built-in validation.| |false|
122122
|useSpringController|Annotate the generated API as a Spring Controller| |false|

docs/generators/spring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
109109
|useOptional|Use Optional container for optional parameters| |false|
110110
|useResponseEntity|Use the `ResponseEntity` type to wrap return values of generated API methods. If disabled, method are annotated using a `@ResponseStatus` annotation, which has the status of the first response declared in the Api definition| |true|
111111
|useSealed|Whether to generate sealed model interfaces and classes| |false|
112-
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot ≥ 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
112+
|useSpringBoot3|Generate code and provide dependencies for use with Spring Boot ≥ 3 (use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |true|
113113
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x. (Use jakarta instead of javax in imports). Enabling this option will also enable `useJakartaEe`.| |false|
114114
|useSpringBuiltInValidation|Disable `@Validated` at the class level when using built-in validation.| |false|
115115
|useSpringController|Annotate the generated API as a Spring Controller| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/SpringCodegen.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public enum RequestMappingMode {
163163
@Setter protected boolean generateGenericResponseEntity = false;
164164
@Setter protected boolean useEnumCaseInsensitive = false;
165165
@Getter @Setter
166-
protected boolean useSpringBoot3 = false;
166+
protected boolean useSpringBoot3 = true;
167167
@Getter @Setter
168168
protected boolean useSpringBoot4 = false;
169169
@Getter @Setter
@@ -520,9 +520,11 @@ public void processOpts() {
520520
convertPropertyToBooleanAndWriteBack(USE_JACKSON_3, this::setUseJackson3);
521521
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT3, this::setUseSpringBoot3);
522522
convertPropertyToBooleanAndWriteBack(USE_SPRING_BOOT4, this::setUseSpringBoot4);
523-
if(isUseSpringBoot3() && isUseSpringBoot4()){
524-
throw new IllegalArgumentException("Choose between Spring Boot 3 and Spring Boot 4");
523+
524+
if (isUseSpringBoot4()) {
525+
setUseSpringBoot3(false);
525526
}
527+
526528
if (isUseSpringBoot3() || isUseSpringBoot4()) {
527529
if (AnnotationLibrary.SWAGGER1.equals(getAnnotationLibrary())) {
528530
throw new IllegalArgumentException(AnnotationLibrary.SWAGGER1.getPropertyName() + " is not supported with Spring Boot > 3.x");

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,7 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
12211221
codegen.additionalProperties().put(SpringCodegen.PERFORM_BEANVALIDATION, "true");
12221222
codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "xyz.model");
12231223
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xyz.controller");
1224+
codegen.additionalProperties().put("useSpringBoot3", false);
12241225

12251226
ClientOptInput input = new ClientOptInput()
12261227
.openAPI(openAPI)
@@ -2148,6 +2149,7 @@ public void testTypeMappings() {
21482149
@Test
21492150
public void testImportMappings() {
21502151
final SpringCodegen codegen = new SpringCodegen();
2152+
codegen.additionalProperties().put("useSpringBoot3", false);
21512153
codegen.processOpts();
21522154
Assert.assertEquals(codegen.importMapping().get("org.springframework.core.io.Resource"), "org.springframework.core.io.Resource");
21532155
Assert.assertEquals(codegen.importMapping().get("DateTimeFormat"), "org.springframework.format.annotation.DateTimeFormat");
@@ -2512,6 +2514,8 @@ public void paramObjectImportForDifferentSpringBootVersions_issue14077() throws
25122514
additionalProperties.put(DOCUMENTATION_PROVIDER, "springdoc");
25132515
additionalProperties.put(SpringCodegen.INTERFACE_ONLY, "true");
25142516
additionalProperties.put(SpringCodegen.SKIP_DEFAULT_INTERFACE, "true");
2517+
additionalProperties.put("useSpringBoot3", false);
2518+
25152519
Map<String, File> files = generateFromContract("src/test/resources/2_0/petstore-with-spring-pageable.yaml", SPRING_BOOT, additionalProperties);
25162520

25172521
JavaFileAssert.assertThat(files.get("PetApi.java"))
@@ -2767,6 +2771,7 @@ public void requiredFieldShouldIncludeNotNullAnnotation_issue13365() throws IOEx
27672771
codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false");
27682772
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson");
27692773
codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true");
2774+
codegen.additionalProperties().put("useSpringBoot3", false);
27702775

27712776
Map<String, File> files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml");
27722777

@@ -2865,6 +2870,7 @@ public void requiredFieldShouldIncludeNotNullAnnotationWithBeanValidationTrue_is
28652870
codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, "false");
28662871
codegen.additionalProperties().put(CodegenConstants.SERIALIZATION_LIBRARY, "jackson");
28672872
codegen.additionalProperties().put(SpringCodegen.USE_TAGS, "true");
2873+
codegen.additionalProperties().put("useSpringBoot3", false);
28682874

28692875
Map<String, File> files = generateFiles(codegen, "src/test/resources/bugs/issue_13365.yml");
28702876

samples/client/petstore/spring-cloud-auth/pom.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
<name>petstore-spring-cloud-auth</name>
77
<version>1.0.0</version>
88
<properties>
9-
<java.version>1.8</java.version>
10-
<maven.compiler.source>${java.version}</maven.compiler.source>
11-
<maven.compiler.target>${java.version}</maven.compiler.target>
9+
<java.version>17</java.version>
10+
<maven.compiler.release>${java.version}</maven.compiler.release>
1211
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1312
</properties>
1413
<parent>
1514
<groupId>org.springframework.boot</groupId>
1615
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.7.15</version>
16+
<version>3.3.13</version>
1817
<relativePath/> <!-- lookup parent from repository -->
1918
</parent>
19+
2020
<build>
2121
<sourceDirectory>src/main/java</sourceDirectory>
2222

@@ -27,7 +27,7 @@
2727
<dependency>
2828
<groupId>org.springframework.cloud</groupId>
2929
<artifactId>spring-cloud-starter-parent</artifactId>
30-
<version>2021.0.5</version>
30+
<version>2023.0.0</version>
3131
<type>pom</type>
3232
<scope>import</scope>
3333
</dependency>
@@ -48,7 +48,6 @@
4848
<dependency>
4949
<groupId>org.springframework.security</groupId>
5050
<artifactId>spring-security-oauth2-client</artifactId>
51-
<version>5.7.8</version>
5251
</dependency>
5352
<dependency>
5453
<groupId>com.fasterxml.jackson.datatype</groupId>
@@ -57,7 +56,7 @@
5756
<dependency>
5857
<groupId>org.openapitools</groupId>
5958
<artifactId>jackson-databind-nullable</artifactId>
60-
<version>0.2.8</version>
59+
<version>0.2.9</version>
6160
</dependency>
6261
<dependency>
6362
<groupId>org.springframework.boot</groupId>

0 commit comments

Comments
 (0)