Skip to content

Commit

Permalink
refs #1308 - fix jakarta spring generator
Browse files Browse the repository at this point in the history
  • Loading branch information
frantuma committed Oct 15, 2024
1 parent 00d6c5c commit bbe1324
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 5 deletions.
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

0 comments on commit bbe1324

Please sign in to comment.