Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #1308 - fix jakarta spring generator #1315

Merged
merged 2 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-generators</artifactId>
<version>1.0.52</version>
<version>1.0.53-SNAPSHOT</version>
<packaging>jar</packaging>

<build>
Expand Down Expand Up @@ -256,28 +256,28 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.12.0</version>
<version>5.14.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.release>8</maven.compiler.release>
<swagger-codegen-version>3.0.62</swagger-codegen-version>
<swagger-parser-version>2.1.22</swagger-parser-version>
<swagger-core-version>2.2.22</swagger-core-version>
<swagger-core-version>2.2.25</swagger-core-version>
<jackson-version>2.17.2</jackson-version>
<jackson-databind-version>2.17.2</jackson-databind-version>
<scala-version>2.11.1</scala-version>
<felix-version>3.3.0</felix-version>
<commons-io-version>2.16.1</commons-io-version>
<commons-io-version>2.17.0</commons-io-version>
<commons-cli-version>1.9.0</commons-cli-version>
<junit-version>4.13.2</junit-version>
<maven-plugin-version>1.0.0</maven-plugin-version>
<commons-lang-version>3.16.0</commons-lang-version>
<commons-lang-version>3.17.0</commons-lang-version>
<slf4j-version>2.0.9</slf4j-version>
<scala-maven-plugin-version>3.2.1</scala-maven-plugin-version>
<testng-version>7.10.2</testng-version>
<surefire-version>3.3.0</surefire-version>
<surefire-version>3.5.1</surefire-version>
<jmockit-version>1.49</jmockit-version>
<reflections-version>0.10.2</reflections-version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ public void processOpts() {

if (isSpringBoot3Library()) {
setDateLibrary("java8");
setJakarta(true);
additionalProperties.put(JAKARTA, jakarta);
}

super.processOpts();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package {{configPackage}};

{{#jakarta}}
import jakarta.validation.Constraint;
import jakarta.validation.Payload;
{{/jakarta}}
{{^jakarta}}
import javax.validation.Constraint;
import javax.validation.Payload;
{{/jakarta}}
import java.lang.annotation.*;

@Target({ElementType.TYPE})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package {{configPackage}};

import org.openapitools.jackson.nullable.JsonNullable;
{{#jakarta}}
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
{{/jakarta}}
{{^jakarta}}
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
{{/jakarta}}
import java.lang.reflect.Field;

public class NotUndefinedValidator implements ConstraintValidator<NotUndefined, Object>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,13 @@ public class CustomInstantDeserializer<T extends Temporal>
return value;
}
}
{{#jakarta}}
context.reportInputMismatch(handledType(), "Expected type float, integer, or string.");
return null;
{{/jakarta}}
{{^jakarta}}
throw context.mappingException("Expected type float, integer, or string.");
{{/jakarta}}
}

private ZoneId getZone(DeserializationContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
<name>{{artifactId}}</name>
<version>{{artifactVersion}}</version>
<properties>
{{#jakarta}}
<maven.compiler.release>17</maven.compiler.release>
{{/jakarta}}
{{^jakarta}}
<java.version>{{#java11}}11{{/java11}}{{^java11}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/java11}}</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
{{/jakarta}}
{{#useOas2}}
<springfox-version>2.9.2</springfox-version>
{{/useOas2}}
Expand All @@ -19,7 +24,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
{{#jakarta}}
<version>3.3.4</version>
{{/jakarta}}
{{^jakarta}}
<version>{{springBootVersion}}</version>
{{/jakarta}}
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -66,7 +76,13 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

{{#jakarta}}
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
{{/jakarta}}
<!--SpringFox dependencies -->
{{#useOas2}}
<dependency>
Expand Down Expand Up @@ -139,6 +155,7 @@
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
<version>3.0.2</version>
</dependency>
{{/jakarta}}
{{^jakarta}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;

import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
{{#jakarta}}
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
{{/jakarta}}
{{^jakarta}}
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

{{/jakarta}}
@SpringBootApplication
{{#useOas2}}
@EnableSwagger2
Expand Down Expand Up @@ -62,7 +66,12 @@ public class Swagger2SpringBoot implements CommandLineRunner {
{{/useBeanValidation}}

@Configuration
{{#jakarta}}
static class CustomDateConfig implements WebMvcConfigurer {
{{/jakarta}}
{{^jakarta}}
static class CustomDateConfig extends WebMvcConfigurerAdapter {
{{/jakarta}}
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new LocalDateConverter("{{#datePattern}}{{datePattern}}{{/datePattern}}{{^datePattern}}yyyy-MM-dd{{/datePattern}}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>17</maven.compiler.release>
<springboot-version>3.1.1</springboot-version>
<swagger-annotations-version>2.2.14</swagger-annotations-version>
<springboot-version>3.3.4</springboot-version>
<swagger-annotations-version>2.2.25</swagger-annotations-version>
<springdoc-version>1.7.0</springdoc-version>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.1</version>
<version>3.3.4</version>
</parent>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
Expand Down Expand Up @@ -44,6 +44,11 @@
<artifactId>spring-boot-starter-tomcat</artifactId>
<version>${springboot-version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>8.0.1.Final</version>
</dependency>
{{#withXml}}
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public void testGenerator() throws Exception {
false)) // OpenAPI 3.x - use true for Swagger/OpenAPI 2.x definitions
.options(
new Options()
// .library("spring-boot3")
// .addAdditionalProperty("jakarta", true)
// .addAdditionalProperty("validationMode", "loose")
// .addAdditionalProperty("validationMode", "legacy")
// .addAdditionalProperty("validationMode", "legacyNullable")
Expand Down
Loading